dbh_sweep(3)

πŸ“¦ version 5.0.22, in fedora 43, fedora 44

🌈 dbh_sweep(3) β€” the DBHashTables Programmers' Manual, bestie edition πŸ’…

okay so this is a page from the DBHashTables Programmers' Manual, and it's about a whole lil squad of functions: dbh_sweep, dbh_fanout, dbh_foreach_sweep, dbh_foreach_fanout, dbh_exit_sweep and dbh_exit_fanout. they all do the same iconic thing β€” apply a function to all or part of the DBHashtable. let's get into it πŸ¦‹


✨ NAME ✨

dbh_sweep, dbh_fanout, dbh_foreach_sweep, dbh_foreach_fanout, dbh_exit_sweep, dbh_exit_fanout β€” apply a function to all or part of the DBHashtable πŸ‘‘


πŸŽ€ SYNOPSIS πŸŽ€

#include <dbh.h>

int dbh_foreach_sweep (DBHashTable *dbh, DBHashFunc operate);
int dbh_foreach_fanout (DBHashTable *dbh, DBHashFunc operate);
int dbh_sweep (DBHashTable *dbh, DBHashFunc operate, unsigned char
*key1, unsigned char *key2, unsigned char ignore_portion);
int dbh_fanout (DBHashTable *dbh, DBHashFunc operate, unsigned char
*key1, unsigned char *key2, unsigned char ignore_portion);
void dbh_exit_sweep (DBHashTable *dbh);
void dbh_exit_fanout (DBHashTable *dbh);

πŸ’– DESCRIPTION πŸ’–

so dbh_foreach_sweep applies the function operate to each member of the hash, following a sweep trajectory. and what is a sweep trajectory, you ask? it's traversing the DBHashTable in a vertical direction through all the branches. vertical. going down. slay. 🌸

dbh_foreach_fanout applies a function operate to each member of the hash too, but following a fanout trajectory. fanout is traversing the DBHashTable in a horizontal direction through all the records. so like, sideways. different vibe, same energy. ✨

dbh_sweep and dbh_fanout apply a function to subtree members of the hash β€” so not the whole thing, just a piece of it. dbh_sweep follows a sweep trajectory (vertically through branches) and dbh_fanout follows a fanout trajectory (horizontally through branches). iykyk πŸ’…

okay now the arguments, because this is the part where you actually have to pay attention bestie:

  • key1 β€” the key from which to start the sweep, or NULL if you don't care and want to start at the top. 🫢 but if you do decide to define key1, make sure it is a top level node of a subtree. this is done with dbh_find.
  • key2 β€” the key which will trigger an exit condition, or NULL if you don't care and want to continue until the end of the DBHashTable.
  • ignore_portion β€” lets you define the ignored trailing bytes of key1, which will define the size of the subtree to be sweeped, or zero if you don't care and want to process all branches.

and in all of these functions, operate β€” which is void (*operate) (DBHashTable *dbh) β€” is the function to apply to each selected member of the DBHashTable. yes, a function pointer. yes, you're a real programmer now. πŸ‘‘

dbh_exit_sweep and dbh_exit_fanout, when called within the operate function, will cause the exit of a currently running sweep or fanout. it's the "okay we're done here" button. 😭


⭐ RETURN VALUE ⭐

0 on error, 1 otherwise.

that's it. that's the whole thing. binary. iconic. πŸŽ€


πŸ’œ NOTES πŸ’œ

listen. listen. in order for sweep/fanout functions to be extremely fast, you should prepare the DBHashTable for the trajectory you intend to use with dbh_regen_sweep or dbh_regen_fanout first. do this and you get extremely efficient use of hardware and operating system caches. that's the whole point. no cap. πŸ”₯

bestie the performance difference is real, do the regen first, your caches will thank you 🫢

🌈 SEE ALSO 🌈

  • dbh (0)
  • dbh_regen_sweep (3)
  • dbh_regen_fanout (3)
  • dbh_find (3)
  • dbh_settempdir (3)

🌸 Author 🌸

Edscott Wilson Garcia <edscott@xfce.org>


and that's the tea, bestie πŸ“ this page is from the DBHashTables manual, DBH section, page dbh_sweep(3) β€” go forth and sweep, and remember: vertical for sweep, horizontal for fanout, and always regen first. mwah πŸ’–πŸ§šβœ¨

πŸ“¦ where this page comes from