Hash functions

This is a moderated forum that collects tutorials, guides, and references for creating Transcendence extensions and scripts.
Post Reply
User avatar
alterecco
Fleet Officer
Fleet Officer
Posts: 1658
Joined: Wed Jan 14, 2009 3:08 am
Location: Previously enslaved by the Iocrym

Being in need of some datastructures i cooked up some hash functions.

The hash is built on a list where every even element is a key and the following odd element is its value.

Please comment if you can see problems or ways of bettering the functions.

-- Edit:
The functions are now on Xelerus here


They are very simple to use.
Take an empty list, and begin adding, finding and removing items.
The only requirement is that keys remain unique.

Code: Select all

(setq hash (list))
(hshSet hash 'key1 'value)
(hshSet hash 'key2 'somevar)
(hshSet hash 'somevar '(a b c d e))
(hshGet hash 'key1) -> "value"
(hshGet hash 'somevar) -> (a b c d e)
(hshSet hash 'somevar 'override)
(dbgOutput hash) -> (key1 value key2 somevar somevar override)
(hshRemove hash 'key2) -> somevar
(dbgOutput hash) -> (key1 value somevar override)

;; merge two hashes
(setq hash2 '(test testvar key1 merge))
(hshMerge hash hash2) -> (key1 merge somevar override test testvar)
Enjoy.
User avatar
alterecco
Fleet Officer
Fleet Officer
Posts: 1658
Joined: Wed Jan 14, 2009 3:08 am
Location: Previously enslaved by the Iocrym

So, these have been written and rewritten several times over the last year or so. I finally reached an implementation that I am confident is fast, stable and simple and provides the required functionality

Here is the code in a pastebin plus some description.

I will not be updating the original Hash Functions on xelerus as these functions are now part of DSF itself, used internally.

If you want to make use of them in your own mod, then copy them over and modify the function names (so you won't clash with DSF)
Post Reply