14 February 2022

Housekeeping

Hashing

delicious corned beef hash

Delicious Corned Beef Hash

What's the idea? A hash function is a function whose domain is some set of objects and whose codomain is the integers. Hash functions are used in a variety of contexts.

A perfect hash function is one which associates different domain values with different integers. Part of the problem is the F-word, "finite." In practice, this is not attained but a well-defined hashing scheme will minimize these so-called "collisions."

Hash functions must be mathematical functions; i.e. the same input yields the same output every time. This is the consistency specification.

A good hash function is basically impossible to invert. Given the output of the hash function, it should be nearly impossible to determine the input. Hence their usefulness as a security measure.

Hashable Objects in Python Mutable objects are not hashable. You might ask why. Hash function usually depend on object state. So if state changes, the hash function could change, violating the consistency specification. How do you see if something is hashable? Call the hash function on it.

Sets

A Little Math

Stupid Set (You will later write this in Java)

Hashing and Sets Here is why retrieval from a set is fast.

Dictionaries