UFO: Alien Invasion
Loading...
Searching...
No Matches
hashtable.h File Reference

Header file for hashtable. More...

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define HASHTABLE_H

Typedefs

typedef unsigned short int HASH_INDEX
typedef unsigned short int(* hashTable_hash) (const void *key, int len)
typedef int(* hashTable_compare) (const void *key1, int len1, const void *key2, int len2)

Functions

hashTable_sHASH_NewTable (bool ownsKeys, bool ownsValues, bool duplicateOverwrite)
 Creates a new hash table and sets it initial capacity.
hashTable_sHASH_NewTable (bool ownsKeys, bool ownsValues, bool duplicateOverwrite, hashTable_hash h, hashTable_compare c)
 Creates a new hash table and sets it initial capacity.
hashTable_sHASH_NewTable (bool ownsKeys, bool ownsValues, bool duplicateOverwrite, hashTable_hash h, hashTable_compare c, memPool_t *keys, memPool_t *values, memPool_t *table)
 Creates a new hash table and sets it initial capacity.
hashTable_sHASH_CloneTable (hashTable_s *source)
void HASH_DeleteTable (hashTable_s **t)
 Deletes a hash table and sets the pointer to NULL.
bool HASH_Insert (hashTable_s *t, const void *key, int nkey, const void *value, int nvalue)
 Inserts a new value with given key into the hash table.
voidHASH_Remove (hashTable_s *t, const void *key, int nkey)
 Removes an existing value with given key from the hash table.
void HASH_Clear (hashTable_s *t)
 Clears the hash table.
voidHASH_Get (hashTable_s *t, const void *key, int nkey)
 Returns the value for a given key.
int HASH_Count (hashTable_s *t)
 Returns the number of entries in the hash table.

Detailed Description

Header file for hashtable.

Definition in file hashtable.h.

Macro Definition Documentation

◆ HASHTABLE_H

#define HASHTABLE_H

Definition at line 40 of file hashtable.h.

Typedef Documentation

◆ HASH_INDEX

typedef unsigned short int HASH_INDEX

The hash uses a 256 byte table, so we define a index type here The hash function signature.

Definition at line 49 of file hashtable.h.

◆ hashTable_compare

typedef int(* hashTable_compare) (const void *key1, int len1, const void *key2, int len2)

Definition at line 53 of file hashtable.h.

◆ hashTable_hash

typedef unsigned short int(* hashTable_hash) (const void *key, int len)

The compare function signature.

Definition at line 51 of file hashtable.h.

Function Documentation

◆ HASH_Clear()

void HASH_Clear ( hashTable_s * t)

Clears the hash table.

Definition at line 460 of file hashtable.cpp.

References _release_table().

◆ HASH_CloneTable()

◆ HASH_Count()

int HASH_Count ( hashTable_s * t)

Returns the number of entries in the hash table.

Definition at line 481 of file hashtable.cpp.

References hashBucket_s::count, HASH_TABLE_SIZE, i, and hashTable_s::table.

◆ HASH_DeleteTable()

void HASH_DeleteTable ( hashTable_s ** t)

Deletes a hash table and sets the pointer to NULL.

Parameters
[in,out]tA reference to a hashTable_s pointer.

Definition at line 351 of file hashtable.cpp.

References _release_table().

Referenced by CL_ShutdownLua(), and uiNode::deleteNode().

◆ HASH_Get()

void * HASH_Get ( hashTable_s * t,
const void * key,
int nkey )

Returns the value for a given key.

Definition at line 467 of file hashtable.cpp.

References _find_bucket_entry(), hashTable_s::compare, hashTable_s::hash, i, key, and hashTable_s::table.

Referenced by CL_ExecuteCallback(), UI_GetBehaviourMethod(), and UI_GetNodeMethod().

◆ HASH_Insert()

bool HASH_Insert ( hashTable_s * t,
const void * key,
int nkey,
const void * value,
int nvalue )

Inserts a new value with given key into the hash table.

Parameters
[in]tA pointer to a hashTable_s structure.
[in]keyA pointer to a key.
[in]nkeyThe length of the key value in bytes.
[in]valueA pointer to a value.
[in]nvalueThe length of the value in bytes.
Returns
True if the insert succeeds, false otherwise.
Note
If DEBUG then insert will assert when trying to insert a duplicate key value on a list created with duplicateOverwrite = false.
By default the hash table creates duplicates of the inserted key and values. Should this behaviour be modified, the user is responsible for making sure the pointers remain valid during the lifespan of the hash table.

Definition at line 369 of file hashtable.cpp.

References _find_bucket_entry(), _hash_alloc(), hashTable_s::compare, hashBucket_s::count, hashTable_s::duplicateOverwrite, hashTable_s::hash, i, hashTable_s::internalPool, key, hashTable_s::keyPool, hashTable_s::ownsKeys, hashTable_s::ownsValues, hashBucket_s::root, hashTable_s::table, and hashTable_s::valuePool.

Referenced by CL_RegisterCallback(), HASH_CloneTable(), UI_AddBehaviourMethod(), and UI_AddNodeMethod().

◆ HASH_NewTable() [1/3]

hashTable_s * HASH_NewTable ( bool ownsKeys,
bool ownsValues,
bool duplicateOverwrite )

Creates a new hash table and sets it initial capacity.

Parameters
[in]ownsKeysIf true, the hash table stores a copy of the key.
[in]ownsValuesIf true, the hash table stores a copy of the value.
[in]duplicateOverwriteIf true, inserting a value twice will overwrite the old value. If false, the operation asserts.
Returns
A pointer to a hashTable_s.
Note
The table hash an initial index of HASH_TABLE_SIZE buckets.
The hash table will use the default hash function and default compare function.

Definition at line 287 of file hashtable.cpp.

References default_compare(), default_hash(), and HASH_NewTable().

Referenced by CL_InitLua(), HASH_CloneTable(), HASH_NewTable(), HASH_NewTable(), UI_AddBehaviourMethod(), and UI_AddNodeMethod().

◆ HASH_NewTable() [2/3]

hashTable_s * HASH_NewTable ( bool ownsKeys,
bool ownsValues,
bool duplicateOverwrite,
hashTable_hash h,
hashTable_compare c )

Creates a new hash table and sets it initial capacity.

Parameters
[in]ownsKeysIf true, the hash table stores a copy of the key.
[in]ownsValuesIf true, the hash table stores a copy of the value.
[in]duplicateOverwriteIf true, inserting a value twice will overwrite the old value. If false, the operation asserts.
[in]hThe hash function to be used when indexing.
[in]cThe compare function to be used when comparing.
Returns
A pointer to a hashTable_s.
Note
The table hash an initial index of HASH_TABLE_SIZE buckets.

Definition at line 303 of file hashtable.cpp.

References HASH_NewTable().

◆ HASH_NewTable() [3/3]

hashTable_s * HASH_NewTable ( bool ownsKeys,
bool ownsValues,
bool duplicateOverwrite,
hashTable_hash h,
hashTable_compare c,
memPool_t * keys,
memPool_t * values,
memPool_t * table )

Creates a new hash table and sets it initial capacity.

Parameters
[in]ownsKeysIf true, the hash table stores a copy of the key.
[in]ownsValuesIf true, the hash table stores a copy of the value.
[in]duplicateOverwriteIf true, inserting a value twice will overwrite the old value. If false, the operation asserts.
[in]hThe hash function to be used when indexing.
[in]cThe compare function to be used when comparing.
[in]keysIf not null, should point to a memory pool used to allocate key values.
[in]valuesIf not null, should point to a memory pool used to allocated copies of inserted values.
[in]tableIf not null, should point to a memory pool used to allocate the table internal structures, including the hashTable_s structure returned.
Returns
A pointer to a hashTable_s.
Note
The table hash an initial index of HASH_TABLE_SIZE buckets.

Definition at line 322 of file hashtable.cpp.

References _hash_alloc(), hashTable_s::compare, hashTable_s::duplicateOverwrite, hashTable_s::hash, hashTable_s::internalPool, hashTable_s::keyPool, hashTable_s::ownsKeys, hashTable_s::ownsValues, and hashTable_s::valuePool.

◆ HASH_Remove()

void * HASH_Remove ( hashTable_s * t,
const void * key,
int nkey )

Removes an existing value with given key from the hash table.

Returns
If the hash table does not own the data, returns the value pointer stored, otherwise returns NULL.

Definition at line 429 of file hashtable.cpp.

References _find_bucket_entry(), _release_entry(), hashTable_s::compare, hashBucket_s::count, hashTable_s::hash, i, key, hashItem_s::next, hashTable_s::ownsKeys, hashTable_s::ownsValues, hashBucket_s::root, hashTable_s::table, and v.