45#define TOMMY_SIZE_BIT 64
49#define TOMMY_SIZE_BIT 32
58#if SIZE_MAX == UINT64_MAX
59#define TOMMY_SIZE_BIT 64
62#elif SIZE_MAX == UINT32_MAX
63#define TOMMY_SIZE_BIT 32
67#error Unsupported SIZE_MAX
95#define tommy_cast(type, value) static_cast<type>(value)
97#define tommy_cast(type, value) (value)
109#if !defined(tommy_malloc) || !defined(tommy_calloc) || !defined(tommy_realloc) || !defined(tommy_free)
112#if !defined(tommy_malloc)
113#define tommy_malloc malloc
115#if !defined(tommy_calloc)
116#define tommy_calloc calloc
118#if !defined(tommy_realloc)
119#define tommy_realloc realloc
121#if !defined(tommy_free)
122#define tommy_free free
132#if !defined(TOMMY_API)
139#if !defined(tommy_inline)
140#if defined(_MSC_VER) || defined(__GNUC__)
141#define tommy_inline static __inline
143#define tommy_inline static
150#if !defined(tommy_restrict)
151#if __STDC_VERSION__ >= 199901L
152#define tommy_restrict restrict
153#elif defined(_MSC_VER) || defined(__GNUC__)
154#define tommy_restrict __restrict
156#define tommy_restrict
163#if !defined(tommy_likely)
165#define tommy_likely(x) __builtin_expect(!!(x), 1)
167#define tommy_likely(x) (x)
174#if !defined(tommy_unlikely)
176#define tommy_unlikely(x) __builtin_expect(!!(x), 0)
178#define tommy_unlikely(x) (x)
330#if defined(_MSC_VER) && !defined(__cplusplus)
332#pragma intrinsic(_BitScanReverse)
333#pragma intrinsic(_BitScanForward)
334#if TOMMY_SIZE_BIT == 64
335#pragma intrinsic(_BitScanReverse64)
336#pragma intrinsic(_BitScanForward64)
344#define TOMMY_ILOG2(value) ((value) == 256 ? 8 : (value) == 128 ? 7 : (value) == 64 ? 6 : (value) == 32 ? 5 : (value) == 16 ? 4 : (value) == 8 ? 3 : (value) == 4 ? 2 : (value) == 2 ? 1 : 0)
368 _BitScanReverse(&count, value);
370#elif defined(__GNUC__)
380 return __builtin_clz(value) ^ 31;
384 static unsigned char TOMMY_DE_BRUIJN_INDEX_ILOG2[32] = {
385 0, 9, 1, 10, 13, 21, 2, 29, 11, 14, 16, 18, 22, 25, 3, 30,
386 8, 12, 20, 28, 15, 17, 24, 7, 19, 27, 23, 6, 26, 5, 4, 31
393 value |= value >> 16;
395 return TOMMY_DE_BRUIJN_INDEX_ILOG2[(
tommy_uint32_t)(value * 0x07C4ACDDU) >> 27];
399#if TOMMY_SIZE_BIT == 64
407 _BitScanReverse64(&count, value);
409#elif defined(__GNUC__)
410 return __builtin_clzll(value) ^ 63;
434 _BitScanForward(&count, value);
436#elif defined(__GNUC__)
437 return __builtin_ctz(value);
441 static const unsigned char TOMMY_DE_BRUIJN_INDEX_CTZ[32] = {
442 0, 1, 28, 2, 29, 14, 24, 3, 30, 22, 20, 15, 25, 17, 4, 8,
443 31, 27, 13, 23, 21, 19, 16, 7, 26, 12, 18, 6, 11, 5, 10, 9
446 return TOMMY_DE_BRUIJN_INDEX_CTZ[(
tommy_uint32_t)(((value & - value) * 0x077CB531U)) >> 27];
450#if TOMMY_SIZE_BIT == 64
458 _BitScanForward64(&count, value);
460#elif defined(__GNUC__)
461 return __builtin_ctzll(value);
488 value |= value >> 16;
504 value |= value >> 16;
505 value |= value >> 32;
517 return ((value - 0x01010101) & ~value & 0x80808080) != 0;
523#if TOMMY_SIZE_BIT == 64
524#define tommy_ilog2 tommy_ilog2_u64
525#define tommy_ctz tommy_ctz_u64
526#define tommy_roundup_pow2 tommy_roundup_pow2_u64
528#define tommy_ilog2 tommy_ilog2_u32
529#define tommy_ctz tommy_ctz_u32
530#define tommy_roundup_pow2 tommy_roundup_pow2_u32
Data structure node.
Definition: tommytypes.h:211
tommy_size_t index
Index of the node.
Definition: tommytypes.h:236
struct tommy_node_struct * next
Next node.
Definition: tommytypes.h:216
struct tommy_node_struct * prev
Previous node.
Definition: tommytypes.h:222
void * data
Pointer to the object containing the node.
Definition: tommytypes.h:228
uint64_t tommy_uint64_t
Generic uint64_t type.
Definition: tommytypes.h:56
struct tommy_node_struct tommy_node
Data structure node.
uint32_t tommy_uint32_t
Generic uint32_t type.
Definition: tommytypes.h:55
int tommy_compare_func(const void *obj_a, const void *obj_b)
Compare function for elements.
Definition: tommytypes.h:269
int tommy_haszero_u32(tommy_uint32_t value)
Check if the specified word has a byte at 0.
Definition: tommytypes.h:515
tommy_uint_t tommy_ctz_u32(tommy_uint32_t value)
Bit scan forward or trailing zero count.
Definition: tommytypes.h:430
tommy_uint64_t tommy_roundup_pow2_u64(tommy_uint64_t value)
Rounds up to the next power of 2 for 64 bits.
Definition: tommytypes.h:497
tommy_uint_t tommy_ctz_u64(tommy_uint64_t value)
Bit scan forward or trailing zero count for 64 bits.
Definition: tommytypes.h:454
ptrdiff_t tommy_ptrdiff_t
Generic ptrdiff_t type.
Definition: tommytypes.h:71
uint64_t tommy_size_t
Generic size_t type.
Definition: tommytypes.h:60
void tommy_foreach_func(void *obj)
Foreach function.
Definition: tommytypes.h:318
int tommy_search_func(const void *arg, const void *obj)
Search function for elements.
Definition: tommytypes.h:307
tommy_uint32_t tommy_roundup_pow2_u32(tommy_uint32_t value)
Rounds up to the next power of 2.
Definition: tommytypes.h:478
tommy_uint_t tommy_ilog2_u32(tommy_uint32_t value)
Bit scan reverse or integer log2.
Definition: tommytypes.h:364
int64_t tommy_ssize_t
Generic ssize_t type.
Definition: tommytypes.h:61
void tommy_foreach_arg_func(void *arg, void *obj)
Foreach function with an argument.
Definition: tommytypes.h:325
tommy_size_t tommy_hash_t
Type used in hashtables to store the hash of an object.
Definition: tommytypes.h:193
tommy_size_t tommy_key_t
Type used in indexed data structures to store the key of an object.
Definition: tommytypes.h:188
tommy_uint32_t tommy_uint_t
Generic unsigned integer type.
Definition: tommytypes.h:80
uintptr_t tommy_uintptr_t
Generic uintptr_t type.
Definition: tommytypes.h:57
tommy_uint_t tommy_ilog2_u64(tommy_uint64_t value)
Bit scan reverse or integer log2 for 64 bits.
Definition: tommytypes.h:403
int tommy_bool_t
Generic boolean type.
Definition: tommytypes.h:72