Skip to content

Commit

Permalink
issue #6: bug fix for fast_encode
Browse files Browse the repository at this point in the history
  • Loading branch information
yinqiwen committed Aug 16, 2017
1 parent b01291b commit d57e70e
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
7 changes: 5 additions & 2 deletions geohash.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ int geohash_encode(
hash->bits += lon_bit;
hash->bits <<= 1;
hash->bits += lat_bit;
if (i == (step - 1)){

}
}
return 0;
}
Expand Down Expand Up @@ -222,8 +225,8 @@ int geohash_fast_encode(
double lon_offset = (longitude - lon_range.min) / (lon_range.max - lon_range.min);

//convert it to fixed point based on the step size
lat_offset *= (1 << step);
lon_offset *= (1 << step);
lat_offset *= (1LL << step);
lon_offset *= (1LL << step);

uint32_t ilato = (uint32_t) lat_offset;
uint32_t ilono = (uint32_t) lon_offset;
Expand Down
28 changes: 27 additions & 1 deletion test-geohash.c
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,34 @@ int test_2()
return 0;
}

int main() {
void test_3()
{
GeoHashBits hash, fast_hash;

GeoHashRange lat_range, lon_range;
lat_range.max = 90.0;
lat_range.min = -90.0;
lon_range.max = 180.0;
lon_range.min = -180.0;

double latitude = 12.34;
double longitude = 56.78;

for (int step = 1; step <= 32; step++)
{
geohash_encode(lat_range, lon_range, latitude, longitude, step, &hash);
geohash_fast_encode(lat_range, lon_range, latitude, longitude, step, &fast_hash);

printf("normal encode (%d): %llu\n", step, hash.bits);
printf("fast encode (%d): %llu\n", step, fast_hash.bits);
printf("\n");
}
}

int main()
{
test_1();
test_2();
test_3();
return 0;
}

0 comments on commit d57e70e

Please sign in to comment.