[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[hurd] 28/75: libihash: fix item insertion
From: |
Samuel Thibault |
Subject: |
[hurd] 28/75: libihash: fix item insertion |
Date: |
Thu, 14 Jan 2016 01:04:07 +0000 |
This is an automated email from the git hooks/post-receive script.
sthibault pushed a commit to branch dde
in repository hurd.
commit 1842a9dcd1056dac886e96071e8c5dcd2859d471
Author: Justus Winter <address@hidden>
Date: Sun Nov 22 21:04:51 2015 +0100
libihash: fix item insertion
* libihash/ihash.c (find_index): Keep track and return the index where
we could insert the item.
(add_one): Use 'find_index'.
---
libihash/ihash.c | 54 ++++++++++++++++++------------------------------------
1 file changed, 18 insertions(+), 36 deletions(-)
diff --git a/libihash/ihash.c b/libihash/ihash.c
index 451f8db..596f6ff 100644
--- a/libihash/ihash.c
+++ b/libihash/ihash.c
@@ -75,6 +75,8 @@ find_index (hurd_ihash_t ht, hurd_ihash_key_t key)
{
unsigned int idx;
unsigned int up_idx;
+ unsigned int first_deleted = 0;
+ int first_deleted_set = 0;
unsigned int mask = ht->size - 1;
idx = hash (ht, key) & mask;
@@ -88,15 +90,21 @@ find_index (hurd_ihash_t ht, hurd_ihash_key_t key)
do
{
up_idx = (up_idx + 1) & mask;
- if (ht->items[up_idx].value == _HURD_IHASH_EMPTY
- || compare (ht, ht->items[up_idx].key, key))
+ if (ht->items[up_idx].value == _HURD_IHASH_EMPTY)
+ return first_deleted_set ? first_deleted : up_idx;
+ if (compare (ht, ht->items[up_idx].key, key))
return up_idx;
+ if (! first_deleted_set
+ && ht->items[up_idx].value == _HURD_IHASH_DELETED)
+ first_deleted = up_idx, first_deleted_set = 1;
}
while (up_idx != idx);
- /* If we end up here, the item could not be found. Return any
- invalid index. */
- return idx;
+ /* If we end up here, the item could not be found. Return the index
+ of the first deleted item, as this is the position where we can
+ insert an item with the given key once we established that it is
+ not in the table. */
+ return first_deleted;
}
@@ -233,48 +241,22 @@ static inline int
add_one (hurd_ihash_t ht, hurd_ihash_key_t key, hurd_ihash_value_t value)
{
unsigned int idx;
- unsigned int first_free;
- unsigned int mask = ht->size - 1;
-
- idx = hash (ht, key) & mask;
- first_free = idx;
-
- if (ht->items[idx].value != _HURD_IHASH_EMPTY
- && ! compare (ht, ht->items[idx].key, key))
- {
- unsigned int up_idx = idx;
- do
- {
- up_idx = (up_idx + 1) & mask;
- if (ht->items[up_idx].value == _HURD_IHASH_EMPTY
- || compare (ht, ht->items[up_idx].key, key))
- {
- idx = up_idx;
- break;
- }
- }
- while (up_idx != idx);
- }
+ idx = find_index (ht, key);
/* Remove the old entry for this key if necessary. */
if (index_valid (ht, idx, key))
locp_remove (ht, &ht->items[idx].value);
- /* If we have not found an empty slot, maybe the last one we
- looked at was empty (or just got deleted). */
- if (!index_empty (ht, first_free))
- first_free = idx;
-
- if (index_empty (ht, first_free))
+ if (index_empty (ht, idx))
{
ht->nr_items++;
- ht->items[first_free].value = value;
- ht->items[first_free].key = key;
+ ht->items[idx].value = value;
+ ht->items[idx].key = key;
if (ht->locp_offset != HURD_IHASH_NO_LOCP)
*((hurd_ihash_locp_t *) (((char *) value) + ht->locp_offset))
- = &ht->items[first_free].value;
+ = &ht->items[idx].value;
return 1;
}
--
Alioth's /usr/local/bin/git-commit-notice on
/srv/git.debian.org/git/pkg-hurd/hurd.git
- [hurd] 02/75: libtrivfs: remove deprecated static class vectors, (continued)
- [hurd] 02/75: libtrivfs: remove deprecated static class vectors, Samuel Thibault, 2016/01/13
- [hurd] 05/75: random: improve error handling, Samuel Thibault, 2016/01/13
- [hurd] 01/75: pfinet: fix sanity check at translator startup time, Samuel Thibault, 2016/01/13
- [hurd] 22/75: Fix undefined reference, Samuel Thibault, 2016/01/13
- [hurd] 24/75: Use -L instead of -Wl,-rpath-link, Samuel Thibault, 2016/01/13
- [hurd] 26/75: libihash: fix fast insertion corner case, Samuel Thibault, 2016/01/13
- [hurd] 25/75: libihash: fix ill-devised locp lookup interface, Samuel Thibault, 2016/01/13
- [hurd] 21/75: Drop spurious debugging or outdated changes, Samuel Thibault, 2016/01/13
- [hurd] 14/75: Add devnode translator, Samuel Thibault, 2016/01/13
- [hurd] 30/75: ext2fs: improve the block cache, Samuel Thibault, 2016/01/13
- [hurd] 28/75: libihash: fix item insertion,
Samuel Thibault <=
- [hurd] 66/75: Make private variables static, Samuel Thibault, 2016/01/13
- [hurd] 32/75: ext2fs: keep list of reusable disk cache entries, Samuel Thibault, 2016/01/13
- [hurd] 33/75: libdiskfs: use ihash for the node cache, Samuel Thibault, 2016/01/13
- [hurd] 31/75: ext2fs: disable block cache debugging by default, Samuel Thibault, 2016/01/13
- [hurd] 27/75: libihash: generalize the interface to support non-integer keys, Samuel Thibault, 2016/01/13
- [hurd] 68/75: Fix build with perl >= 5.22, Samuel Thibault, 2016/01/13
- [hurd] 29/75: libihash: provide a general purpose hash algorithm, Samuel Thibault, 2016/01/13
- [hurd] 65/75: pflocal: Do not abort on too small getopt parameter, Samuel Thibault, 2016/01/13
- [hurd] 71/75: Merge branch 'dde-upstream' into dde, Samuel Thibault, 2016/01/13
- [hurd] 64/75: Add dumb SO_ERROR support to pflocal, Samuel Thibault, 2016/01/13