summaryrefslogtreecommitdiff
path: root/libihash/ihash.h
diff options
context:
space:
mode:
authorJustus Winter <justus@gnupg.org>2016-04-28 20:11:27 +0200
committerJustus Winter <justus@gnupg.org>2016-04-29 22:39:06 +0200
commit39031d37fd82c119b4b16af256a8ceae5d8c6ea8 (patch)
treefc63fd59c5346bfb415a2eee45eddb1953e6e7bc /libihash/ihash.h
parent74d373342f799a45e9193c2f56189843b7b42c04 (diff)
libihash: keep track of free slots
* libihash/ihash.c (hurd_ihash_init): Init new field 'nr_free'. (add_one): Decrement counter if a free slot is used. (hurd_ihash_locp_add): Likewise. (hurd_ihash_add): Reset counter on reallocation. * libihash/ihash.h (struct hurd_ihash): New field 'nr_free'. (hurd_ihash_get_effective_load): New function.
Diffstat (limited to 'libihash/ihash.h')
-rw-r--r--libihash/ihash.h11
1 files changed, 11 insertions, 0 deletions
diff --git a/libihash/ihash.h b/libihash/ihash.h
index 356f6473..80679f14 100644
--- a/libihash/ihash.h
+++ b/libihash/ihash.h
@@ -113,6 +113,9 @@ struct hurd_ihash
/* User-supplied functions for the generalized key interface. */
hurd_ihash_fct_hash_t fct_hash;
hurd_ihash_fct_cmp_t fct_cmp;
+
+ /* Number of free slots. */
+ size_t nr_free;
};
typedef struct hurd_ihash *hurd_ihash_t;
@@ -225,6 +228,14 @@ hurd_ihash_get_load (hurd_ihash_t ht)
return d >= 0 ? ht->nr_items >> d : ht->nr_items << -d;
}
+/* Similar, but counts tombstones as well. */
+static inline unsigned int
+hurd_ihash_get_effective_load (hurd_ihash_t ht)
+{
+ int d = __builtin_ctzl (ht->size) - 7;
+ return
+ d >= 0 ? (ht->size - ht->nr_free) >> d : (ht->size - ht->nr_free) << -d;
+}
/* Add ITEM to the hash table HT under the key KEY. If there already
is an item under this key, call the cleanup function (if any) for