lib/rambling/trie/compressor.rb in rambling-trie-1.0.3 vs lib/rambling/trie/compressor.rb in rambling-trie-2.0.0
- old
+ new
@@ -1,5 +1,7 @@
+# frozen_string_literal: true
+
module Rambling
module Trie
# Responsible for the compression process of a trie data structure.
class Compressor
# Compresses a {Nodes::Node Node} from a trie data structure.
@@ -24,38 +26,38 @@
new_compressed_node(
letter.to_sym,
node.parent,
other.children_tree,
- other.terminal?
+ other.terminal?,
)
end
def compress_children_and_copy node
new_compressed_node(
node.letter,
node.parent,
compress_children(node.children_tree),
- node.terminal?
+ node.terminal?,
)
end
- def compress_children children_tree
- new_children_tree = {}
+ def compress_children tree
+ new_tree = {}
- children_tree.each_value do |child|
+ tree.each do |letter, child|
compressed_child = compress child
- new_children_tree[compressed_child.letter] = compressed_child
+ new_tree[letter] = compressed_child
end
- new_children_tree
+ new_tree
end
- def new_compressed_node letter, parent, children_tree, terminal
- node = Rambling::Trie::Nodes::Compressed.new letter, parent, children_tree
+ def new_compressed_node letter, parent, tree, terminal
+ node = Rambling::Trie::Nodes::Compressed.new letter, parent, tree
node.terminal! if terminal
- children_tree.each_value { |child| child.parent = node }
+ tree.each_value { |child| child.parent = node }
node
end
end
end
end