]> git.kaiwu.me - klib.git/commitdiff
fixed a bug in khashl; resolves #135
authorAttractive Chaos <attractor@live.co.uk>
Tue, 14 Jan 2020 01:05:38 +0000 (20:05 -0500)
committerAttractive Chaos <attractor@live.co.uk>
Tue, 14 Jan 2020 01:05:38 +0000 (20:05 -0500)
cpp/khashl.hpp
khashl.h

index b35d349c83b2f8a41eb0a4873a5707a0d6c57ce4..8b870d69c1d421468a130f4099ae173637a99602 100644 (file)
@@ -144,7 +144,7 @@ public:
                        j = (j + khint_t(1)) & mask;
                        if (j == i || !__kh_used(used, j)) break; /* j==i only when the table is completely full */
                        k = __kh_h2b(Hash()(keys[j]), bits);
-                       if (k <= i || k > j)
+                       if ((j > i && (k <= i || k > j)) || (j < i && (k <= i && k > j)))
                                keys[i] = keys[j], i = j;
                }
                __kh_set_unused(used, i);
index 77314885a9908b7c17f317f8b8cd6fb4fecbe8fa..951feda3b67e890fa31e3f00fd67d0824e4d13ef 100644 (file)
--- a/khashl.h
+++ b/khashl.h
@@ -230,7 +230,7 @@ static kh_inline khint_t __kh_h2b(khint_t hash, khint_t bits) { return hash * 26
                        j = (j + 1U) & mask; \
                        if (j == i || !__kh_used(h->used, j)) break; /* j==i only when the table is completely full */ \
                        k = __kh_h2b(__hash_fn(h->keys[j]), h->bits); \
-                       if (k <= i || k > j) \
+                       if ((j > i && (k <= i || k > j)) || (j < i && (k <= i && k > j))) \
                                h->keys[i] = h->keys[j], i = j; \
                } \
                __kh_set_unused(h->used, i); \