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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2b536af387a65d00a6d05596a8b209b32b500abf5cf156d5ab7169ab0149f6b2
4
- data.tar.gz: 0bc6b9317ee4659228b201d5feb0c3146b356c5831ebe00a003d5d4f491020dc
3
+ metadata.gz: b90594d4e04c47851ed0eaa18f0f517c37081a9c52c21ae5d4af66b142e2fdb1
4
+ data.tar.gz: de26391d21001786ee4f39859ef248985bbb5ca9750187f069219b3fdd72813e
5
5
  SHA512:
6
- metadata.gz: ea60c092e82dcecf019933df7348db451e10922437d4ac90c325fb1654ad5226738513b4a4d2e2ee45f19d2af86753c7f5932584a66ec0e90bf8c3ea0ce4836a
7
- data.tar.gz: c022d30679141753341dee36142b6690756d1797fe11e2dab34b4ddeeaafcc163693a3686bf4e2a324bd60951b869d9cd6d9496d49fed0c2a9fa4c7c3335751a
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
@@ -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
@@ -11,7 +11,7 @@ class RedBlackTree
11
11
  end
12
12
 
13
13
  def respond_to_missing? method_name, include_private = false
14
- @data.respond_to? method_name, include_private || super
14
+ (@data.respond_to? method_name, include_private) || super
15
15
  end
16
16
  end
17
17
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class RedBlackTree
4
- VERSION = "0.1.3"
4
+ VERSION = "0.1.5"
5
5
  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.3
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-21 00:00:00.000000000 Z
11
+ date: 2024-10-27 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email: