ici::doc::pod3::sdrhash(3)
π sdrhash β the ICI library functions page, but make it make sense π
okay bestie, pull up a chair, we're talking about sdrhash from the ICI library functions. it's a (3) manpage, it's all about hash tables in an SDR, and honestly? it's giving organized. let's go π¦
β¨ NAME β¨
sdrhash β Simple Data Recorder hash table management functions π
β¨ SYNOPSIS β¨
#include "sdr.h"
Object sdr_hash_create (Sdr sdr, int keyLength,
int estNbrOfEntries,
int meanSearchLength);
int sdr_hash_insert (Sdr sdr, Object hash, char *key,
Address value, Object *entry);
int sdr_hash_delete_entry (Sdr sdr, Object entry);
int sdr_hash_entry_value (Sdr sdr, Object hash, Object entry);
int sdr_hash_retrieve (Sdr sdr, Object hash, char *key,
Address *value, Object *entry);
int sdr_hash_count (Sdr sdr, Object hash);
int sdr_hash_revise (Sdr sdr, Object hash, char *key,
Address value);
int sdr_hash_remove (Sdr sdr, Object hash, char *key,
Address *value);
int sdr_hash_destroy (Sdr sdr, Object hash);
like yes, that's nine functions, we're gonna get to all of them, don't scroll π
β¨ DESCRIPTION β¨
so the SDR hash functions manage hash table objects in an SDR. that's the whole vibe. hash table objects, inside an SDR. π«Ά
hash tables associate values with keys. a value is always in the form of an SDR Address β nominally the address of some stored object identified by the associated key, but fr fr the actual significance of a value may be anything that fits into a long. a key is always an array of from 1 to 255 bytes, which may have any semantics at all. anything. no notes. π
keys must be unique. no two distinct entries in an SDR hash table may have the same key. any attempt to insert a duplicate entry in an SDR hash table will be rejected. the table said no π
all keys must be of the same length, and that length must be declared at the time the hash table is created. and listen β invoking a hash table function with a key that is shorter than the declared length will have unpredictable results. unpredictable!! we don't do that. π
β οΈ bestie warning: short key = unpredictable results. that's not a vibe, that's a bug you wrote yourself.
an SDR hash table is an array of linked lists. the location of a given value in the hash table is automatically determined by:
- computing a "hash" of the key
- dividing the hash by the number of linked lists in the array
- using the remainder as an index to the corresponding linked list
- then sequentially searching through the list entries until the entry with the matching key is found
the way that's literally just a hash table. iconic algorithm behavior π
the number of linked lists in the array is automatically computed at the time the hash table is created, based on the estimated maximum number of entries you expect to store in the table and the mean linked list length (i.e., mean search time) you prefer. increasing the maximum number of entries in the table and decreasing the mean linked list length both tend to increase the amount of SDR heap space occupied by the hash table. so like, more entries + shorter lists = more heap. tradeoff queen πΈ
π the functions π
Object sdr_hash_create(Sdr sdr, int keyLength, int estNbrOfEntries, int meanSearchLength)β creates an SDR hash table. returns the SDR address of the new hash table on success, zero on any error. β¨int sdr_hash_insert(Sdr sdr, Object hash, char *key, Address value, Object *entry)β inserts an entry into the hash table identified byhash. on success, places the address of the new hash table entry inentryand returns zero. returns-1on any error. πint sdr_hash_delete_entry(Sdr sdr, Object entry)β deletes the hash table entry identified byentry. returns zero on success,-1on any error. bye bye entry πAddress sdr_hash_entry_value(Sdr sdr, Object hash, Object entry)β returns the value of the hash table entry identified byentry. πint sdr_hash_retrieve(Sdr sdr, Object hash, char *key, Address *value, Object *entry)β searches for the value associated withkeyin this hash table, storing it invalueif found. if the entry matchingkeywas found, places the address of the hash table entry inentryand returns1. returns zero if no such entry exists,-1on any other failure. found it bestie π₯int sdr_hash_count(Sdr sdr, Object hash)β returns the number of entries in the hash table identified byhash. math! π§int sdr_hash_revise(Sdr sdr, Object hash, char *key, Address value)β searches for the hash table entry matchingkeyin this hash table, replacing the associated value withvalueif found. returns1if the entry matchingkeywas found, zero if no such entry exists,-1on any other failure. glow up that value πint sdr_hash_remove(Sdr sdr, Object hash, char *key, Address *value)β searches for the hash table entry matchingkeyin this hash table; if the entry is found, stores its value invalue, deletes the entry, and returns1. returns zero if no such entry exists,-1on any other failure. gone, reduced to atoms πvoid sdr_hash_destroy(Sdr sdr, Object hash);β destroyshash, destroying all entries in all linked lists of the array and destroying the hash table array structure itself. π§¨
π¨ DO NOT use sdr_free() to destroy a hash table, as this would leave the hash table's content allocated yet unreferenced. do not do it. i am begging. that's a memory leak with main character energy and we are NOT casting it. π
β¨ SEE ALSO β¨
and that's the page!! this one is from perl v5.24.1, dated 2016-07-07, under the ici::doc::pod3::sdrhash(3) header β so yeah, vintage, but the hash tables still ate. go build something, bestie ππ¦β¨
π¦ where this page comes from
- ubuntu jammy: ion-doc 3.2.1+dfsg-1.1 Β· BSD-3-Clause
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms