critbit0_insert(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_insert β€” ok bestie, let's talk about putting strings in trees πŸ’–

So this page is the manual for critbit0_insert(3), and it lives in the Library Functions Manual. Yes, the third section. Very demure, very C library of it. πŸŽ€


✨ NAME ✨

critbit0_insert β€” insert a string into a critbit tree 🌳


🌸 SYNTAX 🌸

Okay so first you gotta pull in the header, like:

#include <libowfat/critbit.h>

Then you declare your tree and zero it out, no cap:

critbit0_tree cb = { 0 };

And here's the function itself, the main character:

int critbit0_insert(critbit0_tree* cb,const char* str);

πŸ¦‹ DESCRIPTION πŸ¦‹

critbit0_insert attempts to insert a string into a critbit0 tree. 🫢

And here's the thing you gotta know, bestie, because the way this works is iconic: it does not just stash a copy of the pointer. Nope. It makes a copy of the whole entire string. Like, the full thing. Every character. She's thorough. πŸ’…

Then the vibes check out like this:

  • If str is already in cb, critbit0_insert returns 1.
  • If str is not in cb, it gets inserted, and critbit0_insert returns 2.
  • If there's a memory allocation failure on the way 😭, critbit0_insert leaves cb completely alone β€” like, doesn't touch it, doesn't look at it, nothing β€” and returns 0.
⚠️ Note that cb is only left untouched in the allocation-failure case. That's the one where she just walks away. πŸ™ˆ

⭐ RETURN VALUE ⭐

Three possible moods, and she's serving exactly one of them:

  • 2 β€” the key was inserted (slay ✨)
  • 1 β€” it was already in cb
  • 0 β€” memory allocation failure πŸ’€

🌈 SEE ALSO 🌈

  • critbit0_contains(3) β€” for when you wanna check if the thing is in there without adding it, iykyk πŸ”₯

Okay that's literally the whole page, you ate that. This little legend came out under the name critbit0_insert(3), filed under the Library Functions Manual β€” so if you see critbit0_insert(3) floating around, that's just her, the same girl, same page. πŸ’– Go forth and insert responsibly, bestie. 🧚✨