#include <stddef.h>
#include <stdint.h>
#include <stdlib.h>
Go to the source code of this file.
Classes | |
struct | tommy_node_struct |
Macros | |
#define | tommy_cast(type, value) (value) |
#define | tommy_malloc malloc |
#define | tommy_calloc calloc |
#define | tommy_realloc realloc |
#define | tommy_free free |
#define | tommy_inline static |
#define | tommy_restrict |
#define | tommy_likely(x) (x) |
#define | tommy_unlikely(x) (x) |
#define | TOMMY_KEY_BIT (sizeof(tommy_key_t) * 8) |
#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) |
Typedefs | |
typedef uint32_t | tommy_uint32_t |
typedef uint64_t | tommy_uint64_t |
typedef uintptr_t | tommy_uintptr_t |
typedef size_t | tommy_size_t |
typedef ptrdiff_t | tommy_ptrdiff_t |
typedef int | tommy_bool_t |
typedef tommy_uint32_t | tommy_uint_t |
typedef tommy_uint32_t | tommy_count_t |
typedef tommy_uint32_t | tommy_key_t |
typedef struct tommy_node_struct | tommy_node |
typedef int | tommy_compare_func(const void *obj_a, const void *obj_b) |
typedef int | tommy_search_func(const void *arg, const void *obj) |
typedef void | tommy_foreach_func(void *obj) |
typedef void | tommy_foreach_arg_func(void *arg, void *obj) |
Functions | |
tommy_inline tommy_uint_t | tommy_ilog2_u32 (tommy_uint32_t value) |
tommy_inline tommy_uint_t | tommy_ctz_u32 (tommy_uint32_t value) |
tommy_inline tommy_uint32_t | tommy_roundup_pow2_u32 (tommy_uint32_t value) |
Generic types.
Definition in file tommytypes.h.
#define tommy_calloc calloc |
Definition at line 96 of file tommytypes.h.
#define tommy_cast | ( | type, | |
value | |||
) | (value) |
Definition at line 77 of file tommytypes.h.
#define tommy_free free |
Definition at line 102 of file tommytypes.h.
#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) |
Definition at line 306 of file tommytypes.h.
#define tommy_inline static |
Definition at line 115 of file tommytypes.h.
#define TOMMY_KEY_BIT (sizeof(tommy_key_t) * 8) |
Bits into the tommy_key_t type.
Definition at line 165 of file tommytypes.h.
#define tommy_likely | ( | x | ) | (x) |
Definition at line 139 of file tommytypes.h.
#define tommy_malloc malloc |
Generic malloc(), calloc(), realloc() and free() functions. Redefine them to what you need. By default they map to the C malloc(), calloc(), realloc() and free().
Definition at line 93 of file tommytypes.h.
#define tommy_realloc realloc |
Definition at line 99 of file tommytypes.h.
#define tommy_restrict |
Definition at line 128 of file tommytypes.h.
#define tommy_unlikely | ( | x | ) | (x) |
Definition at line 150 of file tommytypes.h.
typedef int tommy_bool_t |
Generic boolean type.
Definition at line 52 of file tommytypes.h.
typedef int tommy_compare_func(const void *obj_a, const void *obj_b) |
Compare function for elements.
obj_a | Pointer at the first object to compare. |
obj_b | Pointer at the second object to compare. |
This function is like the C strcmp().
Definition at line 240 of file tommytypes.h.
typedef tommy_uint32_t tommy_count_t |
Generic unsigned integer for counting objects.
TommyDS doesn't support more than 2^32-1 objects.
Definition at line 67 of file tommytypes.h.
typedef void tommy_foreach_arg_func(void *arg, void *obj) |
Foreach function with an argument.
arg | Pointer at a generic argument. |
obj | Pointer at the object to iterate. |
Definition at line 291 of file tommytypes.h.
typedef void tommy_foreach_func(void *obj) |
Foreach function.
obj | Pointer at the object to iterate. |
A typical example is to use free() to deallocate all the objects in a list.
Definition at line 284 of file tommytypes.h.
typedef tommy_uint32_t tommy_key_t |
Key type used in indexed data structures to store the key or the hash value.
Definition at line 160 of file tommytypes.h.
typedef struct tommy_node_struct tommy_node |
Data structure node. This node type is shared between all the data structures and used to store some info directly into the objects you want to store.
A typical declaration is:
typedef ptrdiff_t tommy_ptrdiff_t |
Generic ptrdiff_t type.
Definition at line 51 of file tommytypes.h.
typedef int tommy_search_func(const void *arg, const void *obj) |
Search function for elements.
arg | Pointer at the value to search. |
obj | Pointer at the object to compare to. |
Note that the first argument is a pointer to the value to search and the second one is a pointer to the object to compare. They are pointers of two different types.
Definition at line 273 of file tommytypes.h.
typedef size_t tommy_size_t |
Generic size_t type.
Definition at line 50 of file tommytypes.h.
typedef uint32_t tommy_uint32_t |
Generic uint32_t type.
Definition at line 46 of file tommytypes.h.
typedef uint64_t tommy_uint64_t |
Generic uint64_t type.
Definition at line 47 of file tommytypes.h.
typedef tommy_uint32_t tommy_uint_t |
Generic unsigned integer type.
It has no specific size, as is used to store only small values. To make the code more efficient, a full 32 bit integer is used.
Definition at line 60 of file tommytypes.h.
typedef uintptr_t tommy_uintptr_t |
Generic uintptr_t type.
Definition at line 48 of file tommytypes.h.
tommy_inline tommy_uint_t tommy_ctz_u32 | ( | tommy_uint32_t | value | ) |
Bit scan forward or trailing zero count. Return the bit index of the least significant 1 bit.
If no bit is set, the result is undefined.
value | Value to scan. 0 is not allowed. |
Definition at line 369 of file tommytypes.h.
tommy_inline tommy_uint_t tommy_ilog2_u32 | ( | tommy_uint32_t | value | ) |
Bit scan reverse or integer log2. Return the bit index of the most significant 1 bit.
If no bit is set, the result is undefined. To force a return 0 in this case, you can use tommy_ilog2_u32(value | 1).
Other interesting ways for bitscan are at:
Bit Twiddling Hacks http://graphics.stanford.edu/~seander/bithacks.html
Chess Programming BitScan http://chessprogramming.wikispaces.com/BitScan
value | Value to scan. 0 is not allowed. |
Definition at line 326 of file tommytypes.h.
tommy_inline tommy_uint32_t tommy_roundup_pow2_u32 | ( | tommy_uint32_t | value | ) |
Rounds up to the next power of 2. For the value 0, the result is undefined.
Definition at line 394 of file tommytypes.h.