X-Git-Url: https://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=ccan%2Fstringmap%2Fstringmap.c;h=364e2a4881519b2d2af1f89dd3dedb6dd08d8ceb;hp=7380e4e1e82b0fc0575c98ad3562bb9cd6ea1650;hb=e6862ec8ae269217f3596f5af84747868b983afb;hpb=703565490945abb062b20e043863c3ca0366f394 diff --git a/ccan/stringmap/stringmap.c b/ccan/stringmap/stringmap.c index 7380e4e1..364e2a48 100644 --- a/ccan/stringmap/stringmap.c +++ b/ccan/stringmap/stringmap.c @@ -29,7 +29,7 @@ /* This is a heavily modified version of the Patricia tree implementation in PCC at http://pcc.zentus.com/cgi-bin/cvsweb.cgi/cc/cpp/cpp.c?rev=1.96 */ -#include "stringmap.h" +#include //#define CONSISTENCY_CHECK @@ -39,7 +39,7 @@ #define assert(...) do {} while(0) #endif -#define PEEK_BIT(key, bit) ((key[bit >> 3] >> (bit & 7)) & 1) +#define PEEK_BIT(key, bit) ((key[bit >> 3] >> (~bit & 7)) & 1) struct stringmap_node { uint32_t left_is_leaf:1, right_is_leaf:1, bitno:30; @@ -155,8 +155,8 @@ void *stringmap_lookup_real(struct stringmap *t, const char *key, size_t len, in //advance cix to the first differing bit ix = *m ^ *k; - while ((ix & 1) == 0) - ix >>= 1, cix++; + while ((ix & 128) == 0) + ix <<= 1, cix++; //choose left/right based on the differing bit bit = PEEK_BIT(key, cix);