data-structures · beginner · ~15 min

Map a hash to a bucket

Reduce a wide hash to a table index.

Challenge

Implement int bucket_of(unsigned long hash, int nbuckets) returning which bucket (0 .. nbuckets-1) a hash falls into.

Starter code

int bucket_of(unsigned long hash, int nbuckets) {
    /* TODO */
    return 0;
}

Solve this exercise in the browser editor — compile and run against the test harness, no setup required.