Skip to content

Commit

Permalink
Add minLamport to run gc properly
Browse files Browse the repository at this point in the history
  • Loading branch information
JOOHOJANG committed Nov 7, 2024
1 parent 924ba4c commit 5e3fdfb
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion packages/sdk/src/document/time/version_vector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,22 @@ export class VersionVector {
return max;
}

/**
* `minLamport` returns min lamport value from vector
*/
public minLamport() {
const lamports = [...this.vector.values()];
let min = lamports[0];

for (let i = 1; i < lamports.length; i++) {
if (lamports[i] < min) {
min = lamports[i];
}
}

return min;
}

/**
* `max` returns new version vector which consists of max value of each vector
*/
Expand Down Expand Up @@ -96,7 +112,9 @@ export class VersionVector {
const lamport = this.vector.get(other.getActorID());

if (lamport === undefined) {
return false;
const minLamport = this.minLamport();

return !!minLamport && minLamport > other.getLamport();
}

return lamport >= other.getLamport();
Expand Down

0 comments on commit 5e3fdfb

Please sign in to comment.