Method: BiDimensionalTree#search
- Defined in:
- lib/bi-dimensional-access.rb
#search(x, y, node = @root) ⇒ Object
Locate a branch, if it exists
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/bi-dimensional-access.rb', line 58 def search(x, y, node = @root) return false if node.nil? if x == node.x if y == node.y return true elsif y < node.y and !node.south.nil? search(x, y, node.south) elsif y > node.y and !node.north.nil? search(x, y, node.north) else return false end elsif x < node.x and !node.west.nil? search(x, y, node.west) elsif x > node.x and !node.east.nil? search(x, y, node.east) else return false end end |