null+****@clear*****
null+****@clear*****
2010年 8月 3日 (火) 15:24:38 JST
Kouhei Sutou 2010-08-03 06:24:38 +0000 (Tue, 03 Aug 2010) New Revision: 3b493e2277b90eed36129fd2625494084326ec80 Log: show geo point encoded byte string in inspection. Modified files: lib/groonga_in.h lib/pat.c lib/util.c test/unit/core/test-inspect.c test/unit/core/test-table-patricia-trie-cursor.c Modified: lib/groonga_in.h (+37 -0) =================================================================== --- lib/groonga_in.h 2010-08-02 09:20:09 +0000 (c77efc6) +++ lib/groonga_in.h 2010-08-03 06:24:38 +0000 (933dff3) @@ -511,6 +511,43 @@ grn_str_greater(const uint8_t *ap, uint32_t as, const uint8_t *bp, uint32_t bs) #endif /* WORDS_BIGENDIAN */ #define grn_ntoh grn_hton +#define grn_gton(keybuf,key,size)\ +{\ + uint8_t *keybuf_ = keybuf;\ + const void *key_ = key;\ + int la = ((grn_geo_point *)key_)->latitude;\ + int lo = ((grn_geo_point *)key_)->longitude;\ + uint8_t *p = keybuf_;\ + int i = 32;\ + while (i) {\ + i -= 4;\ + *p++ = ((((la >> i) & 8) << 4) + (((lo >> i) & 8) << 3) +\ + (((la >> i) & 4) << 3) + (((lo >> i) & 4) << 2) +\ + (((la >> i) & 2) << 2) + (((lo >> i) & 2) << 1) +\ + (((la >> i) & 1) << 1) + (((lo >> i) & 1) << 0));\ + }\ +} + +#define grn_ntog(keybuf,key,size)\ +{\ + uint8_t *keybuf_ = keybuf;\ + uint8_t *key_ = key;\ + uint32_t size_ = size;\ + int la = 0, lo = 0;\ + uint8_t v, *p = key_;\ + int i = 32;\ + while (size_--) {\ + i -= 4;\ + v = *p++;\ + la += (((v & 128) >> 4) + ((v & 32) >> 3) +\ + ((v & 8) >> 2) + ((v & 2) >> 1)) << i;\ + lo += (((v & 64) >> 3) + ((v & 16) >> 2) +\ + ((v & 4) >> 1) + ((v & 1) >> 0)) << i;\ + }\ + ((grn_geo_point *)keybuf_)->latitude = la;\ + ((grn_geo_point *)keybuf_)->longitude = lo;\ +} + #ifdef USE_FUTEX #include <linux/futex.h> #include <sys/syscall.h> Modified: lib/pat.c (+0 -34) =================================================================== --- lib/pat.c 2010-08-02 09:20:09 +0000 (a3492e3) +++ lib/pat.c 2010-08-03 06:24:38 +0000 (40e503f) @@ -679,40 +679,6 @@ chop(grn_ctx *ctx, grn_pat *pat, const char **key, const char *end, uint32_t *lk } } -static void -grn_gton(uint8_t *keybuf, const void *key, uint32_t size) -{ - int la = ((grn_geo_point *)key)->latitude; - int lo = ((grn_geo_point *)key)->longitude; - uint8_t *p = keybuf; - int i = 32; - while (i) { - i -= 4; - *p++ = ((((la >> i) & 8) << 4) + (((lo >> i) & 8) << 3) + - (((la >> i) & 4) << 3) + (((lo >> i) & 4) << 2) + - (((la >> i) & 2) << 2) + (((lo >> i) & 2) << 1) + - (((la >> i) & 1) << 1) + (((lo >> i) & 1) << 0)); - } -} - -static void -grn_ntog(uint8_t *keybuf, uint8_t *key, uint32_t size) -{ - int la = 0, lo = 0; - uint8_t v, *p = key; - int i = 32; - while (size--) { - i -= 4; - v = *p++; - la += (((v & 128) >> 4) + ((v & 32) >> 3) + - ((v & 8) >> 2) + ((v & 2) >> 1)) << i; - lo += (((v & 64) >> 3) + ((v & 16) >> 2) + - ((v & 4) >> 1) + ((v & 1) >> 0)) << i; - } - ((grn_geo_point *)keybuf)->latitude = la; - ((grn_geo_point *)keybuf)->longitude = lo; -} - #define MAX_FIXED_KEY_SIZE (sizeof(int64_t)) #define KEY_NEEDS_CONVERT(pat,size) \ Modified: lib/util.c (+22 -0) =================================================================== --- lib/util.c 2010-08-02 09:20:09 +0000 (62e234f) +++ lib/util.c 2010-08-03 06:24:38 +0000 (9a7cce8) @@ -400,6 +400,8 @@ grn_geo_point_inspect_point(grn_ctx *ctx, grn_obj *buf, int point) GRN_TEXT_PUTS(ctx, buf, ", "); grn_text_itoa(ctx, buf, point % 1000); GRN_TEXT_PUTS(ctx, buf, ")"); + + return GRN_SUCCESS; } static grn_rc @@ -422,6 +424,26 @@ grn_geo_point_inspect(grn_ctx *ctx, grn_obj *buf, grn_obj *obj) grn_geo_point_inspect_point(ctx, buf, longitude); GRN_TEXT_PUTS(ctx, buf, ")"); + { + int i, j; + grn_geo_point point; + uint8_t encoded[sizeof(grn_geo_point)]; + + GRN_TEXT_PUTS(ctx, buf, " ["); + point.latitude = latitude; + point.longitude = longitude; + grn_gton(encoded, &point, sizeof(grn_geo_point)); + for (i = 0; i < sizeof(grn_geo_point); i++) { + if (i != 0) { + GRN_TEXT_PUTS(ctx, buf, " "); + } + for (j = 0; j < 8; j++) { + grn_text_itoa(ctx, buf, (encoded[i] >> (7 - j)) & 1); + } + } + GRN_TEXT_PUTS(ctx, buf, "]"); + } + GRN_TEXT_PUTS(ctx, buf, "]"); return GRN_SUCCESS; Modified: test/unit/core/test-inspect.c (+6 -2) =================================================================== --- test/unit/core/test-inspect.c 2010-08-02 09:20:09 +0000 (27c62c4) +++ test/unit/core/test-inspect.c 2010-08-03 06:24:38 +0000 (8af6c4e) @@ -350,7 +350,9 @@ test_geo_point_tokyo(void) GRN_GEO_POINT_SET(context, geo_point_tokyo, takane_latitude, takane_longitude); inspected = grn_inspect(context, NULL, geo_point_tokyo); cut_assert_equal_string("[(130194581,503802073) " - "((36, 9, 54, 581),(139, 56, 42, 73))]", + "((36, 9, 54, 581),(139, 56, 42, 73)) " + "[00000001 01111110 10100000 00011101 " + "10010110 11100000 11010011 01100011]]", inspected_string()); } @@ -366,7 +368,9 @@ test_geo_point_wgs84(void) GRN_GEO_POINT_SET(context, geo_point_wgs84, takane_latitude, takane_longitude); inspected = grn_inspect(context, NULL, geo_point_wgs84); cut_assert_equal_string("[(130226900,503769900) " - "((36, 10, 26, 900),(139, 56, 9, 900))]", + "((36, 10, 26, 900),(139, 56, 9, 900)) " + "[00000001 01111110 10100000 00011110 " + "01010110 11001101 10100110 01110000]]", inspected_string()); } Modified: test/unit/core/test-table-patricia-trie-cursor.c (+0 -34) =================================================================== --- test/unit/core/test-table-patricia-trie-cursor.c 2010-08-02 09:20:09 +0000 (9293d63) +++ test/unit/core/test-table-patricia-trie-cursor.c 2010-08-03 06:24:38 +0000 (5f4185d) @@ -286,40 +286,6 @@ test_prefix_short_text(gpointer data) gcut_assert_equal_list_string(expected_keys, actual_keys); } -static void -grn_gton(uint8_t *keybuf, const void *key, uint32_t size) -{ - int la = ((grn_geo_point *)key)->latitude; - int lo = ((grn_geo_point *)key)->longitude; - uint8_t *p = keybuf; - int i = 32; - while (i) { - i -= 4; - *p++ = ((((la >> i) & 8) << 4) + (((lo >> i) & 8) << 3) + - (((la >> i) & 4) << 3) + (((lo >> i) & 4) << 2) + - (((la >> i) & 2) << 2) + (((lo >> i) & 2) << 1) + - (((la >> i) & 1) << 1) + (((lo >> i) & 1) << 0)); - } -} - -static void -grn_ntog(uint8_t *keybuf, uint8_t *key, uint32_t size) -{ - int la = 0, lo = 0; - uint8_t v, *p = key; - int i = 32; - while (size--) { - i -= 4; - v = *p++; - la += (((v & 128) >> 4) + ((v & 32) >> 3) + - ((v & 8) >> 2) + ((v & 2) >> 1)) << i; - lo += (((v & 64) >> 3) + ((v & 16) >> 2) + - ((v & 4) >> 1) + ((v & 1) >> 0)) << i; - } - ((grn_geo_point *)keybuf)->latitude = la; - ((grn_geo_point *)keybuf)->longitude = lo; -} - static const gchar * geo_byte_parse(const gchar *geo_byte_string) {