QBMAP.H(3)
β¨ qbmap.h π
okay so bestie, welcome to qbmap.h β part of the libqb Programmer's Manual, no big deal π
πΈ NAME πΈ
qbmap.h β this is the moment where you get a map interface to a Patricia trie, a hashtable, or a skiplist. pick your fighter, they all serve π«Ά
π SYNOPSIS π
#include <qb/qbmap.h>
π¦ DESCRIPTION π¦
β¨ Ordering β¨
okay so here's the tea β β the hashtable is NOT ordered, but ptrie and skiplist are. so if you need your keys to keep it in order, pick accordingly, bestie π
π Iterating π
below is a lil simple example of how to iterate over a map, and it's giving iconic:
const char *p;
void *data;
qb_map_iter_t *it = qb_map_iter_create(m);
for (p = qb_map_iter_next(it, &data); p; p = qb_map_iter_next(it, &data)) {
printf("%s > %s0, p, (char*) data);
}
qb_map_iter_free(it);
so deletion of items within the iterator is supported. but bestie, listen β do NOT free the item memory in the iterator π¨. if you need to free the data items then you gotta register for a notifier and free the memory <em>there</em>. this is required because the items are reference counted β it's giving main character energy with trust issues, but we move π«Ά
qb_map_notify_add(m, NULL, my_map_free_handler,
QB_MAP_NOTIFY_FREE, NULL);
π« Notifications π«
these lil guys let you get callbacks when values are inserted / removed or replaced. so you're always in the loop, fr fr π²
π§ Prefix matching π§
the ptrie supports prefixes in the iterator, slay:
it = qb_map_pref_iter_create(m, "aa");
while ((p = qb_map_iter_next(it, &data)) != NULL) {
printf("%s > %s0, p, (char*)data);
}
qb_map_iter_free(it);
and the ptrie also supports prefixes in notifications β and remember to pass QB_MAP_NOTIFY_RECURSIVE into the notify_add, iykyk π
qb_map_notify_add(m, "root", my_map_notification,
(QB_MAP_NOTIFY_INSERTED|
QB_MAP_NOTIFY_DELETED|
QB_MAP_NOTIFY_REPLACED|
QB_MAP_NOTIFY_RECURSIVE),
NULL);
π NOTE π
lowkey important β the hashtable only supports deletion and replacement notifications. there's also a special global callback for freeing deleted and replaced values (QB_MAP_NOTIFY_FREE). so like, keep that in your notes app π
π SEE ALSO π
qb_trie_dump(3)qb_map_iter_create(3)qb_skiplist_create(3)qb_map_notify_del(3)qb_map_put(3)qb_map_count_get(3)qb_map_foreach(3)qb_map_pref_iter_create(3)qb_map_iter_next(3)qb_map_get(3)qb_map_destroy(3)qb_hashtable_create(3)qb_map_iter_free(3)qb_map_notify_add(3)qb_trie_create(3)qb_map_notify_del_2(3)qb_map_rm(3)
π COPYRIGHT π
Copyright (C) 2010-2020 Red Hat, Inc. β periodt, respect the legacy π«‘
and that's the whole page bestie!! this one's from LIBQB, dated 2025-09-16, and it's QBMAP.H(3) in the libqb programmer's manual. go forth and map your lil hearts out, ily bye π
β¨π
π¦ where this page comes from
- fedora 44: libqb-devel 2.0.9-2.fc44 Β· LGPL-2.1-or-later
- fedora 44: libqb-devel 2.0.9-2.fc44 Β· LGPL-2.1-or-later
- ubuntu resolute: libqb-dev 2.0.9-1ubuntu1 Β· LGPL-2.1-or-later
- ubuntu stonking: libqb-dev 2.0.9-1ubuntu1 Β· LGPL-2.1-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms