red-black-tree 0.1.3 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +9 -0
- data/lib/red-black-tree.rb +28 -9
- data/lib/red_black_tree/node/data_delegation.rb +1 -1
- data/lib/red_black_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: b90594d4e04c47851ed0eaa18f0f517c37081a9c52c21ae5d4af66b142e2fdb1
|
4
|
+
data.tar.gz: de26391d21001786ee4f39859ef248985bbb5ca9750187f069219b3fdd72813e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: df049ff727c8918d99e255e44977281e378269620d04dbb16e3d6d1990e72416d85c1c42c7815de67d0c2f1366c68db463587d4cdfe56213cc6f45e4476f6648
|
7
|
+
data.tar.gz: dea0e150ee92555bff5af6e81cf81e4df9f75326a3c7e8bfa907c24b17dfa42f13548f113d9ec0b3448127a92794a0059701136eda88cd7c6fe0c44f5a75bfe9
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,14 @@
|
|
1
1
|
## [Unreleased]
|
2
2
|
|
3
|
+
## [0.1.5] - 2024-10-28
|
4
|
+
|
5
|
+
- Alias `RedBlackTree#search` as `RedBlackTree#find`
|
6
|
+
- Add `RedBlackTree#select`, aliased as `RedBlackTree#filter` and `RedBlackTree#find_all`
|
7
|
+
|
8
|
+
## [0.1.4] - 2024-10-27
|
9
|
+
|
10
|
+
- Fix incorrect `super` fallback in `RedBlackTree::DataDelegation#respond_to_missing?`
|
11
|
+
|
3
12
|
## [0.1.3] - 2024-10-21
|
4
13
|
|
5
14
|
- Make `RedBlackTree#left_most_node` public
|
data/lib/red-black-tree.rb
CHANGED
@@ -224,7 +224,7 @@ class RedBlackTree
|
|
224
224
|
# @return [RedBlackTree::Node, nil] the matching node
|
225
225
|
def search data = nil, &block
|
226
226
|
if block_given?
|
227
|
-
raise ArgumentError, "provide either data or block, not both" if data
|
227
|
+
raise ArgumentError, "provide either data or block, not both for search" if data
|
228
228
|
|
229
229
|
_search_by_block block, @root
|
230
230
|
else
|
@@ -233,6 +233,15 @@ class RedBlackTree
|
|
233
233
|
_search_by_data data, @root
|
234
234
|
end
|
235
235
|
end
|
236
|
+
alias_method :find, :search
|
237
|
+
|
238
|
+
def select &block
|
239
|
+
raise ArgumentError, "block must be provided for select" unless block
|
240
|
+
|
241
|
+
_select_by_block block, @root
|
242
|
+
end
|
243
|
+
alias_method :filter, :select
|
244
|
+
alias_method :find_all, :select
|
236
245
|
|
237
246
|
# Returns true if there is a node which matches the given data/value, and false if there is not.
|
238
247
|
#
|
@@ -327,14 +336,6 @@ class RedBlackTree
|
|
327
336
|
opp_direction_child
|
328
337
|
end
|
329
338
|
|
330
|
-
def _search_by_block block, node
|
331
|
-
traverse node do |current|
|
332
|
-
next if current.leaf?
|
333
|
-
|
334
|
-
return current if block.call current
|
335
|
-
end
|
336
|
-
end
|
337
|
-
|
338
339
|
def _search_by_data data, node
|
339
340
|
return if node.nil? || node.leaf?
|
340
341
|
return node if data == node.data
|
@@ -347,6 +348,24 @@ class RedBlackTree
|
|
347
348
|
end
|
348
349
|
end
|
349
350
|
|
351
|
+
def _search_by_block block, node
|
352
|
+
traverse node do |current|
|
353
|
+
next if current.leaf?
|
354
|
+
|
355
|
+
return current if block.call current
|
356
|
+
end
|
357
|
+
end
|
358
|
+
|
359
|
+
def _select_by_block block, node
|
360
|
+
[].tap do |result|
|
361
|
+
traverse node do |current|
|
362
|
+
next if current.leaf?
|
363
|
+
|
364
|
+
result << current if block.call current
|
365
|
+
end
|
366
|
+
end
|
367
|
+
end
|
368
|
+
|
350
369
|
def is_root? node
|
351
370
|
node && @root && node.object_id == @root.object_id
|
352
371
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: red-black-tree
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joshua Young
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-10-
|
11
|
+
date: 2024-10-27 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email:
|