| 359 | |
| 360 | /** @internal */ |
| 361 | export function makeCompareMap<K, V>(keyEquivalence: Equivalence<K>, valueEquivalence: Equivalence<V>) { |
| 362 | return function compareMaps(self: Iterable<[K, V]>, that: Iterable<[K, V]>): boolean { |
| 363 | const thatEntries = Array.from(that) |
| 364 | for (const [selfKey, selfValue] of self) { |
| 365 | let found = false |
| 366 | for (let i = 0; i < thatEntries.length; i++) { |
| 367 | const [thatKey, thatValue] = thatEntries[i] |
| 368 | if (keyEquivalence(selfKey, thatKey) && valueEquivalence(selfValue, thatValue)) { |
| 369 | thatEntries[i] = thatEntries[thatEntries.length - 1] |
| 370 | thatEntries.pop() |
| 371 | found = true |
| 372 | break |
| 373 | } |
| 374 | } |
| 375 | if (!found) { |
| 376 | return false |
| 377 | } |
| 378 | } |
| 379 | |
| 380 | return true |
| 381 | } |
| 382 | } |
| 383 | |
| 384 | const compareMaps = makeCompareMap(compareBoth, compareBoth) |
| 385 | |