13 * char * set_entry(int namespace, char * name, void * value);
14 * returns a pointer to the copy of the name;
16 * void * read_entry(int namespace, char * name);
22 struct hashentry
* next
;
28 struct hashentry
** hashtable
;
29 int hashsize
= 0xFF; /* 2^X -1 */
31 static int hashvalue
P((int namespace, char * word
));
34 read_entry(namespace, word
)
39 struct hashentry
* hashline
;
40 if( hashtable
== 0 ) return 0;
41 hash_val
= hashvalue(namespace, word
);
43 hashline
= hashtable
[hash_val
];
45 for(; hashline
; hashline
= hashline
->next
)
47 if(namespace != hashline
->namespace) continue;
48 if(word
[0] != hashline
->word
[0]) continue;
49 if(strcmp(word
, hashline
->word
) ) continue;
50 return hashline
->value
;
56 set_entry(namespace, word
, value
)
62 struct hashentry
* hashline
, *prev
;
63 hash_val
= hashvalue(namespace, word
);
67 hashline
= hashtable
[hash_val
];
69 for(prev
=0; hashline
; prev
=hashline
, hashline
= hashline
->next
)
71 if(namespace != hashline
->namespace) continue;
72 if(word
[0] != hashline
->word
[0]) continue;
73 if(strcmp(word
, hashline
->word
) ) continue;
74 if( value
) hashline
->value
= value
;
77 if( prev
== 0 ) hashtable
[hash_val
] = hashline
->next
;
78 else prev
->next
= hashline
->next
;
82 return hashline
->word
;
85 if( value
== 0 ) return 0;
88 hashtable
= malloc((hashsize
+1)*sizeof(char*));
89 if( hashtable
== 0 ) cfatal("Out of memory");
90 for(i
=0; i
<=hashsize
; i
++) hashtable
[i
] = 0;
93 hashline
= malloc(sizeof(struct hashentry
)+strlen(word
));
94 if( hashline
== 0 ) cfatal("Out of memory");
97 hashline
->next
= hashtable
[hash_val
];
98 hashline
->namespace = namespace;
99 hashline
->value
= value
;
100 strcpy(hashline
->word
, word
);
101 hashtable
[hash_val
] = hashline
;
103 return hashline
->word
;
106 static int hashvalue(namespace, word
)
115 val
= ((val
<<4)^((val
>>12)&0xF)^((*p
++)&0xFF));