Class: LeftLeaningRedBlackTree::Tree

Inherits:
Object
  • Object
show all
Defined in:
lib/left_leaning_red_black_tree.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeTree

Returns a new instance of Tree.



7
8
9
# File 'lib/left_leaning_red_black_tree.rb', line 7

def initialize
  @root = NullNode.new
end

Instance Attribute Details

#rootObject

Returns the value of attribute root.



5
6
7
# File 'lib/left_leaning_red_black_tree.rb', line 5

def root
  @root
end

Instance Method Details

#delete(key) ⇒ Object



16
17
18
19
# File 'lib/left_leaning_red_black_tree.rb', line 16

def delete(key)
  @root = @root.delete(key)
  @root.color = BLACK
end

#insert(key, payload) ⇒ Object



11
12
13
14
# File 'lib/left_leaning_red_black_tree.rb', line 11

def insert(key, payload)
  @root = @root.insert(key, payload)
  @root.color = BLACK
end


21
22
23
# File 'lib/left_leaning_red_black_tree.rb', line 21

def print_tree
  root.print_node([@root], 1, @root.max_level)
end