# hash collision

An event in which two distinct inputs or messages produce the same hash value.

This is one page of public article previews, not the complete archive. Follow Next page to continue. Summaries are not the original full articles.

## Hash Tables and Hashing Explained (with JavaScript)

DevFeed: [Hash Tables and Hashing Explained (with JavaScript)](<https://devfeed.tech/articles/hash-tables-and-hashing-explained-with-javascript-138570.md>)

Original publisher: [Read original article](<https://markodenic.com/hash-tables/>)

Author: Marko

Published: 2026-11-17T09:00:00Z

Content type: article

Language: en

Sources: [Marko Denic Blog](<https://devfeed.tech/sources/marko-denic-blog.md>)

Topics: [hashing](<https://devfeed.tech/topics/hashing.md>), [JavaScript](<https://devfeed.tech/topics/javascript.md>), [hash collision](<https://devfeed.tech/topics/hash-collision.md>), [sha256](<https://devfeed.tech/topics/sha256.md>)

Tags: [array](<https://devfeed.tech/tags/array.md>), [caching](<https://devfeed.tech/tags/caching.md>), [chaining](<https://devfeed.tech/tags/chaining.md>), [checksums](<https://devfeed.tech/tags/checksums.md>), [coding-interviews](<https://devfeed.tech/tags/coding-interviews.md>), [cryptographic](<https://devfeed.tech/tags/cryptographic.md>), [data-structure](<https://devfeed.tech/tags/data-structure.md>), [encryption](<https://devfeed.tech/tags/encryption.md>), [hash](<https://devfeed.tech/tags/hash.md>), [hash-function](<https://devfeed.tech/tags/hash-function.md>), [hash-table](<https://devfeed.tech/tags/hash-table.md>), [hashing](<https://devfeed.tech/tags/hashing.md>), [javascript](<https://devfeed.tech/tags/javascript.md>), [map](<https://devfeed.tech/tags/map.md>), [set](<https://devfeed.tech/tags/set.md>), [tutorial](<https://devfeed.tech/tags/tutorial.md>)

### AI overview

A hash table maps keys to buckets using a deterministic hash, giving average O(1) lookup, insertion, and deletion; collisions are handled through bucket lists (chaining) or probing (open addressing). As entries accumulate, the load factor rises, so tables resize and reinsert entries; occasional O(n) resizing keeps insertion O(1) on average. The JavaScript example uses chaining, a simple string hash, and a 0.75 resize threshold, and is presented for learning rather than production use. In JavaScript, Map supports keys of any type and preserves insertion order, while Set stores unique values. Objects coerce keys to strings or symbols and inherit properties, so the text recommends Map for user-supplied keys. The article also distinguishes ordinary table hashes from cryptographic hashes and encryption, and advises using established salted password-hashing libraries for passwords.

### Source excerpt

What a hash and a hash table are, how hash functions, buckets, collisions and load factor work, how Map and Set use them, and a small hash table in JavaScript.

## Leapfrog Probing

DevFeed: [Leapfrog Probing](<https://devfeed.tech/articles/leapfrog-probing-21006.md>)

Original publisher: [Read original article](<https://preshing.com/20160314/leapfrog-probing>)

Author: Jeff Preshing

Published: 2016-03-14T20:24:00Z

Content type: tutorial

Language: en

Sources: [Jeff Preshing](<https://devfeed.tech/sources/jeff-preshing.md>)

Topics: [hash collision](<https://devfeed.tech/topics/hash-collision.md>), [Cache](<https://devfeed.tech/topics/cache.md>)

Tags: [array](<https://devfeed.tech/tags/array.md>), [atomic](<https://devfeed.tech/tags/atomic.md>), [cells](<https://devfeed.tech/tags/cells.md>), [data-structure](<https://devfeed.tech/tags/data-structure.md>), [friendly](<https://devfeed.tech/tags/friendly.md>), [hash-table](<https://devfeed.tech/tags/hash-table.md>), [linear-probing](<https://devfeed.tech/tags/linear-probing.md>), [linked-list](<https://devfeed.tech/tags/linked-list.md>), [open-addressing](<https://devfeed.tech/tags/open-addressing.md>)

### AI overview

Leapfrog probing shortens average searches versus linear probing and supports concurrent hash maps by storing two one-byte deltas per cell to link each bucket's probe chain. Lookups check the ideal cell, follow its first delta to the chain, then use the second delta until it is zero. Insertions search the chain, linearly find a free cell, and link it; if the required delta exceeds one byte, the table must be migrated. In Junction's concurrent Leapfrog map, cells are reserved with compare-and-swap and linked with a separate relaxed atomic store, so operations handle intermediate visibility states. Racing gets may return "not found," while concurrent inserts spin until a possibly linked key is visible or repair a missing link when they encounter an unexpected same-bucket item. The excerpt reports Leapfrog was the fastest concurrent map tested up to a modest number of CPU cores, and attributes performance in part to low write contention; it gives no benchmark figures.

### Source excerpt

A hash table is a data structure that stores a set of items, each of which maps a specific key to a specific value. There are many ways to implement a hash table, but they all have one thing in common: buckets. Every hash table maintains an array of buckets somewhere, and each item belongs to exactly one bucket. To determine the bucket for a given item, you typically hash the item's key, then compute its modulus - that is, the remainder when divided by the number of buckets. For a hash table with 16 buckets, the modulus is given by the final hexadecimal digit of the hash. Inevitably, several items will end up belonging to same bucket. For simplicity, let's suppose the hash function is invertible, so that we only need to store hashed keys. A well-known strategy is to store the bucket contents in a linked list: This strategy is known as separate chaining. Separate chaining tends to be relatively slow on modern CPUs, since it requires a lot of pointer lookups. I'm more fond of open addressing, which stores all the items in the array itself: In open addressing, each cell in the array still represents a single bucket, but can actually store an item belonging to any bucket. Open addressing is more cache-friendly than separate chaining. If an item is not found in its ideal cell, it's often nearby. The drawback is that as the array becomes full, you may need to search a lot of cells before finding a particular item, depending on the probing strategy. For example, consider linear probing, the simplest probing strategy. Suppose we want to insert the item (13, "orange") into the above table, and the hash of 13 is 0x95bb7d92. Ideally, we'd store this item at index 2, the last hexadecimal digit of the hash, but that cell is already taken. Under linear probing, we find the next free cell by searching linearly, starting at the item's ideal index, and store the item there instead: As you can see, the item (13, "orange") ended up quite far from its ideal cell. Not great for lookups.

## Counting hash collisions with the birthday paradox

DevFeed: [Counting hash collisions with the birthday paradox](<https://devfeed.tech/articles/counting-hash-collisions-with-the-birthday-paradox-35234.md>)

Original publisher: [Read original article](<http://matt.might.net/articles/counting-hash-collisions/>)

Published: 2015-07-17T03:33:41Z

Content type: article

Language: en

Sources: [Matt Might](<https://devfeed.tech/sources/matt-might.md>)

Topics: [hashing](<https://devfeed.tech/topics/hashing.md>), [hash collision](<https://devfeed.tech/topics/hash-collision.md>)

Tags: [birthday](<https://devfeed.tech/tags/birthday.md>), [geometric-series](<https://devfeed.tech/tags/geometric-series.md>), [hash](<https://devfeed.tech/tags/hash.md>), [hash-function](<https://devfeed.tech/tags/hash-function.md>), [matching](<https://devfeed.tech/tags/matching.md>)

### AI overview

For a uniform hash range of size D, the expected number of matches as n values arrive is n − D + D((D−1)/D)^n. The derivation sums each arrival's probability of matching an earlier value, 1 − ((D−1)/D)^(k−1), then simplifies the geometric series. This counts arrivals that match something already seen, not unique matched values or matching pairs: if three arrivals share one value, the second and third each count as a match, for two total.

### Source excerpt

The birthday paradox observes that in a room of 23 people, the odds that at least two people share a birthday is 50% The same logic that drives matching birthdays also drives the probability that one can find collisions with a hash function. In other words, if you have a uniform hashing function that outputs a value between 1 and 365 for any input, the probability that two hashes would collide in a set of 23 values is also 50% Another useful calculation is the expected number of collisions for a sequence of \(n\) values when the range of the hash function contains \(D\) hashes. The closed form solution is: \[ n - D + D \left( \frac{D-1}{D} \right)^n \] There are a few places online that have this (or an equivalent) closed form solution listed, but I couldn't find anywhere that included the derivation of this form, so I've rederived it and posted it here as a technical note. (My present interest in this calculation comes from the number of matches that will happen in a patient-matching network that attempts to match patients having the same disease, assuming the are \(D\) total diseases possible and \(n\) patients in the network.) Read below for the derivation in terms of generalized birthdays. Click here to read the rest of the article