summaryrefslogtreecommitdiff
path: root/debian/patches/ihash0003-libihash-rehash-if-effective-load-exceeds-the-thresh.patch
blob: a8fc3154ad65e2b4d4128a77f6a26bcc396eb5f1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
From f17a5f81707708d0f80d86f02f7f22d7e285bff3 Mon Sep 17 00:00:00 2001
From: Justus Winter <justus@gnupg.org>
Date: Thu, 28 Apr 2016 21:12:58 +0200
Subject: [PATCH hurd 3/3] libihash: rehash if effective load exceeds the
 threshold

* libihash/ihash.c (hurd_ihash_locp_add): Use the effective load.
(hurd_ihash_add): Likewise.  Use the load to decide whether we want to
enlarge the table, otherwise we merely rehash.
---
 libihash/ihash.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/libihash/ihash.c b/libihash/ihash.c
index 800f492..d5e4333 100644
--- a/libihash/ihash.c
+++ b/libihash/ihash.c
@@ -289,7 +289,7 @@ hurd_ihash_locp_add (hurd_ihash_t ht, hurd_ihash_locp_t locp,
       || item == NULL
       || item->value == _HURD_IHASH_DELETED
       || ! compare (ht, item->key, key)
-      || hurd_ihash_get_load (ht) > ht->max_load)
+      || hurd_ihash_get_effective_load (ht) > ht->max_load)
     return hurd_ihash_add (ht, key, value);
 
   if (item->value == _HURD_IHASH_EMPTY)
@@ -327,21 +327,23 @@ hurd_ihash_add (hurd_ihash_t ht, hurd_ihash_key_t key, hurd_ihash_value_t item)
   int was_added;
   int fatal = 0;	/* bail out on allocation errors */
   unsigned int i;
+  unsigned int load;
 
   if (ht->size)
     {
       /* Only fill the hash table up to its maximum load factor.  */
-      if (hurd_ihash_get_load (ht) <= ht->max_load)
+      if (hurd_ihash_get_effective_load (ht) <= ht->max_load)
       add_one:
 	if (add_one (ht, key, item))
 	  return 0;
     }
 
   /* The hash table is too small, and we have to increase it.  */
+  load = hurd_ihash_get_load (ht);
   ht->nr_items = 0;
   if (ht->size == 0)
       ht->size = HURD_IHASH_MIN_SIZE;
-  else
+  else if (load > ht->max_load)
       ht->size <<= 1;
   ht->nr_free = ht->size;
 
-- 
2.1.4