philiprehberger-tree 0.6.0 → 0.7.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/CHANGELOG.md +8 -0
- data/README.md +15 -0
- data/lib/philiprehberger/tree/node.rb +24 -0
- data/lib/philiprehberger/tree/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 18d116458c7316353a7876c8553cc05016b24e0abd7ebc30317c51919c75434a
|
|
4
|
+
data.tar.gz: 580e5b3c1ab53950728e43be7118d577b8cfd7a42c6849f46cfd95e856ff7a9f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: fb2b4327188f7a3ac49ed51f40d6c8d85e935a62b12af38abe911274c7fd21ff7bd47b228a8bf23cfb80570620a1d5b67d2d202a58208d6c97af2b0bb1c91325
|
|
7
|
+
data.tar.gz: aa48e67482c08f87b69ad2b321a796f33fe59931bcb2c6726c17b82a5a6149ff3e6910fdfae0e817c6413409555de7ea6551500f2163151aaa5438abcf020e0e
|
data/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [0.7.0] - 2026-04-26
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
- `Node#siblings` returns sibling nodes (children of the same parent, excluding self); empty array for root
|
|
14
|
+
- `Node#next_sibling` returns the next sibling in the parent's child order, or nil if last child or no parent
|
|
15
|
+
- `Node#prev_sibling` returns the previous sibling in the parent's child order, or nil if first child or no parent
|
|
16
|
+
|
|
10
17
|
## [0.6.0] - 2026-04-17
|
|
11
18
|
|
|
12
19
|
### Added
|
|
@@ -83,6 +90,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
83
90
|
- Visual tree printing via `print_tree`
|
|
84
91
|
- Add and remove child operations
|
|
85
92
|
|
|
93
|
+
[0.7.0]: https://github.com/philiprehberger/rb-tree/releases/tag/v0.7.0
|
|
86
94
|
[0.6.0]: https://github.com/philiprehberger/rb-tree/releases/tag/v0.6.0
|
|
87
95
|
[0.5.0]: https://github.com/philiprehberger/rb-tree/releases/tag/v0.5.0
|
|
88
96
|
[0.4.0]: https://github.com/philiprehberger/rb-tree/releases/tag/v0.4.0
|
data/README.md
CHANGED
|
@@ -135,6 +135,19 @@ grandchild.ancestors.map(&:value) # => ['child', 'root']
|
|
|
135
135
|
child.siblings.map(&:value) # => ['other_child']
|
|
136
136
|
```
|
|
137
137
|
|
|
138
|
+
### Sibling Navigation
|
|
139
|
+
|
|
140
|
+
```ruby
|
|
141
|
+
a = root.add_child('a')
|
|
142
|
+
b = root.add_child('b')
|
|
143
|
+
c = root.add_child('c')
|
|
144
|
+
|
|
145
|
+
b.next_sibling.value # => 'c'
|
|
146
|
+
b.prev_sibling.value # => 'a'
|
|
147
|
+
a.prev_sibling # => nil (first child)
|
|
148
|
+
c.next_sibling # => nil (last child)
|
|
149
|
+
```
|
|
150
|
+
|
|
138
151
|
### Leaf Collection
|
|
139
152
|
|
|
140
153
|
```ruby
|
|
@@ -194,6 +207,8 @@ root.prune(max_depth: 2).flatten
|
|
|
194
207
|
| `#==` | Structural equality comparison |
|
|
195
208
|
| `#ancestors` | Array of ancestors from parent to root |
|
|
196
209
|
| `#siblings` | Sibling nodes excluding self |
|
|
210
|
+
| `#next_sibling` | Next sibling in parent's child order, or nil |
|
|
211
|
+
| `#prev_sibling` | Previous sibling in parent's child order, or nil |
|
|
197
212
|
| `#map { \|value\| }` | New tree with transformed values |
|
|
198
213
|
| `#flatten` | All values as flat array (DFS pre-order) |
|
|
199
214
|
| `#each_with_depth` | Iterate yielding node and depth level |
|
|
@@ -198,6 +198,30 @@ module Philiprehberger
|
|
|
198
198
|
@parent.children.reject { |c| c.equal?(self) }
|
|
199
199
|
end
|
|
200
200
|
|
|
201
|
+
# Return the next sibling in the parent's child order.
|
|
202
|
+
#
|
|
203
|
+
# @return [Node, nil] the next sibling, or nil if this is the last child or has no parent
|
|
204
|
+
def next_sibling
|
|
205
|
+
return nil unless @parent
|
|
206
|
+
|
|
207
|
+
index = @parent.children.index { |c| c.equal?(self) }
|
|
208
|
+
return nil unless index
|
|
209
|
+
|
|
210
|
+
@parent.children[index + 1]
|
|
211
|
+
end
|
|
212
|
+
|
|
213
|
+
# Return the previous sibling in the parent's child order.
|
|
214
|
+
#
|
|
215
|
+
# @return [Node, nil] the previous sibling, or nil if this is the first child or has no parent
|
|
216
|
+
def prev_sibling
|
|
217
|
+
return nil unless @parent
|
|
218
|
+
|
|
219
|
+
index = @parent.children.index { |c| c.equal?(self) }
|
|
220
|
+
return nil if index.nil? || index.zero?
|
|
221
|
+
|
|
222
|
+
@parent.children[index - 1]
|
|
223
|
+
end
|
|
224
|
+
|
|
201
225
|
# Find the first node matching the block.
|
|
202
226
|
#
|
|
203
227
|
# @yield [Node] predicate block
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: philiprehberger-tree
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.7.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Philip Rehberger
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-04-
|
|
11
|
+
date: 2026-04-27 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
|
13
13
|
description: A generic tree data structure supporting depth-first and breadth-first
|
|
14
14
|
traversal, node search, path finding, and hash serialization. Each node tracks its
|