Class: IntervalTree::Node

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

Overview

class Tree

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(x_center, s_center, left_node, right_node) ⇒ Node

Returns a new instance of Node.



97
98
99
100
101
102
# File 'lib/interval_tree.rb', line 97

def initialize(x_center, s_center, left_node, right_node)
  @x_center = x_center
  @s_center = s_center
  @left_node = left_node
  @right_node = right_node
end

Instance Attribute Details

#left_nodeObject (readonly)

Returns the value of attribute left_node.



103
104
105
# File 'lib/interval_tree.rb', line 103

def left_node
  @left_node
end

#right_nodeObject (readonly)

Returns the value of attribute right_node.



103
104
105
# File 'lib/interval_tree.rb', line 103

def right_node
  @right_node
end

#s_centerObject (readonly)

Returns the value of attribute s_center.



103
104
105
# File 'lib/interval_tree.rb', line 103

def s_center
  @s_center
end

#x_centerObject (readonly)

Returns the value of attribute x_center.



103
104
105
# File 'lib/interval_tree.rb', line 103

def x_center
  @x_center
end

Instance Method Details

#==(other) ⇒ Object



105
106
107
108
109
110
# File 'lib/interval_tree.rb', line 105

def ==(other)
  x_center == other.x_center &&
  s_center == other.s_center &&
  left_node == other.left_node &&
  right_node == other.right_node
end

#search(query) ⇒ Object

Search by range only



113
114
115
116
117
# File 'lib/interval_tree.rb', line 113

def search(query)
  search_s_center(query) +
    (left_node && query.begin.to_r < x_center && left_node.search(query) || []) +
    (right_node && query.end.to_r > x_center && right_node.search(query) || [])
end