rooted_tree 0.2.2 → 0.2.3
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/README.md +1 -0
- data/lib/rooted_tree/node.rb +11 -7
- data/lib/rooted_tree/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 70e0e394dca29c945f79679ac2ade085f9210412
|
4
|
+
data.tar.gz: d8e06827ee6b284d2cc39140229125b5f0232428
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2b63502165e12f8d0ff158f07c2d2c010485f85f227ffbe05b1f73cc541907601c8a642816e568b8575a6cb7f7b2f4b41d901e5ffafe926a34b855077ea1764b
|
7
|
+
data.tar.gz: 29c29640e1f5e18812f994a76646e91e15b7e0bc5df125056707901e197a97455d5442cb6e19ff758221fc361663646d50a69b9d64331db5a836e51136c96346
|
data/README.md
CHANGED
@@ -3,6 +3,7 @@
|
|
3
3
|
[](http://badge.fury.io/rb/rooted_tree)
|
4
4
|
[](https://travis-ci.org/seblindberg/ruby-rooted_tree)
|
5
5
|
[](https://coveralls.io/github/seblindberg/ruby-rooted_tree?branch=master)
|
6
|
+
[](http://inch-ci.org/github/seblindberg/ruby-rooted_tree)
|
6
7
|
|
7
8
|
A tree is a connected graph with no cycles. There, that is plenty of explanation. Please refer to https://en.wikipedia.org/wiki/Tree_structure for a more in depth description, but if you need one this library probably is not for you.
|
8
9
|
|
data/lib/rooted_tree/node.rb
CHANGED
@@ -33,10 +33,10 @@ module RootedTree
|
|
33
33
|
|
34
34
|
def self.[](value = nil)
|
35
35
|
return value if value.is_a? self
|
36
|
-
|
36
|
+
new value
|
37
37
|
end
|
38
38
|
|
39
|
-
def initialize
|
39
|
+
def initialize(value = nil)
|
40
40
|
@parent = nil
|
41
41
|
@next = nil
|
42
42
|
@prev = nil
|
@@ -56,9 +56,9 @@ module RootedTree
|
|
56
56
|
end
|
57
57
|
|
58
58
|
def freeze
|
59
|
-
super
|
60
59
|
@value.freeze
|
61
60
|
children.each(&:freeze)
|
61
|
+
super
|
62
62
|
end
|
63
63
|
|
64
64
|
# Leaf?
|
@@ -399,15 +399,19 @@ module RootedTree
|
|
399
399
|
# Add
|
400
400
|
#
|
401
401
|
# Add two roots together to create a larger tree. A new common root will be
|
402
|
-
# created and returned.
|
402
|
+
# created and returned. Note that if the any of the root nodes are not
|
403
|
+
# frozen they will be modified, and as a result seize to be roots.
|
403
404
|
|
404
405
|
def +(other)
|
405
406
|
unless root? && other.root?
|
406
407
|
raise StructureException, 'Only roots can be added'
|
407
408
|
end
|
408
409
|
|
409
|
-
|
410
|
-
|
410
|
+
a = frozen? ? dup : self
|
411
|
+
b = other.frozen? ? other.dup : other
|
412
|
+
|
413
|
+
ab = self.class.new
|
414
|
+
ab << a << b
|
411
415
|
end
|
412
416
|
|
413
417
|
# Equality
|
@@ -465,7 +469,7 @@ module RootedTree
|
|
465
469
|
# |--Node:0x3ffd64c1fd30
|
466
470
|
# | |--Node:0x3ffd64c1f86c
|
467
471
|
# | +--Node:0x3ffd64c1f63c
|
468
|
-
# +--
|
472
|
+
# +--Node:0x3ffd64c1f40c
|
469
473
|
#
|
470
474
|
# By passing `as_array: true` the method will instead return an array
|
471
475
|
# containing each of the output lines. The method also accepts a block
|
data/lib/rooted_tree/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rooted_tree
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sebastian Lindberg
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-07-
|
11
|
+
date: 2016-07-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|