src/sn_hashtable.[ch]: Implement sn_hashtable_check_collision().
authorFlorian Forster <octo@leeloo.octo.it>
Mon, 17 Jan 2011 13:30:33 +0000 (14:30 +0100)
committerFlorian Forster <octo@leeloo.octo.it>
Mon, 17 Jan 2011 13:30:33 +0000 (14:30 +0100)
src/sn_hashtable.c
src/sn_hashtable.h

index 3d0fd2d..e77e6c6 100644 (file)
@@ -141,6 +141,44 @@ int sn_hashtable_account (sn_hashtable_t *ht, const sn_network_t *n) /* {{{ */
   return (0);
 } /* }}} int sn_hashtable_account */
 
   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)
 uint64_t sn_hashtable_get_collisions (sn_hashtable_t *ht) /* {{{ */
 {
   if (ht == NULL)
index 3871646..08eab18 100644 (file)
@@ -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);
 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);
 
 uint64_t sn_hashtable_get_collisions (sn_hashtable_t *ht);
 double   sn_hashtable_get_collisions_pct (sn_hashtable_t *ht);