[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[hurd] 29/31: libihash: keep track of free slots
From: |
Samuel Thibault |
Subject: |
[hurd] 29/31: libihash: keep track of free slots |
Date: |
Mon, 02 May 2016 23:48:33 +0000 |
This is an automated email from the git hooks/post-receive script.
sthibault pushed a commit to branch upstream
in repository hurd.
commit 39031d37fd82c119b4b16af256a8ceae5d8c6ea8
Author: Justus Winter <address@hidden>
Date: Thu Apr 28 20:11:27 2016 +0200
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.
---
libihash/ihash.c | 9 +++++++++
libihash/ihash.h | 11 +++++++++++
2 files changed, 20 insertions(+)
diff --git a/libihash/ihash.c b/libihash/ihash.c
index 01ba23b..800f492 100644
--- a/libihash/ihash.c
+++ b/libihash/ihash.c
@@ -131,6 +131,7 @@ hurd_ihash_init (hurd_ihash_t ht, intptr_t locp_offs)
ht->cleanup = 0;
ht->fct_hash = NULL;
ht->fct_cmp = NULL;
+ ht->nr_free = 0;
}
@@ -246,6 +247,11 @@ add_one (hurd_ihash_t ht, hurd_ihash_key_t key,
hurd_ihash_value_t value)
if (index_empty (ht, idx))
{
ht->nr_items++;
+ if (ht->items[idx].value == _HURD_IHASH_EMPTY)
+ {
+ assert (ht->nr_free > 0);
+ ht->nr_free--;
+ }
ht->items[idx].value = value;
ht->items[idx].key = key;
@@ -290,6 +296,8 @@ hurd_ihash_locp_add (hurd_ihash_t ht, hurd_ihash_locp_t
locp,
{
item->key = key;
ht->nr_items += 1;
+ assert (ht->nr_free > 0);
+ ht->nr_free -= 1;
}
else
{
@@ -335,6 +343,7 @@ hurd_ihash_add (hurd_ihash_t ht, hurd_ihash_key_t key,
hurd_ihash_value_t item)
ht->size = HURD_IHASH_MIN_SIZE;
else
ht->size <<= 1;
+ ht->nr_free = ht->size;
/* calloc() will initialize all values to _HURD_IHASH_EMPTY implicitly. */
ht->items = calloc (ht->size, sizeof (struct _hurd_ihash_item));
diff --git a/libihash/ihash.h b/libihash/ihash.h
index 356f647..80679f1 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
--
Alioth's /usr/local/bin/git-commit-notice on
/srv/git.debian.org/git/pkg-hurd/hurd.git
- [hurd] 19/31: libpager: add missing include, (continued)
- [hurd] 19/31: libpager: add missing include, Samuel Thibault, 2016/05/02
- [hurd] 09/31: Make make install idempotent, Samuel Thibault, 2016/05/02
- [hurd] 23/31: startup: implement bits of the fs and io protocols, Samuel Thibault, 2016/05/02
- [hurd] 11/31: libfshelp: pass cookie to the callback function, Samuel Thibault, 2016/05/02
- [hurd] 13/31: Merge branch 'master' of git.savannah.gnu.org:/srv/git/hurd/hurd, Samuel Thibault, 2016/05/02
- [hurd] 20/31: libshouldbeinlibc: add assert(3) variant that prints backtraces, Samuel Thibault, 2016/05/02
- [hurd] 07/31: utils/settrans: get an authenticated root node in chroot mode, Samuel Thibault, 2016/05/02
- [hurd] 06/31: isofs: make superblock detection more robust, Samuel Thibault, 2016/05/02
- [hurd] 08/31: utils/settrans: add option to specify the underlying node, Samuel Thibault, 2016/05/02
- [hurd] 31/31: Fix build, Samuel Thibault, 2016/05/02
- [hurd] 29/31: libihash: keep track of free slots,
Samuel Thibault <=
- [hurd] 10/31: mach-defpager: fix error handling, Samuel Thibault, 2016/05/02
- [hurd] 30/31: libihash: rehash if effective load exceeds the threshold, Samuel Thibault, 2016/05/02
- [hurd] 26/31: startup: write all messages to stderr, Samuel Thibault, 2016/05/02
- [hurd] 27/31: Fix root operations on trivfs-translated nodes, Samuel Thibault, 2016/05/02
- [hurd] 16/31: libtrivfs: fix notion of privileged user, Samuel Thibault, 2016/05/02
- [hurd] 28/31: libihash: fix index computation, Samuel Thibault, 2016/05/02
- [hurd] 24/31: startup: add verbose parameter, Samuel Thibault, 2016/05/02
- [hurd] 25/31: startup: use the generated default server implementations, Samuel Thibault, 2016/05/02
- [hurd] 01/31: netfs: Remove global reference count lock., Samuel Thibault, 2016/05/03
- [hurd] 04/31: Use posix types for mig definitions., Samuel Thibault, 2016/05/03