|
qb_map_t * | qb_hashtable_create (size_t max_size) |
| Create an unsorted map based on a hashtable. More...
|
|
qb_map_t * | qb_skiplist_create (void) |
| Create a sorted map using a skiplist. More...
|
|
qb_map_t * | qb_trie_create (void) |
| Create a sorted map using a Patricia trie or "Radix tree". More...
|
|
void | qb_trie_dump (qb_map_t *m) |
| print out the nodes in the trie More...
|
|
int32_t | qb_map_notify_add (qb_map_t *m, const char *key, qb_map_notify_fn fn, int32_t events, void *user_data) |
| Add a notifier to the map. More...
|
|
int32_t | qb_map_notify_del (qb_map_t *m, const char *key, qb_map_notify_fn fn, int32_t events) |
| Delete a notifier from the map. More...
|
|
int32_t | qb_map_notify_del_2 (qb_map_t *m, const char *key, qb_map_notify_fn fn, int32_t events, void *user_data) |
| Delete a notifier from the map (including the userdata). More...
|
|
void | qb_map_put (qb_map_t *map, const char *key, const void *value) |
| Inserts a new key and value into a qb_map_t. More...
|
|
void * | qb_map_get (qb_map_t *map, const char *key) |
| Gets the value corresponding to the given key. More...
|
|
int32_t | qb_map_rm (qb_map_t *map, const char *key) |
| Removes a key/value pair from a map. More...
|
|
size_t | qb_map_count_get (qb_map_t *map) |
| Get the number of items in the map. More...
|
|
void | qb_map_foreach (qb_map_t *map, qb_map_transverse_fn func, void *user_data) |
| Calls the given function for each of the key/value pairs in the map. More...
|
|
qb_map_iter_t * | qb_map_iter_create (qb_map_t *map) |
| Create an iterator. More...
|
|
qb_map_iter_t * | qb_map_pref_iter_create (qb_map_t *map, const char *prefix) |
| Create a prefix iterator. More...
|
|
const char * | qb_map_iter_next (qb_map_iter_t *i, void **value) |
| Get the next item. More...
|
|
void | qb_map_iter_free (qb_map_iter_t *i) |
| free the iterator More...
|
|
void | qb_map_destroy (qb_map_t *map) |
| Destroy the map, removes all the items from the map. More...
|
|
This provides a map interface to a Patricia trie, hashtable or skiplist.
- Ordering
- The hashtable is NOT ordered, but ptrie and skiplist are.
- Iterating
- Below is a simple example of how to iterate over a map.
const char *p;
void *data;
printf("%s > %s\n", p, (char*) data);
}
struct qb_map_iter qb_map_iter_t
This is an opaque data type representing an iterator instance.
Definition: qbmap.h:103
qb_map_iter_t * qb_map_iter_create(qb_map_t *map)
Create an iterator.
const char * qb_map_iter_next(qb_map_iter_t *i, void **value)
Get the next item.
void qb_map_iter_free(qb_map_iter_t *i)
free the iterator
Deletion of items within the iterator is supported. But note do not free the item memory in the iterator. If you need to free the data items then register for a notifier and free the memory there. This is required as the items are reference counted.
#define QB_MAP_NOTIFY_FREE
Definition: qbmap.h:109
int32_t qb_map_notify_add(qb_map_t *m, const char *key, qb_map_notify_fn fn, int32_t events, void *user_data)
Add a notifier to the map.
- Notifications
- These allow you to get callbacks when values are inserted/removed or replaced.
- Note
- hashtable only supports deletion and replacement notificatins. There is also a special global callback for freeing deleted and replaced values (QB_MAP_NOTIFY_FREE).
- See also
- qb_map_notify_add() qb_map_notify_del_2()
- Prefix matching
- The ptrie supports prefixes in the iterator:
printf("%s > %s\n", p, (char*)data);
}
qb_map_iter_t * qb_map_pref_iter_create(qb_map_t *map, const char *prefix)
Create a prefix iterator.
The ptrie also supports prefixes in notifications: (remember to pass QB_MAP_NOTIFY_RECURSIVE into the notify_add.
NULL);
#define QB_MAP_NOTIFY_RECURSIVE
Definition: qbmap.h:108
#define QB_MAP_NOTIFY_DELETED
Definition: qbmap.h:105
#define QB_MAP_NOTIFY_INSERTED
Definition: qbmap.h:107
#define QB_MAP_NOTIFY_REPLACED
Definition: qbmap.h:106