Skip to content

Commit

Permalink
Improve code style
Browse files Browse the repository at this point in the history
  • Loading branch information
threedaymonk committed Jul 11, 2012
1 parent 394a562 commit 10b6f5b
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions lib/bk.rb
Expand Up @@ -24,7 +24,7 @@ def initialize(term, distancer)
def add(term)
score = distance(term)
if child = children[score]
child.add(term)
child.add term
else
children[score] = Node.new(term, @distancer)
end
Expand All @@ -33,14 +33,14 @@ def add(term)
def query(term, threshold, collected)
distance_at_node = distance(term)
collected[self.term] = distance_at_node if distance_at_node <= threshold
((distance_at_node-threshold)..(threshold+distance_at_node)).each do |score|
child = children[score]
child.query(term, threshold, collected) if child
(-threshold..threshold).each do |d|
child = children[distance_at_node + d] or next
child.query term, threshold, collected
end
end

def distance(term)
@distancer.call(term, self.term)
@distancer.call term, self.term
end
end

Expand All @@ -52,20 +52,20 @@ def initialize(distancer = LevenshteinDistancer.new)

def add(term)
if @root
@root.add(term)
@root.add term
else
@root = Node.new(term, @distancer)
end
end

def query(term, threshold)
collected = {}
@root.query(term, threshold, collected)
@root.query term, threshold, collected
return collected
end

def export(stream)
stream.write(YAML.dump(self))
stream.write YAML.dump(self)
end

def self.import(stream)
Expand Down

0 comments on commit 10b6f5b

Please sign in to comment.