- if(IS_HASH(hash)) {
- struct HashNode* n = find(PTR(hash).hash, key);
- if(n) n->val = val;
- return n != 0;
- }
- return 0;
-}
-
-// Special purpose optimization for use in function call setups. Sets
-// a value that is known *not* to be present in the hash table. As
-// for naHash_sym, the key must be a string with a precomputed hash
-// code.
-void naHash_newsym(struct naHash* hash, naRef* sym, naRef* val)
-{
- int col;
- struct HashRec* h = hash->rec;
- while(!h || h->size >= 1<<h->lgalloced)
- h = resize(hash);
- col = (HASH_MAGIC * PTR(*sym).str->hashcode) >> (32 - h->lgalloced);
- INSERT(h, *sym, *val, col);
-}
-
-// The cycle check is an integrity requirement for multithreading,
-// where raced inserts can potentially cause cycles. This ensures
-// that the "last" thread to hold a reference to an inserted node
-// breaks any cycles that might have happened (at the expense of
-// potentially dropping items out of the hash). Under normal
-// circumstances, chains will be very short and this will be fast.
-static void chkcycle(struct HashNode* node, int count)
-{
- struct HashNode* hn = node;
- while(hn && (hn = hn->next) != 0)
- if(count-- <= 0) { node->next = 0; return; }
-}
-
-void naHash_set(naRef hash, naRef key, naRef val)
-{
- int col;
- struct HashRec* h;
- struct HashNode* n;
- if(!IS_HASH(hash)) return;
- if((n = find(PTR(hash).hash, key))) { n->val = val; return; }
- h = PTR(hash).hash->rec;
- while(!h || h->size >= 1<<h->lgalloced)
- h = resize(PTR(hash).hash);
- col = hashcolumn(h, key);
- INSERT(h, key, val, hashcolumn(h, key));
- chkcycle(h->table[col], h->size - h->dels);