COMBINATORIAL_BLAS  1.6
tommytypes.h File Reference
#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)
 

Detailed Description

Generic types.

Definition in file tommytypes.h.

Macro Definition Documentation

◆ tommy_calloc

#define tommy_calloc   calloc

Definition at line 96 of file tommytypes.h.

◆ tommy_cast

#define tommy_cast (   type,
  value 
)    (value)

Definition at line 77 of file tommytypes.h.

◆ tommy_free

#define tommy_free   free

Definition at line 102 of file tommytypes.h.

◆ TOMMY_ILOG2

#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.

◆ tommy_inline

#define tommy_inline   static

Definition at line 115 of file tommytypes.h.

◆ TOMMY_KEY_BIT

#define TOMMY_KEY_BIT   (sizeof(tommy_key_t) * 8)

Bits into the tommy_key_t type.

Definition at line 165 of file tommytypes.h.

◆ tommy_likely

#define tommy_likely (   x)    (x)

Definition at line 139 of file tommytypes.h.

◆ tommy_malloc

#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.

◆ tommy_realloc

#define tommy_realloc   realloc

Definition at line 99 of file tommytypes.h.

◆ tommy_restrict

#define tommy_restrict

Definition at line 128 of file tommytypes.h.

◆ tommy_unlikely

#define tommy_unlikely (   x)    (x)

Definition at line 150 of file tommytypes.h.

Typedef Documentation

◆ tommy_bool_t

typedef int tommy_bool_t

Generic boolean type.

Definition at line 52 of file tommytypes.h.

◆ tommy_compare_func

typedef int tommy_compare_func(const void *obj_a, const void *obj_b)

Compare function for elements.

Parameters
obj_aPointer at the first object to compare.
obj_bPointer at the second object to compare.
Returns
<0 if the first element is less than the second, ==0 equal, >0 if greather.

This function is like the C strcmp().

struct object {
tommy_node node;
int value;
};
int compare(const void* obj_a, const void* obj_b)
{
if (((const struct object*)obj_a)->value < ((const struct object*)obj_b)->value)
return -1;
if (((const struct object*)obj_a)->value > ((const struct object*)obj_b)->value)
return 1;
return 0;
}

Definition at line 240 of file tommytypes.h.

◆ 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.

◆ tommy_foreach_arg_func

typedef void tommy_foreach_arg_func(void *arg, void *obj)

Foreach function with an argument.

Parameters
argPointer at a generic argument.
objPointer at the object to iterate.

Definition at line 291 of file tommytypes.h.

◆ tommy_foreach_func

typedef void tommy_foreach_func(void *obj)

Foreach function.

Parameters
objPointer 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.

◆ 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.

◆ tommy_node

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:

struct object {
tommy_node node;
// other fields
};

◆ tommy_ptrdiff_t

typedef ptrdiff_t tommy_ptrdiff_t

Generic ptrdiff_t type.

Definition at line 51 of file tommytypes.h.

◆ tommy_search_func

typedef int tommy_search_func(const void *arg, const void *obj)

Search function for elements.

Parameters
argPointer at the value to search.
objPointer at the object to compare to.
Returns
==0 if the value matches the element. !=0 if different.

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.

struct object {
tommy_node node;
int value;
};
int compare(const void* arg, const void* obj)
{
return *(const int*)arg != ((const struct object*)obj)->value;
}
int value_to_find = 1;
struct object* obj = tommy_hashtable_search(&hashtable, compare, &value_to_find, tommy_inthash_u32(value_to_find));
if (!obj) {
// not found
} else {
// found
}

Definition at line 273 of file tommytypes.h.

◆ tommy_size_t

typedef size_t tommy_size_t

Generic size_t type.

Definition at line 50 of file tommytypes.h.

◆ tommy_uint32_t

typedef uint32_t tommy_uint32_t

Generic uint32_t type.

Definition at line 46 of file tommytypes.h.

◆ tommy_uint64_t

typedef uint64_t tommy_uint64_t

Generic uint64_t type.

Definition at line 47 of file tommytypes.h.

◆ 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.

◆ tommy_uintptr_t

typedef uintptr_t tommy_uintptr_t

Generic uintptr_t type.

Definition at line 48 of file tommytypes.h.

Function Documentation

◆ tommy_ctz_u32()

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.

Parameters
valueValue to scan. 0 is not allowed.
Returns
The index of the least significant bit set.

Definition at line 369 of file tommytypes.h.

◆ tommy_ilog2_u32()

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

Parameters
valueValue to scan. 0 is not allowed.
Returns
The index of the most significant bit set.

Definition at line 326 of file tommytypes.h.

◆ tommy_roundup_pow2_u32()

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.

Returns
The smallest power of 2 not less than the specified value.

Definition at line 394 of file tommytypes.h.