lib/rambling/trie/compressor.rb in rambling-trie-0.4.2 vs lib/rambling/trie/compressor.rb in rambling-trie-0.5.0
- old
+ new
@@ -6,14 +6,14 @@
# @return [Boolean] `true` for compressed tries, `false` otherwise.
def compressed?
@parent.nil? ? false : @parent.compressed?
end
- # Compressed the current node using redundant node elimination.
+ # Compress the current node using redundant node elimination.
# @return [Root, Node] the compressed node.
def compress_tree!
- if @children.size == 1 and not terminal? and not @letter.nil?
+ if @children.size == 1 and not terminal? and @letter
merge_with! @children.values.first
compress_tree!
end
@children.values.each &:compress_tree!
@@ -22,10 +22,10 @@
end
private
def merge_with!(child)
- new_letter = (@letter.to_s + child.letter.to_s).to_sym
+ new_letter = (@letter.to_s << child.letter.to_s).to_sym
rehash_on_parent! @letter, new_letter
redefine_self! new_letter, child
@children.values.each { |node| node.parent = self }