critbit0_allprefixed(3)

πŸ“¦
version 0.34 Β· 2 versions
  • 0.34 Β· alpine 3.24, debian bookworm, debian trixie, nixos 26.05, nixpkgs unstable, opensuse-leap 16.0, ubuntu noble, ubuntu questing, ubuntu resolute, ubuntu stonking (latest)
  • 0.30 Β· fedora 43, fedora 44, ubuntu jammy
, in alpine 3.24, debian bookworm, debian trixie, nixos 26.05, nixpkgs unstable, opensuse-leap 16.0, ubuntu noble, ubuntu questing, ubuntu resolute, ubuntu stonking

✨ critbit0_allprefixed ✨

okay bestie so you found your way to critbit0_allprefixed(3) from the Library Functions Manual and honestly? you're about to eat. this is the "gimme everything that starts with this" function for your critbit tree. let's get into it πŸ’…


🌸 NAME 🌸

critbit0_allprefixed β€” search a critbit tree by prefix πŸ”πŸŒ³


πŸŽ€ SYNTAX πŸŽ€

like all good things, it starts with an include. no cap:

#include <libowfat/critbit.h>

critbit0_tree cb = { 0 };

int critbit0_allprefixed(critbit0_tree* cb,const char* prefix,
    int (*handle)(const char*,void*),void* arg);

yes bestie, you gotta zero-init your tree with critbit0_tree cb = { 0 }; before anything happens. it's giving responsible.


πŸ’– DESCRIPTION πŸ’–

so here's the vibe: critbit0_allprefixed calls the handle function on all members of cb that start with prefix. every single one that matches. and it passes arg as the second argument to handle, so you can smuggle whatever you want in there. iconic behavior honestly 🫢

now the way handle answers back is the whole plot twist, so pay attention:

  • if handle returns 0, the search stops and critbit0_allprefixed returns 0.
  • if handle returns 1, the search continues, and critbit0_allprefixed returns 1 if all keys with the given prefix were handled.
  • if handle returns something else β€” anything that isn't 0 or 1 β€” the search stops and critbit0_allprefixed returns -1.

so like, 1 means "keep going queen", 0 means "okay stop but I'm fine", and literally anything else means "STOP I'm unwell" πŸ˜­πŸ’€


πŸ¦‹ NOTE πŸ¦‹

heads up bestie: this function uses recursion to traverse the tree. it may require nontrivial amounts of available stack space. so if your tree is deep-deep, be mindful. the stack is not infinite and neither is my patience for stack overflows πŸ™ˆ

⭐ RETURN VALUE ⭐

  • 1 β€” if all keys were found and handled (or if there were no keys with that prefix). like, nothing to do is still a win ✨
  • 0 β€” if at least one key was found, handle was called and returned 0.
  • -1 β€” if at least one key was found, handle was called and returned something other than 0 or 1.

πŸ’œ SEE ALSO πŸ’œ

  • critbit0_contains(3) β€” the "is this one specific key in here" bestie to this "gimme the whole squad" bestie. they're a duo fr fr.

and that's the whole page bestie, go forth and prefix-search slay πŸ’…βœ¨

anyway, this was critbit0_allprefixed(3) from the Library Functions Manual, closing out the page like it opened it. stay recursive, stay hydrated, and may your stack always have room πŸŽ€πŸ¦‹πŸ’–