Implement a key-value map type (a “dictionary” / hash map) from scratch, without using the language’s built-in dictionary/map as the underlying storage.
Requirements
-
Support at least:
-
put(key, value)
-
get(key) -> value | null
-
remove(key)
-
Keys are hashable.
-
Handle hash collisions correctly.
-
Discuss or implement resizing/rehashing to keep operations efficient.
Constraints / Goals
-
Aim for
O(1)
average time per operation.
-
You may use arrays/lists as the underlying storage, but not a built-in associative container.
Follow-ups
-
Compare separate chaining vs open addressing.
-
How would you design this as a generic type (e.g., in Swift:
Key: Hashable
)?