( self: Iterable<A>, that: Iterable<A>, hashOf: (item: A) => number, equivalent: (self: A, that: A) => boolean )
| 349 | |
| 350 | // Match items one-to-one within equal-hash groups. |
| 351 | function compareHashed<A>( |
| 352 | self: Iterable<A>, |
| 353 | that: Iterable<A>, |
| 354 | hashOf: (item: A) => number, |
| 355 | equivalent: (self: A, that: A) => boolean |
| 356 | ): boolean { |
| 357 | const groups = new Map<number, Array<A>>() |
| 358 | let remaining = 0 |
| 359 | for (const item of that) { |
| 360 | const h = hashOf(item) |
| 361 | const group = groups.get(h) |
| 362 | if (group) group.push(item) |
| 363 | else groups.set(h, [item]) |
| 364 | remaining++ |
| 365 | } |
| 366 | outer: for (const item of self) { |
| 367 | const group = groups.get(hashOf(item)) |
| 368 | if (group) { |
| 369 | for (let i = 0; i < group.length; i++) { |
| 370 | if (equivalent(item, group[i])) { |
| 371 | group[i] = group[group.length - 1] |
| 372 | group.pop() |
| 373 | remaining-- |
| 374 | continue outer |
| 375 | } |
| 376 | } |
| 377 | } |
| 378 | return false |
| 379 | } |
| 380 | return remaining === 0 |
| 381 | } |
| 382 | |
| 383 | const entryHash = (entry: readonly [unknown, unknown]): number => Hash.hash(entry[0]) |
| 384 |
no test coverage detected