rbtree-ruby 0.1.5 → 0.1.6

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 56ddd66545f9e423b96066b12deea8e22fc86b35b7a97be056ebf91f80543e77
4
- data.tar.gz: 10a3ec88b0a5f5cb199ac96267d7665bfee99ab4fb9cf89488790fe798120b05
3
+ metadata.gz: bf6eb0a695ef93f89f9af8ceea5928c549785ea0110992f061b00ecdc76e3d64
4
+ data.tar.gz: 458cbee1ded3e8e0686ec495392bffbaf881ac0bc798d68790240abb0a3011b7
5
5
  SHA512:
6
- metadata.gz: 1d521a30299f8c3db327d1b671d84113cf3c9e5adc90a78747e76b7480ef02ceb95d813a90eeebadfd32e4b8360b2d43fffd1ed1ac4d9314d8368cbe137ce7aa
7
- data.tar.gz: 445a6cf0a99efdd0b5b4dc41dd86ec219e784cc3a2ecf150b4467e2619bcb08bd9b47d119d1c5310f43fdecdd7dc19941c3bfa4ae9e7b68d2b359819336f0a97
6
+ metadata.gz: 48ee9755aad89802b6cb1b6af19a7919151e14531f2c6e2f2dfbb07062c5e1060490e8d5244d0fd960f44d4eb8b00e84ee9f24e5b3be6319c808f212dde848c2
7
+ data.tar.gz: aeadf12c689069742c8cc05c569a84bbb6a87b3736f2f7e6351b68fb2aae5dbc24eca80e65a97455b50dae82b47c3ade7b8b70a171d86f879a179865eab9182d
data/CHANGELOG.md CHANGED
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [0.1.6] - 2026-01-13
9
+
10
+ ### Changed
11
+ - **Performance**: Standardized on Boolean colors (`true`/`false`) instead of Symbols (`:red`/`:black`) for faster checks.
12
+ - **Optimization**: `insert` operations now check the internal hash index first, allowing O(1) updates for existing keys (RBTree) and O(1) appends (MultiRBTree).
13
+
8
14
  ## [0.1.5] - 2026-01-13
9
15
 
10
16
  ### Changed
@@ -77,6 +83,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77
83
  - ASCII diagrams for tree rotation operations
78
84
  - MIT License (Copyright © 2026 Masahito Suzuki)
79
85
 
86
+ [0.1.6]: https://github.com/firelzrd/rbtree-ruby/releases/tag/v0.1.6
80
87
  [0.1.5]: https://github.com/firelzrd/rbtree-ruby/releases/tag/v0.1.5
81
88
  [0.1.4]: https://github.com/firelzrd/rbtree-ruby/releases/tag/v0.1.4
82
89
  [0.1.3]: https://github.com/firelzrd/rbtree-ruby/releases/tag/v0.1.3
@@ -2,5 +2,5 @@
2
2
 
3
3
  class RBTree
4
4
  # The version of the rbtree-ruby gem
5
- VERSION = "0.1.5"
5
+ VERSION = "0.1.6"
6
6
  end
data/lib/rbtree.rb CHANGED
@@ -174,6 +174,11 @@ class RBTree
174
174
  # tree.insert(1, 'uno', overwrite: false) # => nil (no change)
175
175
  # tree[2] = 'two' # using alias
176
176
  def insert(key, value, overwrite: true)
177
+ if (node = @hash_index[key])
178
+ return nil unless overwrite
179
+ node.value = value
180
+ return true
181
+ end
177
182
  y = @nil_node
178
183
  x = @root
179
184
  while x != @nil_node
@@ -1052,6 +1057,10 @@ class MultiRBTree < RBTree
1052
1057
  # tree.insert(1, 'first')
1053
1058
  # tree.insert(1, 'second') # adds another value for key 1
1054
1059
  def insert(key, value)
1060
+ if (node = @hash_index[key])
1061
+ node.value << value
1062
+ return true
1063
+ end
1055
1064
  y = @nil_node
1056
1065
  x = @root
1057
1066
  while x != @nil_node
@@ -1288,16 +1297,16 @@ end
1288
1297
  class RBTree::Node
1289
1298
  attr_accessor :key, :value, :color, :left, :right, :parent
1290
1299
 
1291
- # Red color constant
1292
- RED = :red
1293
- # Black color constant
1294
- BLACK = :black
1300
+ # Red color constant (true)
1301
+ RED = true
1302
+ # Black color constant (false)
1303
+ BLACK = false
1295
1304
 
1296
1305
  # Creates a new Node.
1297
1306
  #
1298
1307
  # @param key [Object] the key
1299
1308
  # @param value [Object] the value
1300
- # @param color [Symbol] the color (:red or :black)
1309
+ # @param color [Boolean] the color (true=red, false=black)
1301
1310
  # @param left [Node] the left child
1302
1311
  # @param right [Node] the right child
1303
1312
  # @param parent [Node] the parent node
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rbtree-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Masahito Suzuki