Skip to content

Commit

Permalink
update geohash decode, 300% faster now
Browse files Browse the repository at this point in the history
  • Loading branch information
yinqiwen committed Sep 18, 2014
1 parent 43f4bad commit f886601
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 18 deletions.
16 changes: 8 additions & 8 deletions ardb.conf
Original file line number Diff line number Diff line change
Expand Up @@ -401,26 +401,26 @@ check_type_before_set_string 0
# Hashes are encoded using a memory efficient data structure when they have a
# small number of entries, and the biggest entry does not exceed a given
# threshold. These thresholds can be configured using the following directives.
hash-max-ziplist-entries 128
hash-max-ziplist-value 64
hash-max-ziplist-entries 256
hash-max-ziplist-value 256

# Similarly to hashes, small lists are also encoded in a special way in order
# to save a lot of space. The special representation is only used when
# you are under the following limits:
list-max-ziplist-entries 128
list-max-ziplist-value 64
list-max-ziplist-entries 256
list-max-ziplist-value 256

# Similarly to hashes and lists, sorted sets are also specially encoded in
# order to save a lot of space. This encoding is only used when the length and
# elements of a sorted set are below the following limits:
set-max-ziplist-entries 128
set-max-ziplist-value 64
set-max-ziplist-entries 256
set-max-ziplist-value 256

# Similarly to hashes and lists, sorted sets are also specially encoded in
# order to save a lot of space. This encoding is only used when the length and
# elements of a sorted set are below the following limits:
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
zset-max-ziplist-entries 256
zset-max-ziplist-value 256

# Experiment: L1 cahce is the high level LRU cache holded in memory.
# Use 'CACHE LOAD key' to load a key in L1 cache, 'CACHE EVICT key' to evict one, 'CACHE STATUS key' to view status for a key.
Expand Down
17 changes: 7 additions & 10 deletions src/common/geo/geohash.c
Original file line number Diff line number Diff line change
Expand Up @@ -243,16 +243,13 @@ int geohash_fast_decode(GeoHashRange lat_range, GeoHashRange lon_range, GeoHashB
uint32_t ilato = xyhilo; //get back the original integer coordinates
uint32_t ilono = xyhilo >> 32;

//double lat_offset=ilato;
//double lon_offset=ilono;
//lat_offset /= (1<<step);
//lon_offset /= (1<<step);

//the ldexp call converts the integer to a double,then divides by 2**step to get the 0-1 coordinate, which is then multiplied times scale and added to the min to get the absolute coordinate
area->latitude.min = lat_range.min + ldexp(ilato, -step) * lat_scale;
area->latitude.max = lat_range.min + ldexp(ilato + 1, -step) * lat_scale;
area->longitude.min = lon_range.min + ldexp(ilono, -step) * lon_scale;
area->longitude.max = lon_range.min + ldexp(ilono + 1, -step) * lon_scale;
/*
* much faster than 'ldexp'
*/
area->latitude.min = lat_range.min + (ilato * 1.0 / (1ull << step)) * lat_scale;
area->latitude.max = lat_range.min + ((ilato + 1) * 1.0 / (1ull << step)) * lat_scale;
area->longitude.min = lon_range.min + (ilono * 1.0 / (1ull << step)) * lon_scale;
area->longitude.max = lon_range.min + ((ilono + 1) * 1.0 / (1ull << step)) * lon_scale;

return 0;
}
Expand Down

0 comments on commit f886601

Please sign in to comment.