require "xml/libxml"
require "set"
require "time"
-require "simple-mmap"
module Expire
# projection object to go from latlon -> spherical mercator
# the size of the meta tile blocks
METATILE = 8
# the directory root for meta tiles
- HASH_ROOT = "/tiles/default/"
+ HASH_ROOT = "/tiles/default/".freeze
# node cache file
- NODE_CACHE_FILE = "/store/database/nodes"
+ NODE_CACHE_FILE = "/store/database/nodes".freeze
# turns a spherical mercator coord into a tile coord
def self.tile_from_merc(point, zoom)
nodes[node_id] = tile_from_merc(point, max_zoom)
end
end
+ node_cache.close
# create a set of all the tiles at the maximum zoom level which are touched by
# any of the nodes we've collected. we'll create the tiles at other zoom levels
set = Set.new nodes.values
# expire tiles and shrink to the set of parents
- (max_zoom).downto(min_zoom) do |_|
+ max_zoom.downto(min_zoom) do |_|
# allow the block to work on the set, returning the set at the next
# zoom level
set = yield set
# open the cache
def initialize(filename)
- @cache = SimpleMmap::FileWindow.open(filename)
+ @cache = File.new(filename, "r")
- throw "Unexpected format" unless @cache[0..3].unpack("l").first == 1
- throw "Unexpected ID size" unless @cache[4..7].unpack("l").first == 8
+ throw "Unexpected format" unless @cache.sysread(4).unpack("l").first == 1
+ throw "Unexpected ID size" unless @cache.sysread(4).unpack("l").first == 8
- @max_id = @cache[8..15].unpack("q").first
+ @max_id = @cache.sysread(8).unpack("q").first
+ end
+
+ # close the cache
+ def close
+ @cache.close
end
# lookup a node
if id <= @max_id
offset = 16 + id * 8
- lon, lat = @cache[offset..offset + 7].unpack("ll")
+ @cache.sysseek(offset)
+
+ lon, lat = @cache.sysread(8).unpack("ll")
if lon != -2147483648 && lat != -2147483648
node = Node.new(lon, lat)