Step 2 of 4

Collision Chaining & Deletion

You start from the build so far — your own work where you have written it, the reference build where you have not. Either way this step stands on its own.

When two different keys hash to the exact same bucket index, a collision occurs.

Using separate chaining, each bucket holds a list of entries.

  • Ensure set and get work correctly when multiple keys occupy the same bucket.
  • Implement delete(key):
    • If the key exists, remove its [key, value] pair from the bucket, decrement the item count, and return true.
    • If the key does not exist, return false.

Your build

Running is free — Submit is what records the step. Or press ⌘↩

Tests

2 cases
calltypeexpectedresult
runOps(2, [["set","k1",100],["set","k2",200],["set","k3",300],["get","k1"],["get","k2"],["get","k3"]])handles deliberate bucket collisions[null,null,null,100,200,300]
runOps(4, [["set","alpha",1],["set","beta",2],["delete","alpha"],["get","alpha"],["delete","alpha"],["get","beta"]])deletes existing and missing keys[null,null,true,null,false,2]

Hints

Stuck? Hints open one at a time, each giving a little more away.

3 hints left