Method: RubyIndexer::PrefixTree#delete
- Defined in:
- lib/ruby_indexer/lib/ruby_indexer/prefix_tree.rb
#delete(key) ⇒ Object
Deletes the entry identified by key from the tree. Notice that a partial match will still delete all entries that match it. For example, if the tree contains foo and we ask to delete fo, then foo will be deleted : (String key) -> void
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/ruby_indexer/lib/ruby_indexer/prefix_tree.rb', line 76 def delete(key) node = find_node(key) return unless node # Remove the node from the tree and then go up the parents to remove any of them with empty children parent = node.parent #: Node[Value]? while parent parent.children.delete(node.key) return if parent.children.any? || parent.leaf node = parent parent = parent.parent end end |