|
Kohi Game Engine
|
This file contains the hashtable implementation. More...
#include "defines.h"Go to the source code of this file.
Data Structures | |
| struct | hashtable |
| Represents a simple hashtable. Members of this structure should not be modified outside the functions associated with it. More... | |
Typedefs | |
| typedef struct hashtable | hashtable |
| Represents a simple hashtable. Members of this structure should not be modified outside the functions associated with it. More... | |
Functions | |
| KAPI void | hashtable_create (u64 element_size, u32 element_count, void *memory, b8 is_pointer_type, hashtable *out_hashtable) |
| Creates a hashtable and stores it in out_hashtable. More... | |
| KAPI void | hashtable_destroy (hashtable *table) |
| Destroys the provided hashtable. Does not release memory for pointer types. More... | |
| KAPI b8 | hashtable_set (hashtable *table, const char *name, void *value) |
| Stores a copy of the data in value in the provided hashtable. Only use for tables which were NOT created with is_pointer_type = true. More... | |
| KAPI b8 | hashtable_set_ptr (hashtable *table, const char *name, void **value) |
| Stores a pointer as provided in value in the hashtable. Only use for tables which were created with is_pointer_type = true. More... | |
| KAPI b8 | hashtable_get (hashtable *table, const char *name, void *out_value) |
| Obtains a copy of data present in the hashtable. Only use for tables which were NOT created with is_pointer_type = true. More... | |
| KAPI b8 | hashtable_get_ptr (hashtable *table, const char *name, void **out_value) |
| Obtains a pointer to data present in the hashtable. Only use for tables which were created with is_pointer_type = true. More... | |
| KAPI b8 | hashtable_fill (hashtable *table, void *value) |
| Fills all entries in the hashtable with the given value. Useful when non-existent names should return some default value. Should not be used with pointer table types. More... | |
This file contains the hashtable implementation.
Represents a simple hashtable. Members of this structure should not be modified outside the functions associated with it.
For non-pointer types, table retains a copy of the value.For pointer types, make sure to use the _ptr setter and getter. Table does not take ownership of pointers or associated memory allocations, and should be managed externally.
| KAPI void hashtable_create | ( | u64 | element_size, |
| u32 | element_count, | ||
| void * | memory, | ||
| b8 | is_pointer_type, | ||
| hashtable * | out_hashtable | ||
| ) |
Creates a hashtable and stores it in out_hashtable.
| element_size | The size of each element in bytes. |
| element_count | The maximum number of elements. Cannot be resized. |
| memory | A pointer to hold a block of memory to be used. Internally allocated. Will be equal in size to element_size * element_count. |
| is_pointer_type | Indicates if this hashtable will hold pointer types. |
| out_hashtable | A pointer to a hashtable in which to hold relevant data. |
Destroys the provided hashtable. Does not release memory for pointer types.
| table | A pointer to the table to be destroyed. |
Fills all entries in the hashtable with the given value. Useful when non-existent names should return some default value. Should not be used with pointer table types.
| table | A pointer to the table filled. Required. |
| value | The value to be filled with. Required. |
Obtains a copy of data present in the hashtable. Only use for tables which were NOT created with is_pointer_type = true.
| table | A pointer to the table to retrieved from. Required. |
| name | The name of the entry to retrieved. Required. |
| value | A pointer to store the retrieved value. Required. |
Obtains a pointer to data present in the hashtable. Only use for tables which were created with is_pointer_type = true.
| table | A pointer to the table to retrieved from. Required. |
| name | The name of the entry to retrieved. Required. |
| value | A pointer to store the retrieved value. Required. |
Stores a copy of the data in value in the provided hashtable. Only use for tables which were NOT created with is_pointer_type = true.
| table | A pointer to the table to get from. Required. |
| name | The name of the entry to set. Required. |
| value | The value to be set. Required. |
Stores a pointer as provided in value in the hashtable. Only use for tables which were created with is_pointer_type = true.
| table | A pointer to the table to get from. Required. |
| name | The name of the entry to set. Required. |
| value | A pointer value to be set. Can pass 0 to 'unset' an entry. |