MCPcopy Create free account
hub / github.com/immutable-js/immutable-js / collisionKeys

Function collisionKeys

__tests__/Map.collision.ts:11–22  ·  view source on GitHub ↗

* Generates `2 ** rounds` distinct strings that all share the same * `Immutable.hash()`, by concatenating the classic "Aa"/"BB" collision blocks * (both equal `65 * 31 + 97 === 66 * 31 + 66 === 2112` under the JVM-style * `31 * h + c` string hash). Inserting these into a Map forces them all into

(rounds: number)

Source from the content-addressed store, hash-verified

9 * single HashCollisionNode — the hash-flooding scenario this code guards.
10 */
11function collisionKeys(rounds: number): Array<string> {
12 let keys = [''];
13 for (let i = 0; i < rounds; i++) {
14 const next: Array<string> = [];
15 for (const k of keys) {
16 next.push(k + 'Aa');
17 next.push(k + 'BB');
18 }
19 keys = next;
20 }
21 return keys;
22}
23
24describe('Map hash collisions', () => {
25 it('the generated keys really do collide (test is meaningful)', () => {

Callers 1

Map.collision.tsFile · 0.70

Calls 1

pushMethod · 0.65

Tested by

no test coverage detected