1 /* $MirOS: contrib/code/jupp/hash.c,v 1.3 2017/01/10 19:16:27 tg Exp $ */
5 * (C) 1992 Joseph H. Allen
7 * This file is part of JOE (Joe's Own Editor)
18 #define hnext(accu, c) (((accu) << 4) + ((accu) >> 28) + (c))
20 static HENTRY *freentry = NULL;
22 unsigned long hash(unsigned char *s)
24 unsigned long accu = 0;
27 accu = hnext(accu, *s++);
34 HASH *t = (HASH *) joe_malloc(sizeof(HASH));
37 t->tab = (HENTRY **) joe_calloc(sizeof(HENTRY *), len);
47 void *htadd(HASH *ht, unsigned char *name, void *val)
49 int idx = hash(name) & ht->len;
54 entry = (HENTRY *) joe_malloc(sizeof(HENTRY) *64);
55 for (x = 0; x != 64; ++x) {
56 entry[x].next = freentry;
61 freentry = entry->next;
62 entry->next = ht->tab[idx];
65 return entry->val = val;
68 void *htfind(HASH *ht, unsigned char *name)
72 for (e = ht->tab[hash(name) & ht->len]; e; e = e->next) {
73 if (!strcmp(e->name, name)) {