UHashTable(3U)
π UHashTable β hash table classes (from the InterViews Reference Manual, section 3U) π
okay bestie, sit down, hydrate, because today we're learning about UHashTable and UHashElem β two lil classes from <Unidraw/uhash.h> that are literally the backbone of storing stuff by key around here. no cap. π¦
β¨ SYNOPSIS β¨
#include <Unidraw/uhash.h>
πΈ DESCRIPTION πΈ
So UHashTable implements a simple open hash table. iconic behavior honestly. π
The number of slots is your call β you specify it when the table gets created. slay, customisation.
UHashTable stores UHashElem instances, and those little guys contain the key that gets hashed. so the key lives inside the element, got it?
Now here's the cute part: if you're writing code that uses UHashTables, you can derive from UHashElem to store extra data alongside the key. yes bestie, your own custom data. main character energy. π
UHashTable also gives you operations for iterating over the elements in the hash table, so you're never stuck staring at it from the outside. π«Ά
π UHASHELEM OPERATIONS π
UHashElem(void* = nil)β creates aUHashElemwith the given key value. that's it, that's the constructor. πvoid* GetKey()/void SetKey(void*)β explicitly get and set the element's key value. no mystery, no drama, just getters and setters doing their thing. β¨
π UHASHTABLE PUBLIC OPERATIONS π
UHashTable(int nslots)β creates a brand newUHashTable, and you tell it how many slots it's got. pick wisely bestie, that's the whole vibe. πvirtual void Register(void* key, UHashElem* = nil)β makes an entry into the hash table. π₯ and here's the tea: if you don't hand it aUHashElem, this function calls theCreateElemfunction (described down below, keep scrolling) to make one for you, and then it callsSetKeyon the result withkeyas the argument. it's giving "we got you covered". πvirtual void Unregister(void* key)β removes the element with the matching key from the hash table and deletes it. gone. deleted. not just uninvited from the party, like, fully removed from existence. πvoid First(Iterator&)void Next(Iterator&)boolean Done(Iterator)UHashElem* GetElem(Iterator)
these four are your iteration squad β the operations for iterating over the elements in the hash table. β
heads up: these operations do not guarantee a particular ordering for the iteration. so don't come for me when your elements show up in a different order than you imagined. it's giving chaos, but it's documented chaos. π
Firstinitializes an iterator to point to the first element in the traversal. π₯Nextincrements the iterator to point to the following element. β‘οΈDonereturns whether or not the iterator points beyond the last element in the traversal. πGetElemreturns the element that the given iterator is pointing at. π
UHashElem* Find(void* key)β finds the element with the matching key in the hash table. and what counts as "matching"? that's defined by theEqualoperation, described below. iykyk. π
π§ UHASHTABLE PROTECTED OPERATIONS π§
these are the ones your subclasses get to play with. protected, not private β so yes, you're invited, but only if you're inheriting. π
virtual UHashElem* CreateElem()β returns a newUHashEleminstance. π and listen: subclasses ofUHashTableshould redefine this function if they use subclasses ofUHashElem. that's not a suggestion, that's the whole point of it existing. periodt.virtual int Hash(void* key)β hashes the specified key to return a slot index. π important caveat: this value should be less than the value of the_nslotsmember variable. don't go past the slots bestie, that's not the vibe.virtual boolean Equal(void* key1, void* key2)β returns whether the specified keys are equivalent. π° by default,Equalsimply compares the pointers for equality. but subclasses may redefine this operation to make more sophisticated comparisons β so if pointer equality isn't cutting it for you, that's your moment to shine. π
π SEE ALSO π
Iterator(3U)
okay that's the whole page, you ate that. π before you go: this little beauty comes from the Unidraw distribution, dated 3 October 1990, and it's page UHashTable(3U) in the manual. mwah. πβ¨π
π¦ where this page comes from
- debian bookworm: ivtools-dev 2.0.11d.a1-1+b4
- debian trixie: ivtools-dev 2.0.11d.a1-3+b4
- ubuntu jammy: ivtools-dev 2.0.11d.a1-1build1
- ubuntu noble: ivtools-dev 2.0.11d.a1-3build1
- ubuntu questing: ivtools-dev 2.0.11d.a1-3build7
- ubuntu resolute: ivtools-dev 2.0.11d.a1-3build9
- ubuntu stonking: ivtools-dev 2.1.1+git.2025.07.26.a1-1 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms