| 385 | |
| 386 | /** @internal */ |
| 387 | export function makeCompareSet<A>(equivalence: Equivalence<A>) { |
| 388 | return function compareSets(self: Iterable<A>, that: Iterable<A>): boolean { |
| 389 | const thatValues = Array.from(that) |
| 390 | for (const selfValue of self) { |
| 391 | let found = false |
| 392 | for (let i = 0; i < thatValues.length; i++) { |
| 393 | const thatValue = thatValues[i] |
| 394 | if (equivalence(selfValue, thatValue)) { |
| 395 | thatValues[i] = thatValues[thatValues.length - 1] |
| 396 | thatValues.pop() |
| 397 | found = true |
| 398 | break |
| 399 | } |
| 400 | } |
| 401 | if (!found) { |
| 402 | return false |
| 403 | } |
| 404 | } |
| 405 | |
| 406 | return true |
| 407 | } |
| 408 | } |
| 409 | |
| 410 | const compareSets = makeCompareSet(compareBoth) |
| 411 | |