Class: Lite::Containers::AvlTree::Node

Inherits:
Object
  • Object
show all
Defined in:
lib/lite/containers/avl_tree/node.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key, value) ⇒ Node

Returns a new instance of Node.



16
17
18
19
20
21
22
# File 'lib/lite/containers/avl_tree/node.rb', line 16

def initialize(key, value)
  @key = key
  @value = value
  @height = 1
  @left = nil
  @right = nil
end

Instance Attribute Details

#heightObject

Returns the value of attribute height.



8
9
10
# File 'lib/lite/containers/avl_tree/node.rb', line 8

def height
  @height
end

#keyObject (readonly)

Returns the value of attribute key.



7
8
9
# File 'lib/lite/containers/avl_tree/node.rb', line 7

def key
  @key
end

#leftObject

Returns the value of attribute left.



8
9
10
# File 'lib/lite/containers/avl_tree/node.rb', line 8

def left
  @left
end

#rightObject

Returns the value of attribute right.



8
9
10
# File 'lib/lite/containers/avl_tree/node.rb', line 8

def right
  @right
end

#valueObject

Returns the value of attribute value.



8
9
10
# File 'lib/lite/containers/avl_tree/node.rb', line 8

def value
  @value
end

Class Method Details

.instance(key, value) ⇒ Object



10
11
12
# File 'lib/lite/containers/avl_tree/node.rb', line 10

def self.instance(key, value)
  new key, value
end

Instance Method Details

#inspectObject



28
29
30
31
# File 'lib/lite/containers/avl_tree/node.rb', line 28

def inspect
  lr = "#{left.nil? ? 0 : :L}|#{right.nil? ? 0 : :R}"
  "#<#{self.class.name} @key: #{key}, @value: #{value}, @height: #{height} #{lr}"
end

#outObject

Raises:

  • (NotImplementedError)


24
25
26
# File 'lib/lite/containers/avl_tree/node.rb', line 24

def out
  raise NotImplementedError, "#{self.class.name}##{__method__} unimplemented"
end