rlib
Convenience library for useful things
Loading...
Searching...
No Matches
Dictionary (string-keyed hashtable)

Thin convenience wrapper around RHashTable that preconfigures string hashing / equality and renames the surface to a more dictionary-flavoured spelling. More...

Files

file  rdictionary.h
 String-keyed convenience wrapper around RHashTable.
 

Macros

#define RDictionary   RHashTable
 Alias: RDictionary is just an RHashTable.
 
#define r_dictionary_ref   r_ref_ref
 Increment the dictionary's refcount.
 
#define r_dictionary_unref   r_ref_unref
 Decrement the dictionary's refcount; clears all entries when it reaches zero.
 

Functions

static RDictionaryr_dictionary_new (void)
 Construct an empty string-keyed dictionary (no value notifier).
 
static RDictionaryr_dictionary_new_full (RDestroyNotify notify)
 Construct an empty dictionary with a value destroy notifier.
 
static rsize r_dictionary_size (RDictionary *dict)
 Number of entries currently in the dictionary.
 
static rsize r_dictionary_current_alloc_size (RDictionary *dict)
 Allocated bucket count.
 
static rboolean r_dictionary_insert (RDictionary *dict, const rchar *key, rpointer value)
 Insert (key, value).
 
static rpointer r_dictionary_lookup (RDictionary *dict, const rchar *key)
 Return the value associated with key, or NULL.
 
static rboolean r_dictionary_lookup_full (RDictionary *dict, const rchar *key, rpointer *value)
 Look up key, returning the value via value.
 
static rboolean r_dictionary_contains (RDictionary *dict, const rchar *key)
 TRUE iff key is present.
 
static rboolean r_dictionary_steal (RDictionary *dict, const rchar *key, rpointer *value)
 Remove key without running the value destroy notifier; return the value via value.
 
static rboolean r_dictionary_remove (RDictionary *dict, const rchar *key)
 Remove key (value destroy notifier runs).
 
static rboolean r_dictionary_foreach (RDictionary *dict, RStrKeyValueFunc func, rpointer user)
 Iterate every entry in the dictionary.
 

Detailed Description

Thin convenience wrapper around RHashTable that preconfigures string hashing / equality and renames the surface to a more dictionary-flavoured spelling.

RDictionary is a typedef alias for RHashTable; the two are the same object and the r_dictionary_* accessors call straight through to their r_hash_table_* equivalents.

Use this when keys are NUL-terminated C strings and the caller doesn't want to spell out the hash / equality pair.

Function Documentation

◆ r_dictionary_insert()

static rboolean r_dictionary_insert ( RDictionary dict,
const rchar key,
rpointer  value 
)
inlinestatic

Insert (key, value).

Returns
TRUE only on a fresh insert; FALSE if the key already existed (its value is replaced) or on internal failure.