Skip to content

Commit

Permalink
KHash: transition to 64bit ints
Browse files Browse the repository at this point in the history
  • Loading branch information
OndrejSladky committed Jan 18, 2024
1 parent b123948 commit 1b1faad
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/khash.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ typedef unsigned long long khint64_t;
#endif
#endif /* klib_unused */

typedef khint32_t khint_t;
typedef khint64_t khint_t;
typedef khint_t khiter_t;

#define __ac_isempty(flag, i) ((flag[i>>4]>>((i&0xfU)<<1))&2)
Expand All @@ -176,6 +176,10 @@ typedef khint_t khiter_t;
#define kroundup32(x) (--(x), (x)|=(x)>>1, (x)|=(x)>>2, (x)|=(x)>>4, (x)|=(x)>>8, (x)|=(x)>>16, ++(x))
#endif

#ifndef kroundup64
#define kroundup64(x) (--(x), (x)|=(x)>>1, (x)|=(x)>>2, (x)|=(x)>>4, (x)|=(x)>>8, (x)|=(x)>>16, (x)|=(x)>>32, ++(x))
#endif

#ifndef kcalloc
#define kcalloc(N,Z) calloc(N,Z)
#endif
Expand Down Expand Up @@ -246,7 +250,7 @@ static const double __ac_HASH_UPPER = 0.77;
khint32_t *new_flags = 0; \
khint_t j = 1; \
{ \
kroundup32(new_n_buckets); \
kroundup64(new_n_buckets); \
if (new_n_buckets < 4) new_n_buckets = 4; \
if (h->size >= (khint_t)(new_n_buckets * __ac_HASH_UPPER + 0.5)) j = 0; /* requested size is too small */ \
else { /* hash table size to be changed (shrink or expand); rehash */ \
Expand Down Expand Up @@ -382,7 +386,8 @@ static const double __ac_HASH_UPPER = 0.77;
@param key The integer [khint64_t]
@return The hash value [khint_t]
*/
#define kh_int64_hash_func(key) (khint32_t)((key)>>33^(key)^(key)<<11)
//#define kh_int64_hash_func(key) (khint32_t)((key)>>33^(key)^(key)<<11)
#define kh_int64_hash_func(key) (khint64_t)(key)
/*! @function
@abstract 64-bit integer comparison function
*/
Expand Down

0 comments on commit 1b1faad

Please sign in to comment.