From 0192df5cecb2f8d0ccb5c0ffd96eb5aa9076738e Mon Sep 17 00:00:00 2001 From: Florian Forster Date: Mon, 17 Jan 2011 14:30:33 +0100 Subject: [PATCH] src/sn_hashtable.[ch]: Implement sn_hashtable_check_collision(). --- src/sn_hashtable.c | 38 ++++++++++++++++++++++++++++++++++++++ src/sn_hashtable.h | 1 + 2 files changed, 39 insertions(+) diff --git a/src/sn_hashtable.c b/src/sn_hashtable.c index 3d0fd2d..e77e6c6 100644 --- a/src/sn_hashtable.c +++ b/src/sn_hashtable.c @@ -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) diff --git a/src/sn_hashtable.h b/src/sn_hashtable.h index 3871646..08eab18 100644 --- a/src/sn_hashtable.h +++ b/src/sn_hashtable.h @@ -42,6 +42,7 @@ sn_hashtable_t *sn_hashtable_create (void); void sn_hashtable_destroy (sn_hashtable_t *ht); int sn_hashtable_account (sn_hashtable_t *ht, const sn_network_t *n); +_Bool sn_hashtable_check_collision (sn_hashtable_t *ht, const sn_network_t *n); uint64_t sn_hashtable_get_collisions (sn_hashtable_t *ht); double sn_hashtable_get_collisions_pct (sn_hashtable_t *ht); -- 2.11.0