rubytree 1.0.2 → 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 +4 -4
- data/API-CHANGES.md +153 -0
- data/Gemfile +2 -6
- data/Gemfile.lock +40 -55
- data/History.md +410 -0
- data/LICENSE.md +1 -1
- data/README.md +21 -24
- data/Rakefile +41 -20
- data/TODO.org +19 -15
- data/examples/example_basic.rb +14 -7
- data/lib/rubytree.rb +2 -3
- data/lib/tree/binarytree.rb +13 -12
- data/lib/tree/tree_deps.rb +2 -5
- data/lib/tree/utils/hash_converter.rb +129 -121
- data/lib/tree/utils/json_converter.rb +80 -77
- data/lib/tree/utils/metrics_methods.rb +14 -47
- data/lib/tree/utils/path_methods.rb +11 -11
- data/lib/tree/utils/tree_merge_handler.rb +80 -80
- data/lib/tree/utils/utils.rb +9 -7
- data/lib/tree/version.rb +3 -4
- data/lib/tree.rb +80 -82
- data/rubytree.gemspec +61 -38
- data/spec/spec_helper.rb +4 -2
- data/spec/tree_spec.rb +129 -28
- data/test/run_test.rb +4 -3
- data/test/test_binarytree.rb +25 -45
- data/test/test_rubytree_require.rb +2 -1
- data/test/test_subclassed_node.rb +2 -20
- data/test/test_thread_and_fiber.rb +4 -4
- data/test/test_tree.rb +126 -199
- metadata +103 -69
- data/API-CHANGES.rdoc +0 -99
- data/History.rdoc +0 -303
- data/lib/tree/utils/camel_case_method_handler.rb +0 -77
- data/setup.rb +0 -1565
data/History.rdoc
DELETED
@@ -1,303 +0,0 @@
|
|
1
|
-
= History of Changes
|
2
|
-
|
3
|
-
=== 0.9.7 / 2015-12-31
|
4
|
-
|
5
|
-
* Released 0.9.6. This is a minor bug-fix release.
|
6
|
-
|
7
|
-
* This release allows the {Tree::TreeNode#print_tree} method to be used on
|
8
|
-
non-root nodes. Thanks to {https://github.com/ojab Ojab}.
|
9
|
-
|
10
|
-
* The spaceship operator ('<=>') now returns 'nil' if the object being compared
|
11
|
-
to is itself 'nil' or not another {Tree::TreeNode}.
|
12
|
-
|
13
|
-
=== 0.9.6 / 2015-05-30
|
14
|
-
|
15
|
-
* Released 0.9.6, which is same as 0.9.5, except for an update to the Gem release date.
|
16
|
-
|
17
|
-
=== 0.9.5 / 2015-05-30
|
18
|
-
|
19
|
-
* Released 0.9.5.
|
20
|
-
|
21
|
-
=== 0.9.5pre7 / 2015-05-30
|
22
|
-
|
23
|
-
* Added new methods for getting the path of a node as a string. These have been
|
24
|
-
added as a new mixin {Tree::Utils::TreePathHandler}. Thanks to
|
25
|
-
{https://github.com/MZic Marco Ziccardi}.
|
26
|
-
|
27
|
-
=== 0.9.5pre5 / 2015-01-01
|
28
|
-
|
29
|
-
* Fixed {issue 32}[https://github.com/evolve75/RubyTree/issues/32] and enabled
|
30
|
-
'move' semantics on the {Tree::TreeNode#add} method, so that a child being
|
31
|
-
added, that has an existing parent, will be removed from its old parent, prior
|
32
|
-
to being added to the new location.
|
33
|
-
|
34
|
-
=== 0.9.5pre4 / 2014-12-17
|
35
|
-
|
36
|
-
* Added performance improvements to {Tree::TreeNode#is_root?} and
|
37
|
-
{Tree::Utils::TreeMetricsHandler#node_depth}.
|
38
|
-
Thanks to {https://github.com/aidansteele Aidan Steel}.
|
39
|
-
|
40
|
-
=== 0.9.5pre3 / 2014-12-16
|
41
|
-
|
42
|
-
* Minor fix to correct the release date. This release is otherwise identical to
|
43
|
-
0.9.5pre2.
|
44
|
-
|
45
|
-
=== 0.9.5pre2 / 2014-12-16
|
46
|
-
|
47
|
-
* Added {Tree::TreeNode#rename} and {Tree::TreeNode#rename_child} methods by
|
48
|
-
merging in code from {https://github.com/evolve75/RubyTree/pull/35}. Thanks to
|
49
|
-
{http://github.com/packetmonkey Evan Sharp}.
|
50
|
-
|
51
|
-
=== 0.9.5pre / 2014-11-01
|
52
|
-
|
53
|
-
* Fixed {issue 13}[https://github.com/evolve75/RubyTree/issues/13] with the
|
54
|
-
patch provided by {Jen Hamon}[http://www.github.com/jhamon].
|
55
|
-
|
56
|
-
* Fixed a bug in {Tree::TreeNode#print_tree} with the patch provided by
|
57
|
-
{https://github.com/packetmonkey Evan Sharp}.
|
58
|
-
|
59
|
-
* Fixed {issue 31}[https://github.com/evolve75/RubyTree/issues/31], which was
|
60
|
-
causing incorrect behavior n {Tree::TreeNode#postordered_each} and
|
61
|
-
{Tree::TreeNode#breadth_each} methods when a block was not provided.
|
62
|
-
|
63
|
-
=== 0.9.4 / 2014-07-04
|
64
|
-
|
65
|
-
* Changed all references to {http://rubyforge.org}.
|
66
|
-
|
67
|
-
=== 0.9.3 / 2014-02-01
|
68
|
-
|
69
|
-
* Fixed the issue with globally unique node names. See Github issue #24.
|
70
|
-
|
71
|
-
=== 0.9.2 / 2014-01-03
|
72
|
-
|
73
|
-
* Yanked R0.9.1 as the History file was not updated.
|
74
|
-
|
75
|
-
* Updated the gem description.
|
76
|
-
|
77
|
-
* Changed the travis-ci build to include coverall support.
|
78
|
-
|
79
|
-
=== 0.9.1 / 2014-01-03
|
80
|
-
|
81
|
-
* Updated the Gem description.
|
82
|
-
|
83
|
-
* Incorporated code coverage using the coverall gem.
|
84
|
-
|
85
|
-
=== 0.9.0 / 2014-01-02
|
86
|
-
|
87
|
-
This is a feature and bug-fix release.
|
88
|
-
|
89
|
-
==== The Features
|
90
|
-
|
91
|
-
* Rubytree now supports +postordered+ traversal via the
|
92
|
-
{Tree::TreeNode#postordered_each} method. Thanks to
|
93
|
-
{https://github.com/pdecourcel Paul de Courcel} for this.
|
94
|
-
|
95
|
-
* The Binary tree now supports +inorder+ traversal via the
|
96
|
-
{Tree::BinaryTreeNode#inordered_each} method.
|
97
|
-
|
98
|
-
* Ability to merge in another tree at a chosen node, or merge two trees to
|
99
|
-
create a third tree. Thanks to {https://github.com/dazoakley Darren Oakley}
|
100
|
-
for this ({https://github.com/evolve75/RubyTree/pull/2 pull request #2})
|
101
|
-
|
102
|
-
* RubyTree now mixes in the {http://ruby-doc.org/core-1.8.7/Comparable.html
|
103
|
-
Comparable} module.
|
104
|
-
|
105
|
-
==== The Fixes
|
106
|
-
|
107
|
-
* (Partial) fix for preventing cyclic graphs in the tree
|
108
|
-
|
109
|
-
* Refactored the {Tree::TreeNode#each} method to prevent stack errors while
|
110
|
-
navigating deep trees
|
111
|
-
({https://github.com/evolve75/RubyTree/issues/12 issue #12})
|
112
|
-
|
113
|
-
* Check to ensure that the added node's name is unique to the destination tree
|
114
|
-
({https://github.com/evolve75/RubyTree/pull/9 merge #9}). Thanks to
|
115
|
-
{https://github.com/ysf Youssef Rebahi-Gilbert} for the idea and the initial
|
116
|
-
code
|
117
|
-
|
118
|
-
* Fix for {issue 23}[https://github.com/evolve75/RubyTree/issues/23], where the
|
119
|
-
tree traversal on a binary tree would fail if the _left_ child was +nil+
|
120
|
-
|
121
|
-
* The traversal methods ({Tree::TreeNode#each},
|
122
|
-
{Tree::TreeNode#preordered_each}, {Tree::TreeNode#postordered_each} and
|
123
|
-
{Tree::TreeNode#breadth_each}) now correctly return an
|
124
|
-
{http://ruby-doc.org/core-1.8.7/Enumerable.html Enumerator} as the
|
125
|
-
return value when no block is given, and return the receiver node if a block was
|
126
|
-
provided. This is consistent with how the standard Ruby collections work.
|
127
|
-
|
128
|
-
==== Other Changes
|
129
|
-
|
130
|
-
* Structural changes in the code to refactor out the non-core functions into
|
131
|
-
modules (mostly by extracting out non-core code as mixins).
|
132
|
-
|
133
|
-
* Significant refactoring of the documentation. The {http://yardoc.org Yardoc}
|
134
|
-
tags are now extensively used.
|
135
|
-
|
136
|
-
* Basic support built-in for including example code in the Gem. This will be
|
137
|
-
fully expanded in the next release.
|
138
|
-
|
139
|
-
* Various changes to the {http://bundler.io bundler}, {https://travis-ci.org
|
140
|
-
travis-ci} and other Rakefile related changes.
|
141
|
-
|
142
|
-
=== 0.8.3 / 2012-08-21
|
143
|
-
|
144
|
-
This is a primarily a bug-fix release, with some packaging changes.
|
145
|
-
|
146
|
-
* Have removed the dependency on Hoe[https://github.com/seattlerb/hoe]. The
|
147
|
-
build is now vanilla
|
148
|
-
{gemspec}[http://guides.rubygems.org/specification-reference/] based.
|
149
|
-
|
150
|
-
* Included support for {gem-testers}[http://test.rubygems.org/].
|
151
|
-
|
152
|
-
* Included support for {Bundler}[http://gembundler.com/].
|
153
|
-
|
154
|
-
* Implemented the {Tree::Utils::JSONConverter#as_json} method to support Rails'
|
155
|
-
JSON encoding, by pulling in the changes by Eric Cline
|
156
|
-
(https://github.com/escline).
|
157
|
-
|
158
|
-
* Partial fix for {Github Bug
|
159
|
-
#5}[https://github.com/evolve75/RubyTree/issues/5]. This is to
|
160
|
-
prevent infinite looping is an existing node is added again
|
161
|
-
elsewhere in the tree.
|
162
|
-
|
163
|
-
* Fixed the issue with using +integers+ as node names, and its
|
164
|
-
interaction with the +Tree::TreeNode#[]+ access method as documented in
|
165
|
-
{Github Bug #6}[https://github.com/evolve75/RubyTree/issues/6].
|
166
|
-
|
167
|
-
* Clarified the need to have unique node names {Github Bug
|
168
|
-
#7}[https://github.com/evolve75/RubyTree/issues/7] (documentation).
|
169
|
-
|
170
|
-
* Fixed {Tree::TreeNode#siblings} method to return an empty array for the
|
171
|
-
root node as well (it returned +nil+ earlier).
|
172
|
-
|
173
|
-
=== 0.8.2 / 2011-12-15
|
174
|
-
|
175
|
-
* Minor bug-fix release to address bug #1215 ({Tree::TreeNode#to_s}
|
176
|
-
breaks if +@content+ or +@parent.name+ is not a string).
|
177
|
-
|
178
|
-
=== 0.8.1 / 2010-10-02
|
179
|
-
|
180
|
-
* This is the public release of +R0.8.0+, with additional bug-fixes.
|
181
|
-
Note that +R0.8.0+ will not be released separately as a publicly
|
182
|
-
available Rubygem. All changes as listed for +R0.8.0+ are available in
|
183
|
-
this release.
|
184
|
-
|
185
|
-
* The main change in +R0.8.0+/+R0.8.1+ is conversion of all CamelCase
|
186
|
-
method names to snake_case. The old CamelCase method names will
|
187
|
-
still work (to ensure backwards compatibility), but will also
|
188
|
-
display a warning.
|
189
|
-
|
190
|
-
* The {Tree::TreeNode#add} method now accepts an optional child insertion
|
191
|
-
point.
|
192
|
-
|
193
|
-
* The subtree from the current node can now be cloned in its entirety
|
194
|
-
using the {Tree::TreeNode#detached_subtree_copy} method.
|
195
|
-
|
196
|
-
* A major bug-fix for {bug #28613}[http://rubyforge.org/tracker/index.php?func=detail&aid=28613&group_id=1215&atid=4793]
|
197
|
-
which impacted the Binarytree implementation.
|
198
|
-
|
199
|
-
* Minor code re-factoring driven by the code-smell checks using
|
200
|
-
{reek}[https://github.com/troessner/reek].
|
201
|
-
|
202
|
-
* Inclusion of the +reek+ code-smell detection tool in the Rakefile.
|
203
|
-
|
204
|
-
=== 0.8.0 / 2010-05-04
|
205
|
-
|
206
|
-
* Updated the {Tree::TreeNode#add} method to allow the optional specification
|
207
|
-
of an insertion position in the child array.
|
208
|
-
|
209
|
-
* Added a new method {Tree::TreeNode#detached_subtree_copy} to allow cloning
|
210
|
-
the entire tree (this method is also aliased as +dup+).
|
211
|
-
|
212
|
-
* Converted all +CamelCase+ method names to the canonical +ruby_method_names+
|
213
|
-
(underscore separated). The +CamelCase+ methods _can still_ be invoked, but will
|
214
|
-
throw a {http://rug-b.rubyforge.org/structured_warnings/rdoc/ Deprecated
|
215
|
-
warning}.
|
216
|
-
The support for old CamelCase methods will go away some time in the future,
|
217
|
-
so the user is advised to convert all current method invocations
|
218
|
-
to the new names.
|
219
|
-
|
220
|
-
=== 0.7.0 / 2010-05-03
|
221
|
-
|
222
|
-
* Added new methods to report the degree statistics of a node.
|
223
|
-
|
224
|
-
* Added a convenience method alias
|
225
|
-
{Tree::Utils::TreeMetricsHandler#level Tree::TreeNode#level} to +nodeDepth+.
|
226
|
-
|
227
|
-
* Converted the exceptions thrown on invalid arguments to
|
228
|
-
{http://www.ruby-doc.org/core-2.0.0/ArgumentError.html ArgumentError}
|
229
|
-
instead of {http://www.ruby-doc.org/core-2.0.0/RuntimeError.html RuntimeError}.
|
230
|
-
|
231
|
-
* Converted the documentation to {http://yardoc.org Yard} format.
|
232
|
-
|
233
|
-
* Added new methods for converting from/to {http://www.json.org JSON} formats.
|
234
|
-
Thanks to Dirk Breuer[http://github.com/railsbros-dirk] for this
|
235
|
-
fork[http://github.com/galaxycats/].
|
236
|
-
|
237
|
-
* Added a separate {file:API-CHANGES.rdoc} documentation file.
|
238
|
-
|
239
|
-
* Added fixes for root related edge conditions to {Tree::TreeNode#is_only_child?
|
240
|
-
isOnlyChild?}, {Tree::TreeNode#next_sibling nextSibling},
|
241
|
-
{Tree::TreeNode#previous_sibling previousSibling} and
|
242
|
-
{Tree::TreeNode#remove! remove!} methods.
|
243
|
-
|
244
|
-
* Removed the 'ChangeLog' file as this can now be generated from the git logs.
|
245
|
-
|
246
|
-
* Other minor code cleanup.
|
247
|
-
|
248
|
-
=== 0.6.2 / 2010-01-30
|
249
|
-
|
250
|
-
* Updated the documentation.
|
251
|
-
|
252
|
-
=== 0.6.1 / 2010-01-04
|
253
|
-
|
254
|
-
* Changed the hard-dependency on the 'structured_warnings' RubyGem to a
|
255
|
-
soft-dependency - which lets Rubytree still work if this RubyGem is not
|
256
|
-
available. The rationale for this is that we should not require the user to
|
257
|
-
install a separate library just for one single edge-case function (in this
|
258
|
-
case, to indicate a deprecated method). However, if the library _is_ available
|
259
|
-
on the user's system, then it will get used.
|
260
|
-
|
261
|
-
=== 0.6.0 / 2010-01-03
|
262
|
-
|
263
|
-
* Fixed the
|
264
|
-
bug#22535[http://rubyforge.org/tracker/index.php?func=detail&aid=22535&group_id=1215&atid=4793]
|
265
|
-
where the {Tree::Utils::TreeMetricsHandler#depth Tree::TreeNode#depth} method
|
266
|
-
was actually returning height+1 (not the depth).
|
267
|
-
|
268
|
-
* Marked the {Tree::Utils::TreeMetricsHandler#depth Tree::TreeNode#depth}
|
269
|
-
method as *deprecated* (and introduced the run-time dependency on
|
270
|
-
structured-warnings[http://github.com/schmidt/structured_warnings] gem).
|
271
|
-
|
272
|
-
=== 0.5.3 / 2009-12-31
|
273
|
-
|
274
|
-
* Cleanup of the build system to exclusively use Hoe.
|
275
|
-
* Modifications and reformatting to the documentation.
|
276
|
-
* No user visible changes.
|
277
|
-
|
278
|
-
=== 0.5.2 / 2007-12-21
|
279
|
-
|
280
|
-
* Added more test cases and enabled
|
281
|
-
{https://github.com/seattlerb/zentest ZenTest} compatibility for the test case
|
282
|
-
names.
|
283
|
-
|
284
|
-
=== 0.5.1 / 2007-12-20
|
285
|
-
|
286
|
-
* Minor code refactoring.
|
287
|
-
|
288
|
-
=== 0.5.0 / 2007-12-18
|
289
|
-
|
290
|
-
* Fixed the marshalling code to correctly handle non-string content.
|
291
|
-
|
292
|
-
=== 0.4.3 / 2007-10-09
|
293
|
-
|
294
|
-
* Changes to the build mechanism (now uses
|
295
|
-
{http://www.zenspider.com/projects/hoe.html Hoe}).
|
296
|
-
|
297
|
-
=== 0.4.2 / 2007-10-01
|
298
|
-
|
299
|
-
* Minor code refactoring. Changes in the Rakefile.
|
300
|
-
|
301
|
-
;; Local Variables:
|
302
|
-
;; mode: rdoc
|
303
|
-
;; End:
|
@@ -1,77 +0,0 @@
|
|
1
|
-
# camel_case_methods.rb - This file is part of the RubyTree package.
|
2
|
-
#
|
3
|
-
# = camel_case_methods.rb - Provides conversion from CamelCase to snake_case.
|
4
|
-
#
|
5
|
-
# Author:: Anupam Sengupta (anupamsg@gmail.com)
|
6
|
-
#
|
7
|
-
# Time-stamp: <2021-12-29 13:02:04 anupam>
|
8
|
-
#
|
9
|
-
# Copyright (C) 2012, 2013, 2015, 2017, 2021 Anupam Sengupta <anupamsg@gmail.com>
|
10
|
-
#
|
11
|
-
# All rights reserved.
|
12
|
-
#
|
13
|
-
# Redistribution and use in source and binary forms, with or without
|
14
|
-
# modification, are permitted provided that the following conditions are met:
|
15
|
-
#
|
16
|
-
# - Redistributions of source code must retain the above copyright notice, this
|
17
|
-
# list of conditions and the following disclaimer.
|
18
|
-
#
|
19
|
-
# - Redistributions in binary form must reproduce the above copyright notice,
|
20
|
-
# this list of conditions and the following disclaimer in the documentation
|
21
|
-
# and/or other materials provided with the distribution.
|
22
|
-
#
|
23
|
-
# - Neither the name of the organization nor the names of its contributors may
|
24
|
-
# be used to endorse or promote products derived from this software without
|
25
|
-
# specific prior written permission.
|
26
|
-
#
|
27
|
-
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
28
|
-
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
29
|
-
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
30
|
-
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
|
31
|
-
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
32
|
-
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
33
|
-
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
34
|
-
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
35
|
-
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
36
|
-
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
37
|
-
#
|
38
|
-
|
39
|
-
require 'structured_warnings'
|
40
|
-
|
41
|
-
module Tree::Utils
|
42
|
-
# Provides utility functions to handle CamelCase methods, and redirect
|
43
|
-
# invocation of such methods to the snake_case equivalents.
|
44
|
-
module CamelCaseMethodHandler
|
45
|
-
def self.included(_base)
|
46
|
-
# @!visibility private
|
47
|
-
# Allow the deprecated CamelCase method names. Display a warning.
|
48
|
-
# :nodoc:
|
49
|
-
def method_missing(meth, *args, &blk)
|
50
|
-
if respond_to?((new_method_name = to_snake_case(meth)))
|
51
|
-
warn StructuredWarnings::DeprecatedMethodWarning,
|
52
|
-
'The camelCased methods are deprecated. ' +
|
53
|
-
"Please use #{new_method_name} instead of #{meth}"
|
54
|
-
send(new_method_name, *args, &blk)
|
55
|
-
else
|
56
|
-
super
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
# @!visibility private
|
61
|
-
# Convert a CamelCasedWord to a underscore separated camel_cased_word.
|
62
|
-
#
|
63
|
-
# @param [String] camel_cased_word The word to be converted to snake_case.
|
64
|
-
# @return [String] the snake_cased_word.
|
65
|
-
def to_snake_case(camel_cased_word)
|
66
|
-
word = camel_cased_word.to_s
|
67
|
-
word.gsub!(/::/, '/')
|
68
|
-
word.gsub!(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
|
69
|
-
word.gsub!(/([a-z\d])([A-Z])/, '\1_\2')
|
70
|
-
word.tr!('-', '_')
|
71
|
-
word.downcase!
|
72
|
-
word
|
73
|
-
end
|
74
|
-
protected :to_snake_case
|
75
|
-
end # self.included
|
76
|
-
end
|
77
|
-
end
|