CLibs
Loading...
Searching...
No Matches
dictionary.h
Go to the documentation of this file.
1/*
2 * For more information, see `docs/set.md`.
3 * Lots of relevant information is shared between the two structures.
4 */
5
6#ifndef CLIBS_DICTIONARY_H
7#define CLIBS_DICTIONARY_H
8
10
11
12typedef struct dictionary Dictionary;
13
14
19
24
25
26struct dictionary *dict_init( void );
27
28
34int dict_item_key_cmp( const void *, const void * );
40int dict_item_val_cmp( const void *, const void * );
46int dict_item_cmp( const void *, const void * );
47
48int dict_insert_f( struct dictionary *,
49 const void *key,
50 size_t key_size,
51 const void *val,
52 size_t val_size,
53 PrintFunction key_print,
54 PrintFunction val_print );
55
66int dict_insert( struct dictionary *,
67 const void *key,
68 size_t key_size,
69 const void *val,
70 size_t val_size );
71
72bool dict_has_key( const struct dictionary *, const void *key, size_t key_size );
73
74const void *dict_get_val( const struct dictionary *, const void *key, size_t key_size );
75
76int dict_set_val( struct dictionary *,
77 const void *key,
78 size_t key_size,
79 const void *val,
80 size_t val_size );
81
82enum DictRemoveRV dict_remove( struct dictionary *,
83 const void *key_data,
84 size_t key_size );
85
86
87/* -------- SIZE/CAP -------- */
88
89size_t dict_size( const struct dictionary * );
90
91/* -------- DESTRUCTOR -------- */
92
93void dict_destroy( struct dictionary * );
94
95
96/* -------- PRINT -------- */
97
98#define dict_printn( DICTIONARY ) \
99 do \
100 { \
101 printf( "\"" #DICTIONARY "\" " ); \
102 dict_print( DICTIONARY ); \
103 } \
104 while ( 0 )
105
106#define dict_printn_as( DICTIONARY, KEY_PRINT_FUNC, VAL_PRINT_FUNC ) \
107 do \
108 { \
109 printf( "\"" #DICTIONARY "\" " ); \
110 dict_print_as( DICTIONARY, KEY_PRINT_FUNC, VAL_PRINT_FUNC ); \
111 } \
112 while ( 0 )
113
117void dict_print( const struct dictionary * );
118void dict_print_as( const struct dictionary *,
119 PrintFunction key_print,
120 PrintFunction val_print );
121
122#endif //CLIBS_DICTIONARY_H
int dict_item_val_cmp(const void *, const void *)
struct dictionary * dict_init(void)
void dict_print_as(const struct dictionary *, PrintFunction key_print, PrintFunction val_print)
enum DictRemoveRV dict_remove(struct dictionary *, const void *key_data, size_t key_size)
void dict_destroy(struct dictionary *)
size_t dict_size(const struct dictionary *)
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)
const void * dict_get_val(const struct dictionary *, const void *key, size_t key_size)
bool dict_has_key(const struct dictionary *, const void *key, size_t key_size)
DictInsertRV
Definition dictionary.h:20
@ DICTINSERT_INSERTED
Definition dictionary.h:21
@ DICTINSERT_WAS_IN
Definition dictionary.h:22
int dict_insert(struct dictionary *, const void *key, size_t key_size, const void *val, size_t val_size)
int dict_set_val(struct dictionary *, const void *key, size_t key_size, const void *val, size_t val_size)
struct dictionary Dictionary
Definition dictionary.h:12
int dict_item_cmp(const void *, const void *)
DictRemoveRV
Definition dictionary.h:15
@ DICTREMOVE_REMOVED
Definition dictionary.h:16
@ DICTREMOVE_NOT_FOUND
Definition dictionary.h:17
void dict_print(const struct dictionary *)
int dict_item_key_cmp(const void *, const void *)
void(* PrintFunction)(const void *, size_t)
Interface for functions that print data.
Definition item_print_functions.h:17