50 #define HASH_BYTE(x, y) (((y) + ((x) << 4) + ((x) >> 4)) * 11) 51 #define DEFAULT_SIZE 32 56 const unsigned char *str = (
const unsigned char *)sstr;
66 val = (val + (*str >> 4) + (*str << 4)) * 11;
70 return val % hash->
size;
77 unsigned char *data = (
unsigned char *)sdata;
83 for (i = 0; i < len; i++)
84 val = (val + (data[i] >> 4) + (data[i] << 4)) * 11;
86 return val % hash->
size;
108 curHeader->
type = type;
117 return (
void*)curHeader;
124 tHashHead *oldHashHead;
131 oldSize = curHeader->
size;
133 curHeader->
size *= 2;
134 curHeader->
hashHead = (tHashHead *)malloc(curHeader->
size *
sizeof(tHashHead));
135 for (i = 0; i < curHeader->
size; i++) {
140 for (i = 0; i < oldSize; i++) {
145 switch (curHeader->
type) {
180 if ((curHeader->
nbElem + 1) > (2 * curHeader->
size)) {
190 newElem->
key = strdup(key);
191 newElem->
size = strlen(key) + 1;
192 newElem->
data = data;
228 if (!strcmp(curElem->
key, key)) {
254 if (!strcmp(curElem->
key, key)) {
255 return curElem->
data;
281 if ((curHeader->
nbElem + 1) > (2 * curHeader->
size)) {
285 index =
hash_buf(curHeader, key, sz);
287 newElem->
key = (
char *)malloc(sz);
288 memcpy(newElem->
key, key, sz);
290 newElem->
data = data;
309 index =
hash_buf(curHeader, key, sz);
312 if (!memcmp(curElem->
key, key, sz)) {
336 index =
hash_buf(curHeader, key, sz);
339 if (!memcmp(curElem->
key, key, sz)) {
340 return curElem->
data;
360 for (i = 0; i < curHeader->
size; i++) {
#define GF_HASH_TYPE_STR
String key based hash table.
void(* tfHashFree)(const void *)
Function to call for releasing the user data associated with hash table.
#define GF_TAILQ_INSERT_TAIL(head, elm, field)
Insert an element at the tail.
const void * GfHashGetNext(void *hash)
Get the next user data of a hash table, this is used for table scans.
GF_TAILQ_HEAD(HashHead, tHashElem)
const void * GfHashGetFirst(void *hash)
Get the first user data of a hash table, this is used for table scans.
void GfHashRelease(void *hash, tfHashFree hashFree)
Release a hash table.
const void * GfHashGetBuf(void *hash, char *key, size_t sz)
Get the user data associated with a memory buffer key.
const void * GfHashGetStr(void *hash, const char *key)
Get the user data associated with a string key.
void GfHashAddBuf(void *hash, char *key, size_t sz, void *data)
Add an element with a memory buffer key to a hash table.
const void * GfHashRemBuf(void *hash, char *key, size_t sz)
Remove an element with a memory buffer key from a hash table.
void * GfHashCreate(int type)
Create a new hash table.
The Gaming Framework API.
#define GF_TAILQ_INIT(head)
Head initialization (Mandatory)
static const void * gfRemElem(tHashHead *hashHead, tHashElem *elem)
Remove a table element.
#define GF_HASH_TYPE_BUF
Memory buffer key based hash table.
const void * GfHashRemStr(void *hash, char *key)
Remove an element with a string key from a hash table.
struct HashElem tHashElem
#define GF_TAILQ_FIRST(head)
First element of a TAILQ.
static unsigned int hash_str(tHashHeader *hash, const char *sstr)
#define GF_TAILQ_REMOVE(head, elm, field)
Remove an element.
int GfHashAddStr(void *hash, const char *key, const void *data)
Add an element with a string key to a hash table.
#define GF_TAILQ_NEXT(elm, field)
Next element of a TAILQ.
struct HashHeader tHashHeader
static void gfIncreaseHash(tHashHeader *curHeader)
Double the size of the hash table.
GF_TAILQ_ENTRY(struct HashElem) link
static unsigned int hash_buf(tHashHeader *hash, char *sdata, int len)