libcritnib(3)

πŸ“¦
version 1.1 Β· 5 versions
, in ubuntu noble, ubuntu questing

πŸ’– libcritnib β€” an ordered map data structure with lock-free reads πŸ’–

okay bestie, sit DOWN, because this is the critnib manual page and she is lowkey iconic. it's libcritnib, a library for an ordered map data structure, and the whole vibe is that reads are lock-free β€” readers don't gotta wait on anybody. periodt. πŸ¦‹


✨ NAME ✨

libcritnib β€” an ordered map data structure with lock-free reads. that's the whole name, that's the whole assignment, and she ate. πŸ’…


🌸 SYNOPSIS 🌸

#include <critnib.h>

and then, like, link her in:

-lcritnib

no cap, that's it. link with -lcritnib and you're in. 🫢


πŸ‘‘ DESCRIPTION πŸ‘‘

πŸŽ€ Functions:

okay so here's the whole friend group, one by one, no skips, no cuts. πŸ’œ

  • critnib *critnib_new(void); β€” makes you a brand new, empty critnib structure. fresh out the box, zero keys, main character energy. ✨
  • void critnib_delete(critnib *c); β€” destroys her and frees the memory. and listen, important detail: items you removed earlier get reused, but their memory does not get freed until you call this function. so like, the removals were never really gone gone, they were just in the group chat but muted. call this and it's actually over. 😭
  • int critnib_insert(critnib *c, uintptr_t key, void *value, int update); β€” adds a key:value pair to the critnib structure. here's the tea on update: if it's non-zero, a key that already exists gets its value updated (glow up ✨). if it's zero, the function returns EEXIST instead. it may also return ENOMEM if we're out of memory, or 0 if everything went okay. slay.
  • void *critnib_remove(critnib *c, uintptr_t key); β€” yeets a given key out of the structure. you get its associated value back as a parting gift, or 0 (NULL) if there was no such key. sorry bestie, no key, no souvenir. πŸ’€
  • void *critnib_get(critnib *c, uintptr_t key); β€” grabs you a value for a given key, or 0 (NULL) if it's not present. simple, clean, no drama.
  • void *critnib_find_le(critnib *c, uintptr_t key); β€” searches for the largest key not exceeding the argument and hands you its value. like finding the closest thing that didn't overstep. 🧚
  • int critnib_find(critnib *c, uintptr_t key, enum find_dir_t dir, uintptr_t *rkey, void **rvalue); β€” searches for a key that's smaller (FIND_L), smaller-or-equal (FIND_LE), equal (FIND_EQ), greater-or-equal (FIND_GE), or greater (FIND_G) than the argument. if found, the key and value get assigned to *rkey and *rvalue (and yes, those may be null if you wanna skip the assignment, we respect boundaries), and 1 is returned. πŸ’…
  • void critnib_iter(critnib *c, uintptr_t min, uintptr_t max, func, void *privdata); β€” walks the structure, visiting all entries whose keys are at least min but no larger than max (give -1 for no max, live a little). she calls func for every entry she finds. and if func returns a non-zero value, the walk is aborted β€” that's the emergency exit, bestie. πŸšͺ

the prototype for func should be:

int (*func)(uintptr_t key, void *value, void *privdata);

where privdata is an optional value passed to the iterator.

⚠️ NB. this version of the library implements the iterator in a crude blocking way, stalling any concurrent writers and iterators. it's giving "held the door open for way too long." 😭 this limitation will be lifted in the future, so like, patience is a virtue or whatever. πŸ•°οΈ

that's the whole page, bestie β€” go forth and map your keys in order, lock-free, no cap. πŸŒˆπŸ’–

🌸 this page came to you from the libcritnib manual, rendered by perl v5.38.2, dated 2024-04-22. mwah, kissing you goodbye. πŸŽ€πŸ’œ

πŸ“¦ where this page comes from