qse/ase/stx/hash.c

47 lines
864 B
C

/*
* $Id: hash.c,v 1.1 2005-05-08 15:54:44 bacon Exp $
*/
#include <xp/stx/hash.h>
int xp_stx_new_link (
xp_stx_t* stx, xp_stx_word_t key, xp_stx_word_t value)
{
xp_stx_word_t x;
x = xp_stx_alloc_object (3);
XP_STX_CLASS(stx,x) = hash_lookup(stx, XP_STX_TEXT("Link"));
XP_STX_AT(stx,x,0) = key;
XP_STX_AT(stx,x,1) = value;
/* XP_STX_AT(stx,x,2) = stx->nil; */
return x;
}
void xp_stx_hash_insert (
xp_stx_t* stx, xp_stx_word_t key, xp_stx_word_t value)
{
xp_stx_word_t table;
table = XP_STX_AT(stx,stx->globals,0);
hash = __hash(key);
link = XP_STX_AT(stx,table,hash);
for (;;) {
if (XP_STX_AT(stx,link,0) == key) {
XP_STX_AT(stx,link,1) = value;
break;
}
next = XP_STX_AT(stx,link,2);
if (next == stx->nil) {
new = xp_stx_new_link (stx, key, value);
XP_STX_AT(stx,link,2) = new;
break;
}
link = next;
}
}