Class: RedBlackTreeImpl
- Inherits:
-
Object
- Object
- RedBlackTreeImpl
- Includes:
- IHash
- Defined in:
- lib/range_list/infrastructure/red_black_tree_impl.rb
Instance Method Summary collapse
- #delete(key) ⇒ Object
- #each(&block) ⇒ Object
-
#floor_range(key) ⇒ Object
Gets the entry corresponding to the specified key; if no such entry exists, returns the entry for the greatest key less than the specified key; if no such entry exists, returns nil.
-
#initialize ⇒ RedBlackTreeImpl
constructor
A new instance of RedBlackTreeImpl.
- #put(key, value) ⇒ Object
- #sub_hash_key(start_key, end_key) ⇒ Object
Constructor Details
#initialize ⇒ RedBlackTreeImpl
Returns a new instance of RedBlackTreeImpl.
8 9 10 |
# File 'lib/range_list/infrastructure/red_black_tree_impl.rb', line 8 def initialize @rbtree = RBTree.new end |
Instance Method Details
#delete(key) ⇒ Object
27 28 29 |
# File 'lib/range_list/infrastructure/red_black_tree_impl.rb', line 27 def delete(key) @rbtree.delete(key) end |
#each(&block) ⇒ Object
16 17 18 |
# File 'lib/range_list/infrastructure/red_black_tree_impl.rb', line 16 def each(&block) @rbtree.each(&block) end |
#floor_range(key) ⇒ Object
Gets the entry corresponding to the specified key; if no such entry exists, returns the entry for the greatest key less than the specified key; if no such entry exists, returns nil.
23 24 25 |
# File 'lib/range_list/infrastructure/red_black_tree_impl.rb', line 23 def floor_range(key) @rbtree.upper_bound(key) end |
#put(key, value) ⇒ Object
12 13 14 |
# File 'lib/range_list/infrastructure/red_black_tree_impl.rb', line 12 def put(key, value) @rbtree[key] = value end |
#sub_hash_key(start_key, end_key) ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/range_list/infrastructure/red_black_tree_impl.rb', line 31 def sub_hash_key(start_key, end_key) keys = [] @rbtree.bound(start_key, end_key).to_a.each do |k, v| keys.push k end keys end |