The type of the custom elements.
The type of the mapped primitive keys.
The first ISetMapped instance to compare.
The second ISetMapped instance to compare.
true if the sets contain exactly the same elements, false
otherwise.
type Point = Readonly<{ x: number; tag: string }>;
const toKey = (point: Point) => JSON.stringify(point);
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
const fromKey = (key: string) => JSON.parse(key) as Point;
const first = ISetMapped.create<Point, string>(
[
{ x: 1, tag: 'a' },
{ x: 2, tag: 'b' },
],
toKey,
fromKey,
);
const second = ISetMapped.create<Point, string>(
[
{ x: 2, tag: 'b' },
{ x: 1, tag: 'a' },
],
toKey,
fromKey,
);
const third = ISetMapped.create<Point, string>(
[{ x: 3, tag: 'c' }],
toKey,
fromKey,
);
assert.ok(ISetMapped.equal(first, second));
assert.notOk(ISetMapped.equal(first, third));
Checks if two ISetMapped instances are structurally equal.
Two ISetMapped instances are considered equal if they have the same size and contain exactly the same elements. The comparison is performed on the underlying mapped keys, so the transformation functions themselves don't need to be identical. Elements are compared based on their mapped key representations.
Performance: O(n) where n is the size of the smaller set.