Developer concepts

What is a hash table?

Stores key and value pairs and finds any value by its key in about the same time, however big it gets.

How does an app find one user out of millions, almost instantly? Very often, with a hash table.

What it is

A hash table stores data as key and value pairs, and finds any value by its key in about the same time, no matter how big it gets.

How it works

A hash function turns the key, say an email address, into a number. That number picks a slot in an array, and the value goes there. To look it up later, hash the key again and go straight to the slot. When two keys land in the same slot, that's a collision, and the table keeps both side by side.

Why it matters

They're everywhere: Python dictionaries, JavaScript maps, caches. Lookups that stay fast at any size are hard to beat.

More from The Benmore Brief on YouTube

Put AI to work in your business.

Benmore's forward deployed engineers build and connect the software, from discovery to deployment.

Talk to us