22#define TOMMY_SIZE_BIT 64
23#define TOMMY_SIZE_MAX _UI64_MAX
27#define TOMMY_SIZE_BIT 32
28#define TOMMY_SIZE_MAX UINT_MAX
37#if SIZE_MAX == UINT64_MAX
38#define TOMMY_SIZE_BIT 64
39#define TOMMY_SIZE_MAX SIZE_MAX
42#elif SIZE_MAX == UINT32_MAX
43#define TOMMY_SIZE_BIT 32
44#define TOMMY_SIZE_MAX SIZE_MAX
48#error Unsupported SIZE_MAX
76#define tommy_cast(type, value) static_cast<type>(value)
78#define tommy_cast(type, value) (value)
140#if !defined(tommy_malloc) || !defined(tommy_calloc) || !defined(tommy_realloc) || !defined(tommy_free)
143#if !defined(tommy_malloc)
144#define tommy_malloc malloc
146#if !defined(tommy_calloc)
147#define tommy_calloc calloc
149#if !defined(tommy_realloc)
150#define tommy_realloc realloc
152#if !defined(tommy_free)
153#define tommy_free free
163#if !defined(TOMMY_API)
170#if !defined(tommy_inline)
171#if defined(_MSC_VER) || defined(__GNUC__)
172#define tommy_inline static __inline
174#define tommy_inline static
181#if !defined(tommy_restrict)
182#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
183#define tommy_restrict restrict
184#elif defined(_MSC_VER) || defined(__GNUC__)
185#define tommy_restrict __restrict
187#define tommy_restrict
194#if !defined(tommy_likely)
196#define tommy_likely(x) __builtin_expect(!!(x), 1)
198#define tommy_likely(x) (x)
205#if !defined(tommy_unlikely)
207#define tommy_unlikely(x) __builtin_expect(!!(x), 0)
209#define tommy_unlikely(x) (x)
358#if defined(_MSC_VER) && !defined(__cplusplus)
360#pragma intrinsic(_BitScanReverse)
361#pragma intrinsic(_BitScanForward)
362#if TOMMY_SIZE_BIT == 64
363#pragma intrinsic(_BitScanReverse64)
364#pragma intrinsic(_BitScanForward64)
372#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)
396 _BitScanReverse(&count, value);
398#elif defined(__GNUC__)
408 return __builtin_clz(value) ^ 31;
412 static const unsigned char TOMMY_DE_BRUIJN_INDEX_ILOG2[32] = {
413 0, 9, 1, 10, 13, 21, 2, 29, 11, 14, 16, 18, 22, 25, 3, 30,
414 8, 12, 20, 28, 15, 17, 24, 7, 19, 27, 23, 6, 26, 5, 4, 31
421 value |= value >> 16;
423 return TOMMY_DE_BRUIJN_INDEX_ILOG2[(
tommy_uint32_t)(value * 0x07C4ACDDU) >> 27];
437#if defined(_MSC_VER) && defined(_WIN64)
439 _BitScanReverse64(&count, value);
441#elif defined(__GNUC__)
442 return __builtin_clzll(value) ^ 63;
465 _BitScanForward(&count, value);
467#elif defined(__GNUC__)
468 return __builtin_ctz(value);
472 static const unsigned char TOMMY_DE_BRUIJN_INDEX_CTZ[32] = {
473 0, 1, 28, 2, 29, 14, 24, 3, 30, 22, 20, 15, 25, 17, 4, 8,
474 31, 27, 13, 23, 21, 19, 16, 7, 26, 12, 18, 6, 11, 5, 10, 9
477 return TOMMY_DE_BRUIJN_INDEX_CTZ[(
tommy_uint32_t)(((value & -value) * 0x077CB531U)) >> 27];
491#if defined(_MSC_VER) && defined(_WIN64)
493 _BitScanForward64(&count, value);
495#elif defined(__GNUC__)
496 return __builtin_ctzll(value);
523 value |= value >> 16;
542 value |= value >> 16;
543 value |= value >> 32;
556 return ((value - 0x01010101) & ~value & 0x80808080) != 0;
566 return ((value - 0x0101010101010101ULL) & ~value & 0x8080808080808080ULL) != 0;
572#if TOMMY_SIZE_BIT == 64
573#define tommy_ilog2 tommy_ilog2_u64
574#define tommy_ctz tommy_ctz_u64
575#define tommy_roundup_pow2 tommy_roundup_pow2_u64
577#define tommy_ilog2 tommy_ilog2_u32
578#define tommy_ctz tommy_ctz_u32
579#define tommy_roundup_pow2 tommy_roundup_pow2_u32
Data structure node.
Definition: tommytypes.h:242
tommy_size_t index
Index of the node.
Definition: tommytypes.h:269
struct tommy_node_struct * next
Next node.
Definition: tommytypes.h:247
struct tommy_node_struct * prev
Previous node.
Definition: tommytypes.h:253
void * data
Pointer to the element containing the node.
Definition: tommytypes.h:260
uint64_t tommy_uint64_t
Generic uint64_t type.
Definition: tommytypes.h:35
int tommy_haszero_u64(tommy_uint64_t value)
Checks if the specified 64-bit word has a byte at 0.
Definition: tommytypes.h:564
struct tommy_node_struct tommy_node
Data structure node.
uint32_t tommy_uint32_t
Generic uint32_t type.
Definition: tommytypes.h:34
void tommy_foreach_func(void *elem)
Foreach function.
Definition: tommytypes.h:346
int tommy_haszero_u32(tommy_uint32_t value)
Checks if the specified word has a byte at 0.
Definition: tommytypes.h:554
tommy_uint_t tommy_ctz_u32(tommy_uint32_t value)
Bit scan forward or trailing zero count.
Definition: tommytypes.h:461
int tommy_search_func(const void *arg, const void *elem)
Search function for elements.
Definition: tommytypes.h:334
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:535
int tommy_compare_func(const void *elem_a, const void *elem_b)
Compare function for elements.
Definition: tommytypes.h:302
tommy_uint_t tommy_ctz_u64(tommy_uint64_t value)
Bit scan forward or trailing zero count for 64 bits.
Definition: tommytypes.h:489
ptrdiff_t tommy_ptrdiff_t
Generic ptrdiff_t type.
Definition: tommytypes.h:52
uint64_t tommy_size_t
Generic size_t type.
Definition: tommytypes.h:40
void tommy_foreach_arg_func(void *arg, void *elem)
Foreach function with an argument.
Definition: tommytypes.h:353
tommy_uint32_t tommy_roundup_pow2_u32(tommy_uint32_t value)
Rounds up to the next power of 2.
Definition: tommytypes.h:513
tommy_uint_t tommy_ilog2_u32(tommy_uint32_t value)
Bit scan reverse or integer log2.
Definition: tommytypes.h:392
int64_t tommy_ssize_t
Generic ssize_t type.
Definition: tommytypes.h:41
tommy_size_t tommy_hash_t
Type used in hashtables to store the hash of an element.
Definition: tommytypes.h:224
tommy_size_t tommy_key_t
Type used in indexed data structures to store the key of an element.
Definition: tommytypes.h:219
tommy_uint32_t tommy_uint_t
Generic unsigned integer type.
Definition: tommytypes.h:61
uintptr_t tommy_uintptr_t
Generic uintptr_t type.
Definition: tommytypes.h:36
tommy_uint_t tommy_ilog2_u64(tommy_uint64_t value)
Bit scan reverse or integer log2 for 64 bits.
Definition: tommytypes.h:435
int tommy_bool_t
Generic boolean type.
Definition: tommytypes.h:53