lib/tdiff/unordered.rb in tdiff-0.3.1 vs lib/tdiff/unordered.rb in tdiff-0.3.2
- old
+ new
@@ -13,11 +13,11 @@
base.send :include, TDiff
end
#
# Finds the differences between `self` and another tree, not respecting
- # the ordering of children.
+ # the order of the nodes.
#
# @param [#tdiff_each_child] tree
# The other tree.
#
# @yield [change, node]
@@ -42,10 +42,37 @@
yield '-', self
yield '+', tree
return self
end
+ yield ' ', self
+
+ tdiff_recursive_unordered(tree,&block)
+ return self
+ end
+
+ protected
+
+ #
+ # Recursively compares the differences between the children nodes,
+ # without respecting the order of the nodes.
+ #
+ # @param [#tdiff_each_child] tree
+ # The other tree.
+ #
+ # @yield [change, node]
+ # The given block will be passed the added or removed nodes.
+ #
+ # @yieldparam [' ', '+', '-'] change
+ # The state-change of the node.
+ #
+ # @yieldparam [Object] node
+ # A node from one of the two trees.
+ #
+ # @since 0.3.2
+ #
+ def tdiff_recursive_unordered(tree,&block)
x = enum_for(:tdiff_each_child,self)
y = enum_for(:tdiff_each_child,tree)
unchanged = {}
changes = []
@@ -77,12 +104,13 @@
# explicitly release the changes variable
changes = nil
# recurse down the unchanged nodes
- unchanged.each { |xi,yj| xi.tdiff_unordered(yj,&block) }
- unchanged = nil
+ unchanged.each do |xi,yj|
+ xi.tdiff_recursive_unordered(yj,&block)
+ end
- return self
+ unchanged = nil
end
end
end