arjunhm / c-hash-tables

0 stars 0 forks source link

issue in linear_probe #3

Closed arjunhm closed 1 month ago

arjunhm commented 2 months ago

Commit: b3767de91784ce93d8f0e84a650c85c393c7fba6

Running gdb, I found the issue in linear_probe

bool linear_probe(Item *items, int size, Item *item, int idx) {
    int i, c = 0;
    while (i < size) {
        idx = idx % size;
        if (items[idx].key == NULL) {
            items[idx].key = item->key;
            items[idx].value = item->value;
            printf("%d collisions for %s\n", c, item->key);
            return true;
        }
        c++;
        idx++;
        i++;
    }
    return false;
}

i was initialized to a random value instead of 0.

arjunhm commented 2 months ago

Fix: int i=0, c=0;