Crossfire Server, Trunk
hashtable.c File Reference
#include <string.h>
#include <stdlib.h>
#include <stdint.h>
#include <autoconf.h>
#include <hashtable.h>
+ Include dependency graph for hashtable.c:

Go to the source code of this file.

Functions

void add_ptr_assoc (ptr_assoc **hash_table, void *key, void *value)
 
void * find_assoc_value (ptr_assoc **hash_table, void *key)
 
static ptr_assocfind_ptr_assoc (ptr_assoc **hash_table, void *key)
 
void free_ptr_assoc (ptr_assoc **hash_table, void *key)
 
static int hashptr (void *ptr)
 
void init_ptr_assoc_table (ptr_assoc **hash_table)
 
static ptr_assocnew_ptr_assoc (void *key, void *value)
 

Function Documentation

◆ add_ptr_assoc()

void add_ptr_assoc ( ptr_assoc **  hash_table,
void *  key,
void *  value 
)

Adds a value to a hash table which one can lookup with key.

Parameters
hash_tablePointer to the hash table to add to.
keyThe key to lookup by in the association.
valueThe value to store with the key.

Definition at line 108 of file hashtable.c.

References _shared_string::array, hash_table, hashptr(), _ptr_assoc::key, castle_read::key, new_ptr_assoc(), _ptr_assoc::next, _ptr_assoc::previous, autojail::value, and _ptr_assoc::value.

Referenced by add_map_assoc(), and add_object_assoc().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ find_assoc_value()

void* find_assoc_value ( ptr_assoc **  hash_table,
void *  key 
)

Find the value associated with a given key.

Parameters
hash_tablePointer to the hash table to search.
keyThe key to lookup by in the association.
Returns
The value associated with the key.

Definition at line 204 of file hashtable.c.

References find_ptr_assoc(), hash_table, castle_read::key, and _ptr_assoc::value.

Referenced by find_assoc_pymap(), and find_assoc_pyobject().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ find_ptr_assoc()

static ptr_assoc* find_ptr_assoc ( ptr_assoc **  hash_table,
void *  key 
)
static

Find the ptr_assoc with a given key.

Parameters
hash_tablePointer to the hash table to search.
keyThe key to lookup by in the association.
Returns
The ptr_assoc that is found, or null if none is found.

Definition at line 167 of file hashtable.c.

References hash_table, hashptr(), _ptr_assoc::key, castle_read::key, and _ptr_assoc::next.

Referenced by find_assoc_value(), and free_ptr_assoc().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ free_ptr_assoc()

void free_ptr_assoc ( ptr_assoc **  hash_table,
void *  key 
)

Remove the association with a given key.

Parameters
hash_tablePointer to the hash table to search.
keyThe key to lookup by in the association.

Definition at line 221 of file hashtable.c.

References _ptr_assoc::array, find_ptr_assoc(), hash_table, castle_read::key, _ptr_assoc::next, and _ptr_assoc::previous.

Referenced by free_map_assoc(), and free_object_assoc().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ hashptr()

static int hashptr ( void *  ptr)
static

Hashing-function used by the pointer association library. Currently just takes the pointer modulus the table size (which should be a prime number).

Parameters
ptrThe pointer to hash.
Returns
The returned hash value.

Definition at line 71 of file hashtable.c.

References PTR_ASSOC_TABLESIZE.

Referenced by add_ptr_assoc(), and find_ptr_assoc().

+ Here is the caller graph for this function:

◆ init_ptr_assoc_table()

void init_ptr_assoc_table ( ptr_assoc **  hash_table)

Initialises the hash table for a pointer association table.

Parameters
hash_tablePointer to the hash table to initialise.

Definition at line 56 of file hashtable.c.

References hash_table, PTR_ASSOC_TABLESIZE, and nlohmann::detail::void().

Referenced by init_map_assoc_table(), and init_object_assoc_table().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ new_ptr_assoc()

static ptr_assoc* new_ptr_assoc ( void *  key,
void *  value 
)
static

Allocates and initialises a new ptr_assoc structure.

Parameters
keyThe key to lookup by in the association.
valueThe value to store with the key.
Returns
The new ptr_assoc structure.

Definition at line 86 of file hashtable.c.

References _ptr_assoc::array, _ptr_assoc::key, castle_read::key, _ptr_assoc::next, _ptr_assoc::previous, autojail::value, and _ptr_assoc::value.

Referenced by add_ptr_assoc().

+ Here is the caller graph for this function: