18#ifndef __R_HASH_TABLE_H__
19#define __R_HASH_TABLE_H__
21#if !defined(__RLIB_H_INCLUDE_GUARD__) && !defined(RLIB_COMPILATION)
22#error "#include <rlib.h> only please."
77#define R_HASH_TABLE_IS_SUCCESS(err) (err <= R_HASH_TABLE_OK)
79#define R_HASH_TABLE_IS_ERROR(err) (err > R_HASH_TABLE_OK)
85#define r_hash_table_new(hash, equal) r_hash_table_new_full (hash, equal, NULL, NULL)
98#define r_hash_table_ref r_ref_ref
100#define r_hash_table_unref r_ref_unref
179#define r_hash_table_remove_all_values(ht, val) \
180 r_hash_table_remove_with_func (ht, r_hash_table_remove_func_value, val)
RHashTableError r_hash_table_remove_with_func(RHashTable *ht, RKeyValueFuncReturn func, rpointer user)
Remove all entries for which func returns TRUE.
RHashTable * r_hash_table_new_full(RHashFunc hash, REqualFunc equal, RDestroyNotify keynotify, RDestroyNotify valuenotify)
Construct a hash table with custom hash / equality and optional per-side destroy notifiers.
RHashTableError r_hash_table_remove(RHashTable *ht, rconstpointer key)
Remove the entry for key; destroy notifiers run.
RHashTableError r_hash_table_steal(RHashTable *ht, rconstpointer key, rpointer *keyout, rpointer *valueout)
Remove the entry for key without running its destroy notifiers, handing ownership of the key / value ...
void r_hash_table_remove_all(RHashTable *ht)
Remove every entry, invoking destroy notifiers.
RHashTableError r_hash_table_foreach(RHashTable *ht, RKeyValueFunc func, rpointer user)
Iterate every (key, value) pair in the table.
RHashTableError r_hash_table_remove_full(RHashTable *ht, rconstpointer key, rpointer *keyout, rpointer *valueout)
Remove the entry for key, running its destroy notifiers (as r_hash_table_remove), and also report the...
rsize r_hash_table_current_alloc_size(RHashTable *ht)
Allocated bucket count; useful for sizing diagnostics.
RHashTableError r_hash_table_insert(RHashTable *ht, rpointer key, rpointer value)
Insert or replace (key, value).
RHashTableError r_hash_table_lookup_full(RHashTable *ht, rconstpointer key, rpointer *keyout, rpointer *valueout)
Look up key, returning both the stored key and value.
struct RHashTable RHashTable
Opaque refcounted hash table.
Definition rhashtable.h:60
RHashTableError
Result code for hash-table operations.
Definition rhashtable.h:69
rsize r_hash_table_size(RHashTable *ht)
Number of entries currently in the table.
rpointer r_hash_table_lookup(RHashTable *ht, rconstpointer key)
Return the value associated with key, or NULL.
rsize r_hash_table_max_probe(RHashTable *ht)
Worst-case unsuccessful-probe length; diagnostic for home distribution (small means keys are well spr...
rboolean r_hash_table_remove_func_value(rpointer key, rpointer value, rpointer user)
Filter callback that matches by value identity.
RHashTableError r_hash_table_contains(RHashTable *ht, rconstpointer key)
R_HASH_TABLE_OK iff key is present, R_HASH_TABLE_NOT_FOUND otherwise.
@ R_HASH_TABLE_NOT_FOUND
Definition rhashtable.h:73
@ R_HASH_TABLE_REPLACE
Definition rhashtable.h:70
@ R_HASH_TABLE_OK
Definition rhashtable.h:71
@ R_HASH_TABLE_INVAL
Definition rhashtable.h:72
@ R_HASH_TABLE_ERROR
Definition rhashtable.h:74
#define R_API
Public-API decoration: resolves to R_API_EXPORT while building rlib and R_API_IMPORT for consumers.
Definition rmacros.h:115
#define R_BEGIN_DECLS
Open an extern "C" block under C++ (no-op in C).
Definition rmacros.h:196
rboolean(* REqualFunc)(rconstpointer a, rconstpointer b)
Equality predicate.
Definition rtypes.h:407
rboolean(* RKeyValueFuncReturn)(rpointer key, rpointer value, rpointer user)
Key-value iteration callback that can short-circuit.
Definition rtypes.h:421
int rboolean
Boolean type (typedef'd to int).
Definition rtypes.h:59
void(* RDestroyNotify)(rpointer ptr)
Destructor callback: free / release the value at ptr.
Definition rtypes.h:401
void(* RKeyValueFunc)(rpointer key, rpointer value, rpointer user)
Iteration callback over (key, value, user) triples.
Definition rtypes.h:411
void * rpointer
Generic pointer (alias for void *).
Definition rtypes.h:327
const void * rconstpointer
Generic const pointer (alias for const void *).
Definition rtypes.h:329
unsigned long rsize
Unsigned pointer-sized size type (like size_t).
Definition rtypes.h:290
rsize(* RHashFunc)(rconstpointer key)
Hash function over an opaque key.
Definition rtypes.h:409
Pre-built hash / equality function pairs for the common key types (pointer-identity,...
Refcount base struct shared by every refcounted type in rlib.
Foundational type aliases used by every rlib header.