Skip to content

Commit

Permalink
fix: fixed compareSets fn
Browse files Browse the repository at this point in the history
  • Loading branch information
joaopereira12 committed Jul 29, 2024
1 parent d4ba200 commit cc10508
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions packages/crdt/src/builtins/LWWElementSet/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,7 @@ export class LWWElementSet<T> {
}

compare(peerSet: LWWElementSet<T>): boolean {
const adds = new Set(this._adds.keys());
const rems = new Set(this._removes.keys());
const otherAdds = new Set(peerSet._adds.keys());
const otherRems = new Set(peerSet._removes.keys());

return (compareSets(adds, otherAdds) && compareSets(rems, otherRems));
return (compareSets(this._adds.keys(), peerSet._adds.keys()) && compareSets(this._removes.keys(), peerSet._removes.keys()));
}

merge(peerSet: LWWElementSet<T>): void {
Expand All @@ -68,6 +63,8 @@ export class LWWElementSet<T> {
}
}

function compareSets<T>(set1: Set<T>, set2: Set<T>): boolean {
function compareSets<T>(keys1: IterableIterator<T>, keys2: IterableIterator<T>): boolean {
const set1 = new Set<T>(keys1);
const set2 = new Set<T>(keys2);
return (set1.size == set2.size && [...set1].every(value => set2.has(value)));
}

0 comments on commit cc10508

Please sign in to comment.