critbit0_allprefixed(3)
β¨ 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
handlereturns0, the search stops andcritbit0_allprefixedreturns0. - if
handlereturns1, the search continues, andcritbit0_allprefixedreturns1if all keys with the given prefix were handled. - if
handlereturns something else β anything that isn't0or1β the search stops andcritbit0_allprefixedreturns-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,handlewas called and returned0.-1β if at least one key was found,handlewas called and returned something other than0or1.
π 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 ππ¦π
π¦ where this page comes from
- alpine 3.24: libowfat-doc 0.34-r0 Β· GPL-2.0-only
- debian bookworm: libowfat-dev 0.32-4 Β· GPL-2.0-only
- debian trixie: libowfat-dev 0.32-5 Β· GPL-2.0-only
- nixos 26.05: libowfat 0.34
- nixpkgs unstable: libowfat 0.34
- opensuse-leap 16.0: libowfat-devel 0.33-bp160.1.11 Β· GPL-2.0-only
- opensuse-leap 16.0: libowfat-devel 0.33-bp160.1.11 Β· GPL-2.0-only
- opensuse-leap 16.0: libowfat-devel 0.33-bp160.1.11 Β· GPL-2.0-only
- opensuse-leap 16.0: libowfat-devel 0.33-bp160.1.11 Β· GPL-2.0-only
- ubuntu noble: libowfat-dev 0.32-4.1build1 Β· GPL-2.0-only
- ubuntu questing: libowfat-dev 0.32-5
- ubuntu resolute: libowfat-dev 0.34-2 Β· GPL-2.0-only
- ubuntu stonking: libowfat-dev 0.34-2 Β· GPL-2.0-only
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms