rubytree 0.9.7 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/API-CHANGES.md +153 -0
- data/Gemfile +2 -13
- data/Gemfile.lock +60 -61
- data/History.md +410 -0
- data/LICENSE.md +1 -2
- data/README.md +24 -28
- data/Rakefile +65 -48
- data/TODO.org +19 -15
- data/examples/example_basic.rb +19 -12
- data/lib/rubytree.rb +3 -4
- data/lib/tree/binarytree.rb +27 -27
- data/lib/tree/tree_deps.rb +9 -12
- data/lib/tree/utils/hash_converter.rb +127 -121
- data/lib/tree/utils/json_converter.rb +81 -79
- data/lib/tree/utils/metrics_methods.rb +18 -48
- data/lib/tree/utils/path_methods.rb +15 -17
- data/lib/tree/utils/tree_merge_handler.rb +79 -80
- data/lib/tree/utils/utils.rb +9 -6
- data/lib/tree/version.rb +3 -5
- data/lib/tree.rb +194 -177
- data/rubytree.gemspec +67 -44
- data/spec/spec_helper.rb +5 -3
- data/spec/tree_spec.rb +136 -37
- data/test/run_test.rb +9 -8
- data/test/test_binarytree.rb +86 -105
- data/test/test_rubytree_require.rb +4 -5
- data/test/test_subclassed_node.rb +5 -26
- data/test/test_thread_and_fiber.rb +13 -16
- data/test/test_tree.rb +577 -657
- metadata +142 -55
- data/API-CHANGES.rdoc +0 -99
- data/History.rdoc +0 -303
- data/TAGS +0 -248
- data/gem_graph.png +0 -0
- data/lib/tree/utils/camel_case_method_handler.rb +0 -79
- data/setup.rb +0 -1585
@@ -3,9 +3,9 @@
|
|
3
3
|
# tree_merge_handler.rb
|
4
4
|
#
|
5
5
|
# Author: Anupam Sengupta
|
6
|
-
# Time-stamp: <
|
6
|
+
# Time-stamp: <2022-06-20 22:17:12 anupam>
|
7
7
|
#
|
8
|
-
# Copyright (C) 2013, 2015 Anupam Sengupta (anupamsg@gmail.com)
|
8
|
+
# Copyright (C) 2013, 2015, 2022 Anupam Sengupta (anupamsg@gmail.com)
|
9
9
|
#
|
10
10
|
# All rights reserved.
|
11
11
|
#
|
@@ -34,96 +34,95 @@
|
|
34
34
|
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
35
35
|
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
36
36
|
#
|
37
|
+
# frozen_string_literal: true
|
37
38
|
|
38
39
|
# Provides utility methods to merge two {Tree::TreeNode} based trees.
|
39
40
|
# @since 0.9.0
|
40
|
-
module Tree
|
41
|
+
module Tree
|
42
|
+
module Utils
|
43
|
+
# Handles merging of two trees.
|
44
|
+
module TreeMergeHandler
|
45
|
+
# @!group Merging Trees
|
41
46
|
|
42
|
-
|
47
|
+
# Merge two trees that share the same root node and returns <em>a new
|
48
|
+
# tree</em>.
|
49
|
+
#
|
50
|
+
# The new tree contains the contents of the merge between _other_tree_ and
|
51
|
+
# self. Duplicate nodes (coming from _other_tree_) will *NOT* be overwritten
|
52
|
+
# in self.
|
53
|
+
#
|
54
|
+
# @author Darren Oakley (https://github.com/dazoakley)
|
55
|
+
#
|
56
|
+
# @param [Tree::TreeNode] other_tree The other tree to merge with.
|
57
|
+
# @return [Tree::TreeNode] the resulting tree following the merge.
|
58
|
+
#
|
59
|
+
# @raise [TypeError] This exception is raised if _other_tree_ is not a
|
60
|
+
# {Tree::TreeNode}.
|
61
|
+
#
|
62
|
+
# @raise [ArgumentError] This exception is raised if _other_tree_ does not
|
63
|
+
# have the same root node as self.
|
64
|
+
def merge(other_tree)
|
65
|
+
check_merge_prerequisites(other_tree)
|
66
|
+
merge_trees(root.dup, other_tree.root)
|
67
|
+
end
|
43
68
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
def merge(other_tree)
|
62
|
-
check_merge_prerequisites(other_tree)
|
63
|
-
new_tree = merge_trees(self.root.dup, other_tree.root)
|
64
|
-
return new_tree
|
65
|
-
end
|
69
|
+
# Merge in another tree (that shares the same root node) into +this+ tree.
|
70
|
+
# Duplicate nodes (coming from _other_tree_) will NOT be overwritten in
|
71
|
+
# self.
|
72
|
+
#
|
73
|
+
# @author Darren Oakley (https://github.com/dazoakley)
|
74
|
+
#
|
75
|
+
# @param [Tree::TreeNode] other_tree The other tree to merge with.
|
76
|
+
#
|
77
|
+
# @raise [TypeError] This exception is raised if _other_tree_ is not a
|
78
|
+
# {Tree::TreeNode}.
|
79
|
+
#
|
80
|
+
# @raise [ArgumentError] This exception is raised if _other_tree_ does not
|
81
|
+
# have the same root node as self.
|
82
|
+
def merge!(other_tree)
|
83
|
+
check_merge_prerequisites(other_tree)
|
84
|
+
merge_trees(root, other_tree.root)
|
85
|
+
end
|
66
86
|
|
67
|
-
|
68
|
-
# Duplicate nodes (coming from _other_tree_) will NOT be overwritten in
|
69
|
-
# self.
|
70
|
-
#
|
71
|
-
# @author Darren Oakley (https://github.com/dazoakley)
|
72
|
-
#
|
73
|
-
# @param [Tree::TreeNode] other_tree The other tree to merge with.
|
74
|
-
#
|
75
|
-
# @raise [TypeError] This exception is raised if _other_tree_ is not a
|
76
|
-
# {Tree::TreeNode}.
|
77
|
-
#
|
78
|
-
# @raise [ArgumentError] This exception is raised if _other_tree_ does not
|
79
|
-
# have the same root node as self.
|
80
|
-
def merge!(other_tree)
|
81
|
-
check_merge_prerequisites( other_tree )
|
82
|
-
merge_trees( self.root, other_tree.root )
|
83
|
-
end
|
87
|
+
private
|
84
88
|
|
85
|
-
|
89
|
+
# Utility function to check that the conditions for a tree merge are met.
|
90
|
+
#
|
91
|
+
# @author Darren Oakley (https://github.com/dazoakley)
|
92
|
+
#
|
93
|
+
# @see #merge
|
94
|
+
# @see #merge!
|
95
|
+
def check_merge_prerequisites(other_tree)
|
96
|
+
raise TypeError, 'You can only merge in another instance of Tree::TreeNode' \
|
97
|
+
unless other_tree.is_a?(Tree::TreeNode)
|
86
98
|
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
#
|
91
|
-
# @see #merge
|
92
|
-
# @see #merge!
|
93
|
-
def check_merge_prerequisites(other_tree)
|
94
|
-
unless other_tree.is_a?(Tree::TreeNode)
|
95
|
-
raise TypeError,
|
96
|
-
'You can only merge in another instance of Tree::TreeNode'
|
97
|
-
end
|
99
|
+
raise ArgumentError, 'Unable to merge trees as they do not share the same root' \
|
100
|
+
unless root.name == other_tree.root.name
|
101
|
+
end
|
98
102
|
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
103
|
+
# Utility function to recursively merge two subtrees.
|
104
|
+
#
|
105
|
+
# @author Darren Oakley (https://github.com/dazoakley)
|
106
|
+
#
|
107
|
+
# @param [Tree::TreeNode] tree1 The target tree to merge into.
|
108
|
+
# @param [Tree::TreeNode] tree2 The donor tree (that will be merged
|
109
|
+
# into target).
|
110
|
+
# @raise [Tree::TreeNode] The merged tree.
|
111
|
+
def merge_trees(tree1, tree2)
|
112
|
+
names1 = tree1.children? ? tree1.children.map(&:name) : []
|
113
|
+
names2 = tree2.children? ? tree2.children.map(&:name) : []
|
104
114
|
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
# @param [Tree::TreeNode] tree1 The target tree to merge into.
|
110
|
-
# @param [Tree::TreeNode] tree2 The donor tree (that will be merged
|
111
|
-
# into target).
|
112
|
-
# @raise [Tree::TreeNode] The merged tree.
|
113
|
-
def merge_trees(tree1, tree2)
|
114
|
-
names1 = tree1.has_children? ? tree1.children.map { |child| child.name } : []
|
115
|
-
names2 = tree2.has_children? ? tree2.children.map { |child| child.name } : []
|
115
|
+
names_to_merge = names2 - names1
|
116
|
+
names_to_merge.each do |name|
|
117
|
+
tree1 << tree2[name].detached_subtree_copy
|
118
|
+
end
|
116
119
|
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
end
|
120
|
+
tree1.children.each do |child|
|
121
|
+
merge_trees(child, tree2[child.name]) unless tree2[child.name].nil?
|
122
|
+
end
|
121
123
|
|
122
|
-
|
123
|
-
|
124
|
+
tree1
|
125
|
+
end
|
124
126
|
end
|
125
|
-
|
126
|
-
return tree1
|
127
127
|
end
|
128
|
-
|
129
128
|
end
|
data/lib/tree/utils/utils.rb
CHANGED
@@ -4,11 +4,9 @@
|
|
4
4
|
#
|
5
5
|
# Author:: Anupam Sengupta (anupamsg@gmail.com)
|
6
6
|
#
|
7
|
-
# Time-stamp: <
|
7
|
+
# Time-stamp: <2022-06-20 01:21:38 anupam>
|
8
8
|
#
|
9
|
-
# Copyright (C) 2012
|
10
|
-
#
|
11
|
-
# All rights reserved.
|
9
|
+
# Copyright (C) 2012-2022 Anupam Sengupta. All rights reserved.
|
12
10
|
#
|
13
11
|
# Redistribution and use in source and binary forms, with or without
|
14
12
|
# modification, are permitted provided that the following conditions are met:
|
@@ -34,8 +32,13 @@
|
|
34
32
|
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
35
33
|
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
36
34
|
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
35
|
+
#
|
36
|
+
# frozen_string_literal: true
|
37
37
|
|
38
38
|
# Provides utilities and mixin modules for RubyTree.
|
39
|
-
module Tree
|
40
|
-
#
|
39
|
+
module Tree
|
40
|
+
# Provides various utilities for the TreeNode class.
|
41
|
+
module Utils
|
42
|
+
# Empty module. Being used as a namespace.
|
43
|
+
end
|
41
44
|
end
|
data/lib/tree/version.rb
CHANGED
@@ -4,9 +4,7 @@
|
|
4
4
|
#
|
5
5
|
# Author:: Anupam Sengupta (anupamsg@gmail.com)
|
6
6
|
#
|
7
|
-
# Copyright (c) 2012
|
8
|
-
#
|
9
|
-
# All rights reserved.
|
7
|
+
# Copyright (c) 2012-2022 Anupam Sengupta. All rights reserved.
|
10
8
|
#
|
11
9
|
# Redistribution and use in source and binary forms, with or without
|
12
10
|
# modification, are permitted provided that the following conditions are met:
|
@@ -33,9 +31,9 @@
|
|
33
31
|
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
34
32
|
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
35
33
|
#
|
34
|
+
# frozen_string_literal: true
|
36
35
|
|
37
|
-
#
|
38
36
|
module Tree
|
39
37
|
# Rubytree Package Version
|
40
|
-
VERSION = '0.
|
38
|
+
VERSION = '2.0.0'
|
41
39
|
end
|