CLibs
Loading...
Searching...
No Matches
dictionary.h File Reference

Go to the source code of this file.

Macros

#define dict_printn(DICTIONARY)
#define dict_printn_as(DICTIONARY, KEY_PRINT_FUNC, VAL_PRINT_FUNC)

Typedefs

typedef struct dictionary Dictionary

Enumerations

enum  DictRemoveRV { DICTREMOVE_REMOVED = 0 , DICTREMOVE_NOT_FOUND = 1 }
enum  DictInsertRV { DICTINSERT_INSERTED = 0 , DICTINSERT_WAS_IN = 1 }

Functions

struct dictionary * dict_init (void)
int dict_item_key_cmp (const void *, const void *)
int dict_item_val_cmp (const void *, const void *)
int dict_item_cmp (const void *, const void *)
int dict_insert_f (struct dictionary *, const void *key, size_t key_size, const void *val, size_t val_size, PrintFunction key_print, PrintFunction val_print)
int dict_insert (struct dictionary *, const void *key, size_t key_size, const void *val, size_t val_size)
bool dict_has_key (const struct dictionary *, const void *key, size_t key_size)
const void * dict_get_val (const struct dictionary *, const void *key, size_t key_size)
int dict_set_val (struct dictionary *, const void *key, size_t key_size, const void *val, size_t val_size)
enum DictRemoveRV dict_remove (struct dictionary *, const void *key_data, size_t key_size)
size_t dict_size (const struct dictionary *)
void dict_destroy (struct dictionary *)
void dict_print (const struct dictionary *)
void dict_print_as (const struct dictionary *, PrintFunction key_print, PrintFunction val_print)

Macro Definition Documentation

◆ dict_printn

#define dict_printn ( DICTIONARY)
Value:
do \
{ \
printf( "\"" #DICTIONARY "\" " ); \
dict_print( DICTIONARY ); \
} \
while ( 0 )

◆ dict_printn_as

#define dict_printn_as ( DICTIONARY,
KEY_PRINT_FUNC,
VAL_PRINT_FUNC )
Value:
do \
{ \
printf( "\"" #DICTIONARY "\" " ); \
dict_print_as( DICTIONARY, KEY_PRINT_FUNC, VAL_PRINT_FUNC ); \
} \
while ( 0 )

Typedef Documentation

◆ Dictionary

typedef struct dictionary Dictionary

Enumeration Type Documentation

◆ DictInsertRV

Enumerator
DICTINSERT_INSERTED 
DICTINSERT_WAS_IN 

◆ DictRemoveRV

Enumerator
DICTREMOVE_REMOVED 
DICTREMOVE_NOT_FOUND 

Function Documentation

◆ dict_destroy()

void dict_destroy ( struct dictionary * )

◆ dict_get_val()

const void * dict_get_val ( const struct dictionary * ,
const void * key,
size_t key_size )

◆ dict_has_key()

bool dict_has_key ( const struct dictionary * ,
const void * key,
size_t key_size )

◆ dict_init()

struct dictionary * dict_init ( void )

◆ dict_insert()

int dict_insert ( struct dictionary * ,
const void * key,
size_t key_size,
const void * val,
size_t val_size )

Inserts the value pointed to by ‹val› into the dictionary with the key pointed to by ‹key›

Parameters
keykey pointer
key_sizesizeof key
valval pointer
val_sizesizeof val
Returns

◆ dict_insert_f()

int dict_insert_f ( struct dictionary * ,
const void * key,
size_t key_size,
const void * val,
size_t val_size,
PrintFunction key_print,
PrintFunction val_print )

◆ dict_item_cmp()

int dict_item_cmp ( const void * ,
const void *  )

Compares the keys first, then values

Returns
-1, 0, 1

◆ dict_item_key_cmp()

int dict_item_key_cmp ( const void * ,
const void *  )

Only compares the data in key and key_size

Returns
-1, 0, 1

◆ dict_item_val_cmp()

int dict_item_val_cmp ( const void * ,
const void *  )

Only compares the data in val and val_size

Returns
-1, 0, 1

◆ dict_print()

void dict_print ( const struct dictionary * )

Prints the contents of the dictionary as "‹key›: ‹val›"

◆ dict_print_as()

void dict_print_as ( const struct dictionary * ,
PrintFunction key_print,
PrintFunction val_print )

◆ dict_remove()

enum DictRemoveRV dict_remove ( struct dictionary * ,
const void * key_data,
size_t key_size )

◆ dict_set_val()

int dict_set_val ( struct dictionary * ,
const void * key,
size_t key_size,
const void * val,
size_t val_size )

◆ dict_size()

size_t dict_size ( const struct dictionary * )