Class: RangeList::Map::TreeMap

Inherits:
Object
  • Object
show all
Includes:
SortedMap
Defined in:
lib/range_list/map/tree_map.rb

Overview

Sorted map implementation using red-black tree

Instance Method Summary collapse

Methods included from SortedMap

#higher_entry, #lower_entry

Constructor Details

#initializeTreeMap

Returns a new instance of TreeMap.



12
13
14
# File 'lib/range_list/map/tree_map.rb', line 12

def initialize
  @rbtree = RBTree.new
end

Instance Method Details

#ceiling_entry(key) ⇒ Object



32
33
34
# File 'lib/range_list/map/tree_map.rb', line 32

def ceiling_entry(key)
  @rbtree.lower_bound(key)
end

#each(&block) ⇒ Object



40
41
42
# File 'lib/range_list/map/tree_map.rb', line 40

def each(&block)
  @rbtree.each(&block)
end

#floor_entry(key) ⇒ Object



28
29
30
# File 'lib/range_list/map/tree_map.rb', line 28

def floor_entry(key)
  @rbtree.upper_bound(key)
end

#get(key) ⇒ Object



16
17
18
# File 'lib/range_list/map/tree_map.rb', line 16

def get(key)
  @rbtree[key]
end

#put(key, value) ⇒ Object



20
21
22
# File 'lib/range_list/map/tree_map.rb', line 20

def put(key, value)
  @rbtree[key] = value
end

#remove(key) ⇒ Object



24
25
26
# File 'lib/range_list/map/tree_map.rb', line 24

def remove(key)
  @rbtree.delete(key)
end

#sub_map(from_key, to_key) ⇒ Object



36
37
38
# File 'lib/range_list/map/tree_map.rb', line 36

def sub_map(from_key, to_key)
  @rbtree.bound(from_key, to_key).to_a
end