Class: IntervalTree::Node
- Inherits:
-
Object
- Object
- IntervalTree::Node
- Defined in:
- lib/interval_tree.rb
Overview
class Tree
Instance Attribute Summary collapse
-
#left_node ⇒ Object
readonly
Returns the value of attribute left_node.
-
#right_node ⇒ Object
readonly
Returns the value of attribute right_node.
-
#s_center ⇒ Object
readonly
Returns the value of attribute s_center.
-
#x_center ⇒ Object
readonly
Returns the value of attribute x_center.
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize(x_center, s_center, left_node, right_node) ⇒ Node
constructor
A new instance of Node.
-
#search(query) ⇒ Object
Search by range only.
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_node ⇒ Object (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_node ⇒ Object (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_center ⇒ Object (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_center ⇒ Object (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 |