typedef struct _tpl_list tpl_list_t;
typedef struct tpl_util_map_entry tpl_util_map_entry_t;
typedef struct tpl_util_map tpl_util_map_t;
-typedef union tpl_util_key tpl_util_key_t;
+typedef struct tpl_util_key tpl_util_key_t;
typedef int (*tpl_util_hash_func_t)(const tpl_util_key_t key, int key_length);
typedef int (*tpl_util_key_length_func_t)(const tpl_util_key_t key);
TPL_ALL
};
-union tpl_util_key {
- uint32_t key32;
- uint64_t key64;
+struct tpl_util_key {
void *ptr; /*pointer key or user defined key(string)*/
};
tpl_util_key_compare_func_t key_compare_func,
void *buckets);
-void tpl_util_map_int32_init(tpl_util_map_t *map, int bucket_bits,
- void *buckets);
-
-void tpl_util_map_int64_init(tpl_util_map_t *map, int bucket_bits,
- void *buckets);
-
void tpl_util_map_pointer_init(tpl_util_map_t *map, int bucket_bits,
void *buckets);
tpl_util_key_length_func_t key_length_func,
tpl_util_key_compare_func_t key_compare_func);
-tpl_util_map_t *tpl_util_map_int32_create(int bucket_bits);
-
-tpl_util_map_t *tpl_util_map_int64_create(int bucket_bits);
-
tpl_util_map_t *tpl_util_map_pointer_create(int bucket_bits);
void tpl_util_map_destroy(tpl_util_map_t *map);
}
static int
-__int64_hash(const tpl_util_key_t key, int key_length)
-{
- uint64_t _key = key.key64;
-
- /* Hash functions from Thomas Wang https://gist.github.com/badboy/6267743 */
- _key = ~_key + (_key << 18);
- _key ^= _key >> 31;
- _key *= 21;
- _key ^= _key >> 11;
- _key += _key << 6;
- _key ^= _key >> 22;
-
- return (int)_key;;
-}
-
-static int
-__int64_key_compare(const tpl_util_key_t key0, int key0_length,
- const tpl_util_key_t key1, int key1_length)
-{
- return (int)(key0.key64 - key1.key64);
-}
-
-static int
-__int32_hash(const tpl_util_key_t key, int key_length)
-{
- uint32_t _key = (uint32_t)key.key32;
-
- /* Hash functions from Thomas Wang https://gist.github.com/badboy/6267743 */
- _key = ~_key + (_key << 15);
- _key ^= _key >> 12;
- _key += _key << 2;
- _key ^= _key >> 4;
- _key *= 2057;
- _key ^= _key >> 16;
-
- return (int)_key;
-}
-
-static int
-__int32_key_compare(const tpl_util_key_t key0, int key0_length,
- const tpl_util_key_t key1, int key1_length)
-{
- return (int)(key0.key32 - key1.key32);
-}
-
-static int
__pointer_hash(const tpl_util_key_t key, int key_length)
{
#if INTPTR_MAX == INT32_MAX
}
void
-tpl_util_map_int32_init(tpl_util_map_t *map, int bucket_bits, void *buckets)
-{
- tpl_util_map_init(map, bucket_bits, __int32_hash, NULL,
- __int32_key_compare, buckets);
-}
-
-void
-tpl_util_map_int64_init(tpl_util_map_t *map, int bucket_bits, void *buckets)
-{
- tpl_util_map_init(map, bucket_bits, __int64_hash, NULL,
- __int64_key_compare, buckets);
-}
-
-void
tpl_util_map_pointer_init(tpl_util_map_t *map, int bucket_bits, void *buckets)
{
tpl_util_map_init(map, bucket_bits, __pointer_hash, NULL,
}
tpl_util_map_t *
-tpl_util_map_int32_create(int bucket_bits)
-{
- return tpl_util_map_create(bucket_bits, __int32_hash, NULL,
- __int32_key_compare);
-}
-
-tpl_util_map_t *
-tpl_util_map_int64_create(int bucket_bits)
-{
- return tpl_util_map_create(bucket_bits, __int64_hash, NULL,
- __int64_key_compare);
-}
-
-tpl_util_map_t *
tpl_util_map_pointer_create(int bucket_bits)
{
return tpl_util_map_create(bucket_bits, __pointer_hash, NULL,