X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fsn_hashtable.c;h=e77e6c6758b32eb2fe3e8e3405f5ff6fd2bee1ff;hb=ea03c7deb7078b4e08af1d248ba78a32d40ddd3c;hp=065664451fb830b19df90b0bcc66ee928400aa42;hpb=41a304ffa32d46f12921e19e10bce093d48cfbd9;p=sort-networks.git diff --git a/src/sn_hashtable.c b/src/sn_hashtable.c index 0656644..e77e6c6 100644 --- a/src/sn_hashtable.c +++ b/src/sn_hashtable.c @@ -69,7 +69,7 @@ void sn_hashtable_destroy (sn_hashtable_t *ht) /* {{{ */ { int i; - for (i = 0; i < 256; i++) + for (i = 0; i < 65536; i++) { int j; @@ -100,8 +100,8 @@ void sn_hashtable_destroy (sn_hashtable_t *ht) /* {{{ */ int sn_hashtable_account (sn_hashtable_t *ht, const sn_network_t *n) /* {{{ */ { - uint32_t hash; - uint8_t h0; + uint64_t hash; + uint16_t h0; uint8_t h1; uint8_t h2; uint8_t h3; @@ -111,13 +111,13 @@ int sn_hashtable_account (sn_hashtable_t *ht, const sn_network_t *n) /* {{{ */ hash = sn_network_get_hashval (n); - h0 = (uint8_t) (hash >> 24); - h1 = (uint8_t) (hash >> 16); - h2 = (uint8_t) (hash >> 8); - h3 = (uint8_t) hash; + h0 = (uint16_t) (hash >> 24); + h1 = (uint8_t) (hash >> 16); + h2 = (uint8_t) (hash >> 8); + h3 = (uint8_t) hash; if (ht->data == NULL) - ht->data = calloc (256, sizeof (ht->data[0])); + ht->data = calloc (65536, sizeof (ht->data[0])); if (ht->data[h0] == NULL) ht->data[h0] = calloc (256, sizeof (ht->data[h0][0])); @@ -141,6 +141,44 @@ int sn_hashtable_account (sn_hashtable_t *ht, const sn_network_t *n) /* {{{ */ return (0); } /* }}} int sn_hashtable_account */ +_Bool sn_hashtable_check_collision (sn_hashtable_t *ht, const sn_network_t *n) /* {{{ */ +{ + uint64_t hash; + uint16_t h0; + uint8_t h1; + uint8_t h2; + uint8_t h3; + + if ((ht == NULL) || (n == NULL)) + return (0); + + hash = sn_network_get_hashval (n); + + h0 = (uint16_t) (hash >> 24); + h1 = (uint8_t) (hash >> 16); + h2 = (uint8_t) (hash >> 8); + h3 = (uint8_t) hash; + + if (ht->data == NULL) + return (0); + + if (ht->data[h0] == NULL) + return (0); + + if (ht->data[h0][h1] == NULL) + return (0); + + if (ht->data[h0][h1][h2] == NULL) + return (0); + + assert (sizeof (ht->data[h0][h1][h2][0]) == sizeof (uint8_t)); + + if (ht->data[h0][h1][h2][h3] == 0) + return (0); + else + return (1); +} /* }}} _Bool sn_hashtable_check_collision */ + uint64_t sn_hashtable_get_collisions (sn_hashtable_t *ht) /* {{{ */ { if (ht == NULL)