parse/htab.c
/* Inserts 'k' into the hash table, possibly
 * killing any previous key that compares
 * as equal. */
Inserts 'k' into the hash table, possibly
killing any previous key that compares
as equal.
Inserts ' k ' into the hash table possibly killing any previous key that compares as equal .
int htput(Htab *ht, void *k, void *v)
{
    int i;
    ulong h;
    int di;
    di = 0;
    h = hash(ht, k);
    i = h & (ht->sz - 1);
    while (ht->hashes[i] && !ht->dead[i]) {
        if (ht->hashes[i] == h) {
            if (ht->dead[i])
                break;
            else if (ht->cmp(ht->keys[i], k))
                goto conflicted;
        }
        di++;
        i = (h + di) & (ht->sz - 1);
    }
    ht->nelt++;
conflicted:
    if (ht->dead[i])
        ht->ndead--;
    ht->hashes[i] = h;
    ht->keys[i] = k;
    ht->vals[i] = v;
    ht->dead[i] = 0;
    if (ht->sz < ht->nelt * 2) 
        grow(ht, ht->sz * 2);
    if (ht->sz < ht->ndead * 4)
        grow(ht, ht->sz);
    return 1;
}
int htput ( Htab * ht , void * k , void * v ) { int i ; ulong h ; int di ; di = 0 ; h = hash ( ht , k ) ; i = h & ( ht -> sz - 1 ) ; while ( ht -> hashes [ i ] && ! ht -> dead [ i ] ) { if ( ht -> hashes [ i ] == h ) { if ( ht -> dead [ i ] ) break ; else if ( ht -> cmp ( ht -> keys [ i ] , k ) ) goto conflicted ; } di ++ ; i = ( h + di ) & ( ht -> sz - 1 ) ; } ht -> nelt ++ ; conflicted : if ( ht -> dead [ i ] ) ht -> ndead -- ; ht -> hashes [ i ] = h ; ht -> keys [ i ] = k ; ht -> vals [ i ] = v ; ht -> dead [ i ] = 0 ; if ( ht -> sz < ht -> nelt * 2 ) grow ( ht , ht -> sz * 2 ) ; if ( ht -> sz < ht -> ndead * 4 ) grow ( ht , ht -> sz ) ; return 1 ; }
Inserts 'k' into the hash table, possibly
 killing any previous key that compares
 as equal.
Inserts ' k ' into the hash table possibly killing any previous key that compares as equal .
/* second insertion overwrites first. nb, we shouldn't touch the
         * keys for dead values */