objc

Data Structures | Typedefs | Functions
Hash Tables

Methods for hash table creation, insertion, deletion, and lookup. More...

Collaboration diagram for Hash Tables:

Data Structures

struct  sys_hashtable_iterator
 Iterator state for hash table traversal. More...
 
struct  sys_hashtable_entry_t
 Hash table entry. More...
 

Typedefs

typedef struct sys_hashtable sys_hashtable_t
 Opaque type for hash table. More...
 
typedef struct sys_hashtable_iterator sys_hashtable_iterator_t
 Iterator state for hash table traversal. More...
 
typedef bool(* sys_hashtable_keyequals_t) (void *keyptr, void *other_keyptr)
 Compare entry with a key. More...
 

Functions

sys_hashtable_tsys_hashtable_init (size_t size, sys_hashtable_keyequals_t keyequals)
 Initialize a new hash table. More...
 
void sys_hashtable_finalize (sys_hashtable_t *table)
 Free all the hash tables in the chain. More...
 
sys_hashtable_entry_tsys_hashtable_get_key (sys_hashtable_t *table, uintptr_t hash, void *keyptr)
 Search for an entry in the hash table by hash key. More...
 
sys_hashtable_entry_tsys_hashtable_get_value (sys_hashtable_t *table, uintptr_t value)
 Search for an entry in the hash table by hash value. More...
 
sys_hashtable_entry_tsys_hashtable_put (sys_hashtable_t *table, uintptr_t hash, void *keyptr, bool *samekey)
 Return a has table entry in which to put the value, and perhaps the key. More...
 
sys_hashtable_entry_tsys_hashtable_delete_key (sys_hashtable_t *table, uintptr_t hash, void *keyptr)
 Delete an entry into the hash table by key. More...
 
sys_hashtable_entry_tsys_hashtable_delete_value (sys_hashtable_t *table, uintptr_t value)
 Delete an entry from the hash table by value. More...
 
sys_hashtable_entry_tsys_hashtable_iterator_next (sys_hashtable_t *table, sys_hashtable_iterator_t **iterator)
 Get the next entry from the iterator. More...
 
size_t sys_hashtable_count (sys_hashtable_t *table)
 Get the number of active entries in the hash table chain. More...
 
size_t sys_hashtable_capacity (sys_hashtable_t *table)
 Get the total capacity of all tables in the chain. More...
 

Detailed Description

Methods for hash table creation, insertion, deletion, and lookup.

This file declares types and functions for creating and managing hash tables. Hash tables are a data structure that implements an associative array abstract data type, a structure that can map keys to values.

Typedef Documentation

◆ sys_hashtable_iterator_t

Iterator state for hash table traversal.

This structure is used to maintain the state of an iterator while traversing a hash table. To initialize an iterator, set the table field to NULL.

◆ sys_hashtable_keyequals_t

typedef bool(* sys_hashtable_keyequals_t) (void *keyptr, void *other_keyptr)

Compare entry with a key.

This callback function is used to compare a key with another key from the hash table. It should return true if the keys match, false otherwise.

Definition at line 67 of file hashtable.h.

◆ sys_hashtable_t

typedef struct sys_hashtable sys_hashtable_t

Opaque type for hash table.

This type represents a hash table that can store key-value pairs.

Definition at line 24 of file hashtable.h.

Function Documentation

◆ sys_hashtable_capacity()

size_t sys_hashtable_capacity ( sys_hashtable_t table)

Get the total capacity of all tables in the chain.

Parameters
tableThe hash table to get capacity for
Returns
The total capacity (size) of all tables in the chain

◆ sys_hashtable_count()

size_t sys_hashtable_count ( sys_hashtable_t table)

Get the number of active entries in the hash table chain.

Parameters
tableThe hash table to count entries in
Returns
The total number of active (non-deleted) entries across all tables in the chain

◆ sys_hashtable_delete_key()

sys_hashtable_entry_t* sys_hashtable_delete_key ( sys_hashtable_t table,
uintptr_t  hash,
void *  keyptr 
)

Delete an entry into the hash table by key.

Parameters
tableThe hash table to delete from
hashThe hash key for the entry
keyptrPointer to the key data for comparison
Returns
Pointer to the deleted entry, or NULL if not found

◆ sys_hashtable_delete_value()

sys_hashtable_entry_t* sys_hashtable_delete_value ( sys_hashtable_t table,
uintptr_t  value 
)

Delete an entry from the hash table by value.

Parameters
tableThe hash table to delete from
valueThe value to delete
Returns
The deleted entry, or NULL if not found

◆ sys_hashtable_finalize()

void sys_hashtable_finalize ( sys_hashtable_t table)

Free all the hash tables in the chain.

Parameters
tableFirst hash table in the chain to free

◆ sys_hashtable_get_key()

sys_hashtable_entry_t* sys_hashtable_get_key ( sys_hashtable_t table,
uintptr_t  hash,
void *  keyptr 
)

Search for an entry in the hash table by hash key.

Parameters
tableThe hash table to search in
hashThe hash key for the entry
keyptrPointer to the key data for comparison
Returns
Pointer to the found entry, or NULL if not found

◆ sys_hashtable_get_value()

sys_hashtable_entry_t* sys_hashtable_get_value ( sys_hashtable_t table,
uintptr_t  value 
)

Search for an entry in the hash table by hash value.

Parameters
tableThe hash table to search in
valueThe value to search for
Returns
Pointer to the found entry, or NULL if not found

◆ sys_hashtable_init()

sys_hashtable_t* sys_hashtable_init ( size_t  size,
sys_hashtable_keyequals_t  keyequals 
)

Initialize a new hash table.

Parameters
sizeNumber of entries in the hash table (must be > 0)
keyequalsFunction to compare a key pointer to an entry for equality
Returns
Pointer to new hash table, or NULL if allocation failed

◆ sys_hashtable_iterator_next()

sys_hashtable_entry_t* sys_hashtable_iterator_next ( sys_hashtable_t table,
sys_hashtable_iterator_t **  iterator 
)

Get the next entry from the iterator.

Parameters
tableThe hash table being iterated
iteratorPointer to the iterator state (will be updated)
Returns
Pointer to the next entry, or NULL if no more entries

◆ sys_hashtable_put()

sys_hashtable_entry_t* sys_hashtable_put ( sys_hashtable_t table,
uintptr_t  hash,
void *  keyptr,
bool *  samekey 
)

Return a has table entry in which to put the value, and perhaps the key.

Parameters
tableThe hash table to insert into
hashThe hash key for the entry
keyptrPointer to the key data
samekeyOptional pointer to a boolean, indicating if the entry has the same key
Returns
Pointer to an entry, or NULL if allocation failed

The entry returned by this function can be used to insert or update a value in the hash table. If an entry with the same hash and key already exists, the value should be replaced.