From: Attractive Chaos Date: Tue, 14 Jan 2020 01:05:38 +0000 (-0500) Subject: fixed a bug in khashl; resolves #135 X-Git-Url: http://www.kaiwu.me/postgresql/commit/static/gitweb.js?a=commitdiff_plain;h=928581a78413bed4efa956731b35b18a638f20f3;p=klib.git fixed a bug in khashl; resolves #135 --- diff --git a/cpp/khashl.hpp b/cpp/khashl.hpp index b35d349..8b870d6 100644 --- a/cpp/khashl.hpp +++ b/cpp/khashl.hpp @@ -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); diff --git a/khashl.h b/khashl.h index 7731488..951feda 100644 --- 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); \