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 πŸ’œ


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