Ticket #9878: t9887-hash.c.patch

File t9887-hash.c.patch, 1.4 KB (added by qnikst, 4 years ago)

fixes key lookup function

  • rts/Hash.c

    commit 7c4e85f3f800fd334088ad5349c635a1534eb41f
    Author: Alexander Vershilov <alexander.vershilov@gmail.com>
    Date:   Mon Dec 15 04:31:53 2014 +0300
    
        Trac #9878: fix incorrect function in Hash.c
        
        This commit fixes keysHashTable function.
    
    diff --git a/rts/Hash.c b/rts/Hash.c
    index 1881092..5ca476b 100644
    a b lookupHashTable(HashTable *table, StgWord key) 
    212212// If the table is modified concurrently, the function behavior is undefined.
    213213//
    214214int keysHashTable(HashTable *table, StgWord keys[], int szKeys) {
    215     int segment;
     215    int segment, index;
    216216    int k = 0;
    217     for(segment=0;segment<HDIRSIZE && table->dir[segment];segment+=1) {
    218         int index;
    219         for(index=0;index<HSEGSIZE;index+=1) {
    220             HashList *hl;
    221             for(hl=table->dir[segment][index];hl;hl=hl->next) {
     217    HashList *hl;
     218
     219
     220    /* The last bucket with something in it is table->max + table->split - 1 */
     221    segment = (table->max + table->split - 1) / HSEGSIZE;
     222    index = (table->max + table->split - 1) % HSEGSIZE;
     223
     224    while (segment >= 0) {
     225        while (index >= 0) {
     226            hl = table->dir[segment][index];
     227            while (hl) {
    222228                if (k == szKeys)
    223229                  return k;
    224230                keys[k] = hl->key;
    225231                k += 1;
     232                hl = hl->next;
    226233            }
     234            index--;
    227235        }
     236        segment--;
    228237    }
    229238    return k;
    230239}