| Class | Batfish::BKTree::Node |
| In: |
lib/data/bktree.rb
|
| Parent: | Object |
This class represents a node in a BKTree.
| children | [R] | |
| value | [R] |
Add a node to a node in a recursive way.
# File lib/data/bktree.rb, line 113 def add(obj) distance = obj.distance_to(@value) if child = @children[distance] child.add(obj) else @children[distance] = Node.new(obj) end end
Calls block once for each object within threshold distance of the given object that are part of a child node of self.
# File lib/data/bktree.rb, line 126 def fetch_near(obj, threshold, &block) distance = @value.distance_to(obj) if distance <= threshold yield @value end ((distance - threshold)..(distance + threshold)).each do |d| if child = @children[d] child.fetch_near(obj, threshold, &block) end end end