about summary refs log tree commit diff stats
path: root/src/include/khash.h
diff options
context:
space:
mode:
authorYip Coekjan <69834864+Coekjan@users.noreply.github.com>2024-09-06 20:35:32 +0800
committerGitHub <noreply@github.com>2024-09-06 14:35:32 +0200
commit7dc59ac342d315dbb352becbeabc4e7057992de0 (patch)
treea1b24c29de316422205a0f6a86f6268e3bee91dd /src/include/khash.h
parent16f156be3f9b2089af807f012a960034dddb00ac (diff)
downloadbox64-7dc59ac342d315dbb352becbeabc4e7057992de0.tar.gz
box64-7dc59ac342d315dbb352becbeabc4e7057992de0.zip
Eliminate duplicate hash calculations for `getSymbolInSymbolMaps` (#1801)
Diffstat (limited to 'src/include/khash.h')
-rw-r--r--src/include/khash.h34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/include/khash.h b/src/include/khash.h
index 823757bf..80711c3d 100644
--- a/src/include/khash.h
+++ b/src/include/khash.h
@@ -217,6 +217,22 @@ static const double __ac_HASH_UPPER = 0.77;
 			h->size = h->n_occupied = 0;								\
 		}																\
 	}																	\
+	SCOPE khint_t kh_hash_##name(khkey_t key) {							\
+		return __hash_func(key);										\
+	}																	\
+	SCOPE khint_t kh_get_##name##_with_hash(const kh_##name##_t *h, khkey_t key, khint_t hash) { \
+		if (h->n_buckets) {												\
+			khint_t k = hash, i, last, mask, step = 0; \
+			mask = h->n_buckets - 1;									\
+			i = k & mask;												\
+			last = i; \
+			while (!__ac_isempty(h->flags, i) && (__ac_isdel(h->flags, i) || !__hash_equal(h->keys[i], key))) { \
+				i = (i + (++step)) & mask; \
+				if (i == last) return h->n_buckets;						\
+			}															\
+			return __ac_iseither(h->flags, i)? h->n_buckets : i;		\
+		} else return 0;												\
+	}																	\
 	SCOPE khint_t kh_get_##name(const kh_##name##_t *h, khkey_t key) 	\
 	{																	\
 		if (h->n_buckets) {												\
@@ -463,6 +479,24 @@ static kh_inline khint_t __ac_Wang_hash(khint_t key)
 #define kh_put(name, h, k, r) kh_put_##name(h, k, r)
 
 /*! @function
+  @abstract     Hash a key.
+  @param  name  Name of the hash table [symbol]
+  @param  key   Key [type of keys]
+  @return       Hash value [khint_t]
+ */
+#define kh_hash(name, key) kh_hash_##name(key)
+
+/*! @function
+  @abstract     Retrieve a key from the hash table with a given hash value.
+  @param  name  Name of the hash table [symbol]
+  @param  h     Pointer to the hash table [khash_t(name)*]
+  @param  k     Key [type of keys]
+  @param  hash  Hash value [khint_t]
+  @return       Iterator to the found element, or kh_end(h) if the element is absent [khint_t]
+ */
+#define kh_get_with_hash(name, h, k, hash) kh_get_##name##_with_hash(h, k, hash)
+
+/*! @function
   @abstract     Retrieve a key from the hash table.
   @param  name  Name of the hash table [symbol]
   @param  h     Pointer to the hash table [khash_t(name)*]