This file contains different utilities for hashing. The ideas of algorithms were borrowed from the boost library. http://www.boost.org/doc/libs/1_64_0/boost/functional/hash/hash.hpp http://www.boost.org/doc/libs/1_64_0/boost/functional/hash/detail/hash_float.hpp.
More...
#include <cdcontainers/casts.h>
#include <float.h>
#include <limits.h>
#include <stddef.h>
#include <string.h>
Go to the source code of this file.
◆ CDC_DIGITS_CHAR
#define CDC_DIGITS_CHAR (CHAR_BIT - (CHAR_MIN < 0)) |
◆ CDC_DIGITS_SCHAR
#define CDC_DIGITS_SCHAR (CHAR_BIT - 1) |
◆ CDC_DIGITS_UCHAR
#define CDC_DIGITS_UCHAR (CHAR_BIT) |
◆ CDC_DIGITS_SHORT
#define CDC_DIGITS_SHORT (CHAR_BIT * sizeof(short) - 1) |
◆ CDC_DIGITS_USHORT
#define CDC_DIGITS_USHORT (CHAR_BIT * sizeof(short)) |
◆ CDC_DIGITS_INT
#define CDC_DIGITS_INT (CHAR_BIT * sizeof(int) - 1) |
◆ CDC_DIGITS_UINT
#define CDC_DIGITS_UINT (CHAR_BIT * sizeof(int)) |
◆ CDC_DIGITS_LONG
#define CDC_DIGITS_LONG (CHAR_BIT * sizeof(long) - 1) |
◆ CDC_DIGITS_ULONG
#define CDC_DIGITS_ULONG (CHAR_BIT * sizeof(long)) |
◆ CDC_DIGITS_SIZE
#define CDC_DIGITS_SIZE (CHAR_BIT * sizeof(size_t)) |
◆ MAKE_SIGNED_HASH
#define MAKE_SIGNED_HASH |
( |
|
T, |
|
|
|
DIGITS, |
|
|
|
NAME |
|
) |
| |
Value:static inline size_t cdc_hash_##NAME(T val) \
{ \
const int length = (DIGITS - 1) / (int)(size_t_bits); \
unsigned int i; \
size_t seed = 0; \
T positive = val < 0 ? -1 - val : val; \
for (i = length * size_t_bits; i > 0; i -= size_t_bits) \
seed ^= (size_t)(positive >> i) + (seed << 6) + (seed >> 2); \
seed ^= (size_t)val + (seed << 6) + (seed >> 2); \
return seed; \
}
#define CDC_DIGITS_SIZE
Definition: hash.h:49
◆ MAKE_UNSIGNED_HASH
#define MAKE_UNSIGNED_HASH |
( |
|
T, |
|
|
|
DIGITS, |
|
|
|
NAME |
|
) |
| |
Value:static inline size_t cdc_hash_##NAME(T val) \
{ \
const int length = (DIGITS - 1) / (int)(size_t_bits); \
unsigned int i; \
size_t seed = 0; \
for (i = length * size_t_bits; i > 0; i -= size_t_bits) \
seed ^= (size_t)(seed >> i) + (seed << 6) + (seed >> 2); \
seed ^= (size_t)val + (seed << 6) + (seed >> 2); \
return seed; \
}
#define CDC_DIGITS_SIZE
Definition: hash.h:49
◆ MAKE_FLOAT_HASH
#define MAKE_FLOAT_HASH |
( |
|
T, |
|
|
|
NAME |
|
) |
| |
Value:static inline size_t cdc_hash_##NAME(T val) \
{ \
}
static size_t cdc_hash_binary(char *ptr, size_t length)
Definition: hash.h:84
◆ MAKE_POINTER_DATA_HASH
#define MAKE_POINTER_DATA_HASH |
( |
|
T, |
|
|
|
NAME, |
|
|
|
CAST_FUNC |
|
) |
| |
Value:static inline size_t cdc_pdhash_##NAME(void *val) \
{ \
T t = CAST_FUNC(val); \
return cdc_hash_##NAME(t); \
}
◆ cdc_hash_fn_t
typedef size_t(* cdc_hash_fn_t) (void const *) |
◆ cdc_hash_float_combine()
static size_t cdc_hash_float_combine |
( |
size_t |
seed, |
|
|
size_t |
value |
|
) |
| |
|
inlinestatic |
◆ cdc_hash_binary()
static size_t cdc_hash_binary |
( |
char * |
ptr, |
|
|
size_t |
length |
|
) |
| |
|
inlinestatic |