rbtree-ruby 0.1.1 → 0.1.2

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: 047f125ed11edef5fa998d90ff50d80f90879a065d6407b02184d21089f0b1a8
4
- data.tar.gz: 1bb83c26b7aca89d6cce328298f51d9ba9c3e1e5b7fc1ea2adf3b59c88bf2c40
3
+ metadata.gz: 59400faa90822b08dbe1fc115c6bf28f526b4e139924e1950f625ac552f5124c
4
+ data.tar.gz: 3f7bda0222388236a6b9f0b8fc4e8fef0cc5e365b1b98eddceef73ec3c1d8114
5
5
  SHA512:
6
- metadata.gz: '0847bf075101301c924d093b9561c6fe014efbd9bfbc94020427c0382ab38608c275f5e50e0df7221c21b21afc2282de920273bc22dbbb11db2822a367cabc8f'
7
- data.tar.gz: 5b0bc3e6f05ffa239b0316c8927380eddfb322b5e207001930354f5482748f0b148bfd2a42b8796ae83fd19f0b7dd97d9f5b863fcc1500094406b7731bbf3c78
6
+ metadata.gz: b2207668d8974b8af9e0261c819d3a63f537b557d9f1188799026524d27dd23703f020fb3ce397047bd6b9434cc3f079e42e68152f33fa9bd69ede97b4e66530
7
+ data.tar.gz: 593e5575adb4755b6a2212144ca56920918fe31a5a0b048e37655b5729216ee4bfe3f3ae43f5477ec2c8b9e0d2e1cf2ef4dca5df1208f757fef85a643c9b1c7d
data/CHANGELOG.md CHANGED
@@ -5,6 +5,20 @@ 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.2] - 2026-01-13
9
+
10
+ ### Changed
11
+ - **Replaced `RBTree::LinkedList` with Ruby Array** in MultiRBTree
12
+ - 6-8x performance improvement for all operations (shift, pop, append)
13
+ - Removed `RBTree::LinkedList` and `RBTree::LinkedList::Node` classes
14
+ - `get_all` now returns Array instead of LinkedList
15
+ - Benchmark results: 100K shift operations 452ms → 69ms
16
+
17
+ ## [0.1.1] - 2026-01-13
18
+
19
+ ### Fixed
20
+ - Fixed syntax error in `RBTree::LinkedList.[]` method (escaped newline issue)
21
+
8
22
  ## [0.1.0] - 2026-01-13
9
23
 
10
24
  ### Added
@@ -35,4 +49,4 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
35
49
  - ASCII diagrams for tree rotation operations
36
50
  - MIT License (Copyright © 2026 Masahito Suzuki)
37
51
 
38
- [0.1.0]: https://github.com/firelzrd/rbtree-ruby/releases/tag/v0.1.0
52
+ [0.1.2]: https://github.com/firelzrd/rbtree-ruby/releases/tag/v0.1.2
data/README.md CHANGED
@@ -99,7 +99,7 @@ tree.get(1) # => "first one"
99
99
  tree[1] # => "first one"
100
100
 
101
101
  # Get all values for a key
102
- tree.get_all(1) # => LinkedList with ["first one", "second one", "third one"]
102
+ tree.get_all(1) # => ["first one", "second one", "third one"]
103
103
 
104
104
  # Iterate over all key-value pairs
105
105
  tree.each { |k, v| puts "#{k}: #{v}" }
@@ -2,5 +2,5 @@
2
2
 
3
3
  class RBTree
4
4
  # The version of the rbtree-ruby gem
5
- VERSION = "0.1.1"
5
+ VERSION = "0.1.2"
6
6
  end
data/lib/rbtree.rb CHANGED
@@ -50,7 +50,7 @@ require_relative "rbtree/version"
50
50
  # Iteration over all elements takes O(n) time.
51
51
  #
52
52
  # @author Masahito Suzuki
53
- # @since 0.1.1
53
+ # @since 0.1.0
54
54
  class RBTree
55
55
  include Enumerable
56
56
 
@@ -963,7 +963,7 @@ end
963
963
  # tree.delete(1) # removes all remaining values for key 1
964
964
  #
965
965
  # @author Masahito Suzuki
966
- # @since 0.1.0
966
+ # @since 0.1.2
967
967
  class MultiRBTree < RBTree
968
968
  # Retrieves the first value associated with the given key.
969
969
  #
@@ -983,7 +983,7 @@ class MultiRBTree < RBTree
983
983
  # Retrieves all values associated with the given key.
984
984
  #
985
985
  # @param key [Object] the key to look up
986
- # @return [LinkedList, nil] a LinkedList containing all values, or nil if not found
986
+ # @return [Array, nil] an Array containing all values, or nil if not found
987
987
  # @example
988
988
  # tree = MultiRBTree.new
989
989
  # tree.insert(1, 'first')
@@ -1022,7 +1022,7 @@ class MultiRBTree < RBTree
1022
1022
  x = x.right
1023
1023
  end
1024
1024
  end
1025
- z = Node.new(key, LinkedList[value], Node::RED, @nil_node, @nil_node, @nil_node)
1025
+ z = Node.new(key, [value], Node::RED, @nil_node, @nil_node, @nil_node)
1026
1026
  z.parent = y
1027
1027
  if y == @nil_node
1028
1028
  @root = z
@@ -1074,7 +1074,7 @@ class MultiRBTree < RBTree
1074
1074
  # Removes the node and all associated values.
1075
1075
  #
1076
1076
  # @param key [Object] the key to delete
1077
- # @return [LinkedList, nil] the list of all deleted values, or nil if not found
1077
+ # @return [Array, nil] the array of all deleted values, or nil if not found
1078
1078
  # @example
1079
1079
  # tree = MultiRBTree.new
1080
1080
  # tree.insert(1, 'first')
@@ -1258,113 +1258,3 @@ class RBTree::Node
1258
1258
  def black? = @color == BLACK
1259
1259
  end
1260
1260
 
1261
- # A doubly-linked list used by MultiRBTree to store multiple values per key.
1262
- #
1263
- # This internal data structure maintains insertion order and supports efficient
1264
- # operations at both ends of the list.
1265
- #
1266
- # @api private
1267
- class RBTree::LinkedList
1268
- # Returns the number of values in the list.
1269
- # @return [Integer] the size
1270
- attr_reader :size
1271
-
1272
- # Creates a new LinkedList from the given values.
1273
- #
1274
- # @param values [Array<Object>] initial values
1275
- # @return [LinkedList] a new list
1276
- def self.[](*values)
1277
- list = new
1278
- values.each do |value|
1279
- list << value
1280
- end
1281
- list
1282
- end
1283
-
1284
- # Creates a new empty LinkedList.
1285
- def initialize
1286
- @stop = Node.new(nil, nil, nil)
1287
- @stop.prev = @stop.succ = @stop
1288
- @size = 0
1289
- end
1290
-
1291
- # Iterates over values in forward order.
1292
- # @yield [value] each value in the list
1293
- def each
1294
- node = @stop.succ
1295
- while node != @stop
1296
- yield node.value
1297
- node = node.succ
1298
- end
1299
- end
1300
-
1301
- # Iterates over values in reverse order.
1302
- # @yield [value] each value in reverse
1303
- def reverse_each
1304
- node = @stop.prev
1305
- while node != @stop
1306
- yield node.value
1307
- node = node.prev
1308
- end
1309
- end
1310
-
1311
- # Checks if the list is empty.
1312
- # @return [Boolean] true if empty
1313
- def empty? = @stop.succ == @stop
1314
-
1315
- # Returns the first value.
1316
- # @return [Object, nil] the first value or nil if empty
1317
- def first = empty? ? nil : @stop.succ.value
1318
-
1319
- # Returns the last value.
1320
- # @return [Object, nil] the last value or nil if empty
1321
- def last = empty? ? nil : @stop.prev.value
1322
-
1323
- # Appends a value to the end of the list.
1324
- # @param value [Object] the value to append
1325
- # @return [LinkedList] self
1326
- def <<(value)
1327
- @stop.prev = @stop.prev.succ = Node.new(value, @stop.prev, @stop)
1328
- @size += 1
1329
- self
1330
- end
1331
-
1332
- # Removes and returns the first value.
1333
- # @return [Object, nil] the first value or nil if empty
1334
- def shift
1335
- return nil if empty?
1336
- value = @stop.succ.value
1337
- (@stop.succ = @stop.succ.succ).prev = @stop
1338
- @size -= 1
1339
- value
1340
- end
1341
-
1342
- # Removes and returns the last value.
1343
- # @return [Object, nil] the last value or nil if empty
1344
- def pop
1345
- return nil if empty?
1346
- value = @stop.prev.value
1347
- (@stop.prev = @stop.prev.prev).succ = @stop
1348
- @size -= 1
1349
- value
1350
- end
1351
- end
1352
-
1353
- # Internal node structure for LinkedList.
1354
- # @api private
1355
- class RBTree::LinkedList::Node
1356
- # @return [Object] the value stored in this node
1357
- attr_accessor :value
1358
- # @return [Node] the previous node
1359
- attr_accessor :prev
1360
- # @return [Node] the successor node
1361
- attr_accessor :succ
1362
-
1363
- # Creates a new list node.
1364
- # @param value [Object] the value
1365
- # @param prev [Node] the previous node
1366
- # @param succ [Node] the successor node
1367
- def initialize(value, prev, succ)
1368
- @value, @prev, @succ = value, prev, succ
1369
- end
1370
- end
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.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Masahito Suzuki