#ifndef _GEO_HASH__ #define _GEO_HASH__ #include "point.h" #include #include #include #include #include #include #include struct ghash { static std::tuple decode(unsigned h) { const unsigned S=0x80000000; int x=0,y=0; for(int i=0;i<16;i++) { x<<=1; y<<=1; if(h&S) x|=1; h<<=1; if(h&S) y|=1; h<<=1; } return std::make_tuple(x-32768,y-32768); } static unsigned encode(int x, int y) { return encode_(x+32768,y+32768); } public: //test static void test_code(int x,int y) { unsigned h=ghash::encode(x,y); auto t=ghash::decode(h); printf("src x=%X,y=%X hash=%X,check x=%X,y=%X\n",x,y,h,std::get<0>(t),std::get<1>(t)); } static void test() { for(int i=0;i<10;i++) { test_code((4< geo2card; std::map card2geo; inline void find_near(std::vector&ret,int x,int y,unsigned h,uint32_t dist2,unsigned mask,uint64_t card_no); public: std::vector find_near(int x,int y,int dist,uint64_t card_no); //std::vector find_near(const char*card_no,int dist) std::vector find_near(uint64_t card_no,int dist); //void update(int x,int y,const char*card_no) void update(int x,int y,uint64_t card_no); size_t size() { return card2geo.size(); } void print() { for(auto it=card2geo.begin();it!=card2geo.end();++it) { std::cout<first<<"\n"; } } geo_list() { } ~geo_list() { } }; #endif