"""
Generate constant hash tables.
The `constant_hash` module can generate constant pre-populated hash tables. We
don't attempt perfect hashing, but simply generate an open addressed
quadratically probed hash table.
"""
# noqa
pass
# type: (str) -> int
"""
Compute a primitive hash of a string.
Example:
>>> "0x%x" % simple_hash("Hello")
'0x2fa70c01'
>>> "0x%x" % simple_hash("world")
'0x5b0c31d5'
"""
= 5381
= & 0xffffffff
return
# type: (Iterable[Any], Callable[[Any], int]) -> List[Any]
"""
Compute an open addressed, quadratically probed hash table containing
`items`. The returned table is a list containing the elements of the
iterable `items` and `None` in unused slots.
:param items: Iterable set of items to place in hash table.
:param hash_function: Hash function which takes an item and returns a
number.
Simple example (see hash values above, they collide on slot 1):
>>> compute_quadratic(['Hello', 'world'], simple_hash)
[None, 'Hello', 'world', None]
"""
=
# Table size must be a power of two. Aim for >20% unused slots.
=
= * # type: List[Any]
= %
= 0
+= 1
= %
=
return