← Course home

Python reference · Reference

Hash table

Use hashes for expected fast lookup and see what collisions do to that expectation.

ReferenceAbout 2 min

This page lists the library modules for Hash table. The lesson is Hash tables with chaining.

This page is the module index for hash table.

Compare separate chaining with linear probing to see two ways to resolve collisions.

  • hash_tables/chaining.py — separate chaining. Expected O(1) lookup and insert; rehash is O(n) but amortized.
  • hash_tables/linear_probing.py — open addressing with tombstones. degenerate_chain_length explains a one-bucket table.

Industry

A working engineer uses a dict for lookup by key. Python's time-complexity documentation lists average-case get, set, and delete as O(1), and O(n) when every key hashes to the same bucket. Separate chaining is one bucket's list; that worst case is why a degenerate hash is part of this lesson.

Implementation and tests Optional reference

Library code 2

  • bitsandbytes.hash_tables.chaining
  • bitsandbytes.hash_tables.linear_probing

Use these references to compare the explanation with repository code and tests. A test link means it imports a lesson symbol; it does not by itself claim complete behavior coverage.