rts/Hash.c
/* -----------------------------------------------------------------------------
 * Expand the larger hash table by one bucket, and split one bucket
 * from the smaller table into two parts.  Only the bucket referenced
 * by @table->split@ is affected by the expansion.
 * -------------------------------------------------------------------------- */
Expand the larger hash table by one bucket, and split one bucket
from the smaller table into two parts.  Only the bucket referenced
by @table->split@ is affected by the expansion.
Expand the larger hash table by one bucket and split one bucket from the smaller table into two parts . Only the bucket referenced by @table - > split@ is affected by the expansion .
static void
expand(HashTable *table)
{
    int oldsegment;
    int oldindex;
    int newbucket;
    int newsegment;
    int newindex;
    HashList *hl;
    HashList *next;
    HashList *old, *new;
    if (table->split + table->max >= HDIRSIZE * HSEGSIZE)
        return;
    oldsegment = table->split / HSEGSIZE;
    oldindex = table->split % HSEGSIZE;
    newbucket = table->max + table->split;
    newsegment = newbucket / HSEGSIZE;
    newindex = newbucket % HSEGSIZE;
    if (newindex == 0)
        allocSegment(table, newsegment);
    if (++table->split == table->max) {
        table->split = 0;
        table->max *= 2;
        table->mask1 = table->mask2;
        table->mask2 = table->mask2 << 1 | 1;
    }
    table->bcount++;
    old = new = NULL;
    for (hl = table->dir[oldsegment][oldindex]; hl != NULL; hl = next) {
        next = hl->next;
        if (table->hash(table, hl->key) == newbucket) {
            hl->next = new;
            new = hl;
        } else {
            hl->next = old;
            old = hl;
        }
    }
    table->dir[oldsegment][oldindex] = old;
    table->dir[newsegment][newindex] = new;
    return;
}
static void expand ( HashTable * table ) { int oldsegment ; int oldindex ; int newbucket ; int newsegment ; int newindex ; HashList * hl ; HashList * next ; HashList * old , * new ; if ( table -> split + table -> max >= HDIRSIZE * HSEGSIZE ) return ; oldsegment = table -> split / HSEGSIZE ; oldindex = table -> split % HSEGSIZE ; newbucket = table -> max + table -> split ; newsegment = newbucket / HSEGSIZE ; newindex = newbucket % HSEGSIZE ; if ( newindex == 0 ) allocSegment ( table , newsegment ) ; if ( ++ table -> split == table -> max ) { table -> split = 0 ; table -> max *= 2 ; table -> mask1 = table -> mask2 ; table -> mask2 = table -> mask2 << 1 | 1 ; } table -> bcount ++ ; old = new = NULL ; for ( hl = table -> dir [ oldsegment ] [ oldindex ] ; hl != NULL ; hl = next ) { next = hl -> next ; if ( table -> hash ( table , hl -> key ) == newbucket ) { hl -> next = new ; new = hl ; } else { hl -> next = old ; old = hl ; } } table -> dir [ oldsegment ] [ oldindex ] = old ; table -> dir [ newsegment ] [ newindex ] = new ; return ; }
Expand the larger hash table by one bucket, and split one bucket
 from the smaller table into two parts.
Expand the larger hash table by one bucket and split one bucket from the smaller table into two parts .
/* Wow!  That's big.  Too big, so don't expand. */ /* Calculate indices of bucket to split */ /* And the indices of the new bucket */ /* Split the bucket, paying no attention to the original order */