Skip to content

Commit

Permalink
Refactor region detection to avoid duplicate regions in first loop.
Browse files Browse the repository at this point in the history
  • Loading branch information
gravitystorm committed Jul 9, 2012
1 parent e59d924 commit c562528
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions run_regions.rb
Expand Up @@ -24,8 +24,10 @@
@conn.exec("truncate table regions")

def add_region(lat, lon)
@conn.exec("insert into regions (lat, lon) values ($1, $2)", [lat, lon])
@regions[[lat, lon]] = true
unless @regions.key?([lat, lon])
@conn.exec("insert into regions (lat, lon) values ($1, $2)", [lat, lon])
@regions[[lat, lon]] = true
end
end

@conn.transaction do
Expand All @@ -48,9 +50,7 @@ def add_region(lat, lon)
# Add remaining regions that weren't covered by the bounds
(-180..179).each do |lon|
(-90..89).each do |lat|
unless @regions.key?([lat, lon])
add_region(lat, lon)
end
add_region(lat, lon)
end
end
end
Expand Down

0 comments on commit c562528

Please sign in to comment.