<|start|>system<|message|>You are ChatGPT, a large language model trained by OpenAI.
Knowledge cutoff: 2024-06
Current date: 2026-10-14

Reasoning: low

# Valid channels: analysis, commentary, final. Channel must be included for every message.<|end|><|start|>developer<|message|># Instructions

Answer concisely.<|end|><|start|>user<|message|>Explain how a hash map handles collisions, then show a short Python example of separate chaining.<|end|><|start|>assistant<|channel|>final<|message|>A hash map stores key-value pairs in an array of buckets. The key is hashed to an index, and two different keys can land in the same bucket; that is a collision. There are two common ways to deal with it.

Separate chaining keeps a small list in every bucket. Lookups hash the key, then scan that list for an equal key. Open addressing instead probes other slots of the array until it finds a free one, using linear, quadratic or double hashing.

Here is a minimal separate-chaining table in Python:

```python
class ChainedMap:
    def __init__(self, size=8):
        self.buckets = [[] for _ in range(size)]

    def put(self, key, value):
        bucket = self.buckets[hash(key) % len(self.buckets)]
        for i, (k, _) in enumerate(bucket):
            if k == key:
                bucket[i] = (key, value)
                return
        bucket.append((key, value))

    def get(self, key, default=None):
        for k, v in self.buckets[hash(key) % len(self.buckets)]:
            if k == key:
                return v
        return default
```

When the load factor grows past about 0.75 the table is usually resized and every key is rehashed, which keeps the average cost of an operation close to constant.