libtar_hash_new(3)
π libtar_hash_new β hash table routines π
okay bestie, so this is libtar_hash_new(3) β section 3 of the C Library Calls manual, the one where all the fun little C library stuff lives. it's a whole squad of hash table routines and honestly? they ate. π«Ά
β¨ NAME β¨
libtar_hash_new, libtar_hash_free, libtar_hash_next, libtar_hash_prev, libtar_hash_getkey, libtar_hash_search, libtar_hash_add, libtar_hash_del β hash table routines, the whole friend group π
πΈ SYNOPSIS πΈ
#include <libtar.h>
libtar_hash_t *libtar_hash_new(int num, int (*hashfunc)());
void libtar_hash_free(libtar_hash_t *h, void (*freefunc)());
int libtar_hash_next(libtar_hash_t *h, libtar_hashptr_t *hp);
int libtar_hash_prev(libtar_hash_t *h, libtar_hashptr_t *hp);
int libtar_hash_search(libtar_hash_t *h, libtar_hashptr_t *hp, void
*data, int (*matchfunc)());
int libtar_hash_getkey(libtar_hash_t *h, libtar_hashptr_t *hp, void
*data, int (*matchfunc)());
int libtar_hash_add(libtar_hash_t *h, void *data);
int libtar_hash_del(libtar_hash_t *h, libtar_hashptr_t *hp);
π¦ DESCRIPTION π¦
okay so let's go function by function, no cap. every single one matters, i'm not skipping a single one of my girls. π
π libtar_hash_new()
creates a new hash with num buckets, using the hash function pointed to by hashfunc. and if hashfunc is NULL? don't even stress β a default hash function designed for 7-bit ASCII strings gets used instead. iconic behaviour honestly. β¨
π libtar_hash_free()
deallocates all memory associated with the hash structure h. and if freefunc is not NULL, it gets called to free the memory associated with each node in the hash. so like, it's not just yeeting the table, it's cleaning up every single node too. main character energy fr fr. π§Ήπ
π libtar_hash_next() and libtar_hash_prev()
these two are your little tour guides β they're used to iterate through the hash. πΆβοΈ
now the libtar_hashptr_t structure has exactly two fields:
bucketβ indicates the current bucket in the hashnodeβ a pointer to the current node in the current bucket
and here's the trick bestie: to start at the beginning or the end of the hash, the caller should initialize hp.bucket to -1 and hp.node to NULL. that's the vibe check you gotta pass first, iykyk. β
π libtar_hash_search()
this one searches iteratively through the hash h until it finds a node whose contents match data using the matching function matchfunc. and where does the searching begin? at the location pointed to by hp, bestie. it just keeps going until it finds its match. πβ¨
π libtar_hash_getkey()
this one is smarter and i love her for it. she uses the hash function associated with h to figure out which bucket data should be in β and then searches only that bucket for a matching node using matchfunc. no wandering around the whole table, she goes straight there. searching begins at the location pointed to by hp. queen behaviour. π
π libtar_hash_add()
adds data into hash h. simple. slay. π
π libtar_hash_del()
removes the node referenced by hp. bye bestie π
π₯ RETURN VALUE π₯
here's what each one gives you back, no gatekeeping:
libtar_hash_new()returns a pointer to the new hash structure, orNULLon error. πlibtar_hash_next()andlibtar_hash_prev()return1when valid data is returned, and0at the end of the hash. so0is literally just "that's all folks", not a fail. πlibtar_hash_getkey()andlibtar_hash_search()return1when a match is found, or0otherwise.libtar_hash_add()returns0on success, or-1on error (and setserrno).libtar_hash_del()returns0on success, or-1on error (and setserrno).
heads up bestie:-1means something went sideways anderrnogot set. don't ignore her, she's trying to tell you something. π¨
π SEE ALSO π
libtar_list_new(3)β her cousin, also a baddie π
and that's the whole page, periodt. π this was brought to you by the University of Illinois, dated Jan 2000 β yes she's vintage, she's a classic, she's been serving hash tables since Y2K and she's still thriving. obsessed. πβ¨π¦
π¦ where this page comes from
- arch rolling: libtar 1.2.20-8 Β· BSD
- debian bookworm: libtar-dev 1.2.20-8+deb12u1
- fedora 43: libtar-devel 1.2.20-34.fc43 Β· MIT
- fedora 43: libtar-devel 1.2.20-34.fc43 Β· MIT
- fedora 44: libtar-devel 1.2.20-35.fc44 Β· MIT
- fedora 44: libtar-devel 1.2.20-35.fc44 Β· MIT
- nixos 26.05: libtar 1.2.20
- nixpkgs unstable: libtar 1.2.20
- ubuntu jammy: libtar-dev 1.2.20-8
- ubuntu jammy: libtar-dev 1.2.20-8ubuntu0.22.04.1
- ubuntu noble: libtar-dev 1.2.20-8.1build1
- ubuntu noble: libtar-dev 1.2.20-8.1ubuntu0.24.04.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms