@@ -20,16 +20,16 @@ typedef struct TestEncodeItem {
2020 const char *expected;
2121} TestEncodeItem_t;
2222
23- static const char *geohash_str (uint64_t geohash, int8_t prec ) ;
23+ static const char *geohash_str (uint64_t geohash) ;
2424
2525static void tesnEncodeU64 () {
2626 double lat = 27.988056 ;
2727 double lon = 86.925278 ;
2828 uint64_t exp = 0xceb7f254240fd612 ;
29- uint64_t act = GeohashEncodeU64 (lat, lon);
29+ uint64_t act = GeohashEncodeU64 (lat, lon, GEOHASH_MAX_PRECISION );
3030 assert (exp == act);
3131 // tuvz4p141zc1
32- std::cout << geohash_str (act, GEOHASH_MAX_PRECISION ) << std::endl;
32+ std::cout << geohash_str (act) << std::endl;
3333}
3434// /////////////////////////////////////////////////////
3535
@@ -39,15 +39,13 @@ static const char base32Table[BASE32_COUNT] = {'0', '1', '2', '3', '4', '5', '6'
3939 ' h' , ' j' , ' k' , ' m' , ' n' , ' p' , ' q' , ' r' ,
4040 ' s' , ' t' , ' u' , ' v' , ' w' , ' x' , ' y' , ' z' };
4141
42- const char *geohash_str (uint64_t geohash, int8_t prec ) {
42+ const char *geohash_str (uint64_t geohash) {
4343 static char buff[GEOHASH_MAX_PRECISION+1 ] = {0 };
44- char *str = buff + prec + 1 ;
45- int idx;
44+ char *str = buff + GEOHASH_MAX_PRECISION + 1 ;
4645 *str = 0 ;
47- geohash >>= ((GEOHASH_MAX_PRECISION-prec) * 5 ) + 4 ; // cause we don't need last 4 bits
48- while (prec--){
49- idx = geohash & 0x1f ;
50- *--str = base32Table[idx];
46+ geohash >>= 4 ; // cause we don't need last 4 bits. that's strange, I thought we don't need first 4 bits %)
47+ while (geohash){
48+ *--str = base32Table[geohash & 0x1f ];
5149 geohash >>= 5 ;
5250 }
5351 return str;
@@ -86,14 +84,14 @@ static void testEncode() {
8684 TestEncodeItem_t *tmp;
8785
8886 for (tmp = posTests; tmp->expected ; ++tmp) {
89- uint64_t geohash = GeohashEncodeU64 (tmp->lat , tmp->lon );
90- const char *geostr = geohash_str (geohash, tmp-> precision );
87+ uint64_t geohash = GeohashEncodeU64 (tmp->lat , tmp->lon , tmp-> precision );
88+ const char *geostr = geohash_str (geohash);
9189 assert (strcmp (geostr, tmp->expected ) == 0 );
9290 }
9391
9492 for (tmp = negTests; tmp->expected ; ++tmp) {
95- uint64_t geohash = GeohashEncodeU64 (tmp->lat , tmp->lon );
96- const char *geostr = geohash_str (geohash, tmp-> precision );
93+ uint64_t geohash = GeohashEncodeU64 (tmp->lat , tmp->lon , tmp-> precision );
94+ const char *geostr = geohash_str (geohash);
9795 assert (strcmp (geostr, tmp->expected ) != 0 );
9896 }
9997}
0 commit comments