Skip to content

Commit

Permalink
add bitset tests
Browse files Browse the repository at this point in the history
  • Loading branch information
trungnotchung committed Nov 19, 2024
1 parent e80c280 commit fb39835
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 7 deletions.
18 changes: 12 additions & 6 deletions packages/object/src/linearize/multipleSemantics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,17 @@ export function linearizeMultiple(hashGraph: HashGraph): Operation[] {
indices.set(anchor, i);
concurrentOps.push(moving);
indices.set(moving, j);

let reachableVertices : BitSet = new BitSet(hashGraph.getCurrentBitsetSize());
const anchorReachablePredecessors = hashGraph.getReachablePredecessors(anchor);

let reachableVertices: BitSet = new BitSet(
hashGraph.getCurrentBitsetSize(),
);
const anchorReachablePredecessors =
hashGraph.getReachablePredecessors(anchor);
if (anchorReachablePredecessors) {
reachableVertices = reachableVertices.or(anchorReachablePredecessors);
}
const movingReachablePredecessors = hashGraph.getReachablePredecessors(moving);
const movingReachablePredecessors =
hashGraph.getReachablePredecessors(moving);
if (movingReachablePredecessors) {
reachableVertices = reachableVertices.or(movingReachablePredecessors);
}
Expand All @@ -63,7 +67,9 @@ export function linearizeMultiple(hashGraph: HashGraph): Operation[] {
if (add) {
concurrentOps.push(order[k]);
indices.set(order[k], k);
const reachablePredecessors = hashGraph.getReachablePredecessors(order[k]);
const reachablePredecessors = hashGraph.getReachablePredecessors(
order[k],
);
if (reachablePredecessors) {
reachableVertices = reachableVertices.or(reachablePredecessors);
}
Expand Down Expand Up @@ -104,4 +110,4 @@ export function linearizeMultiple(hashGraph: HashGraph): Operation[] {
}

return result;
}
}
21 changes: 20 additions & 1 deletion packages/object/tests/bitset.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,25 @@ describe("BitSet Test", () => {
expect(bitset.findNext(10, 1)).toBe(20);
expect(bitset.findNext(20, 1)).toBe(30);
expect(bitset.findNext(30, 1)).toBe(40);
expect(bitset.findNext(40, 1)).toBe(undefined);
expect(bitset.findNext(40, 1)).toBe(64);
});

test("find next index of zero-bit", () => {
for (let i = 0; i < 64; i++) {
bitset.set(i, true);
}

bitset.set(5, false);
bitset.set(10, false);
bitset.set(20, false);
bitset.set(30, false);
bitset.set(40, false);

expect(bitset.findNext(0, 0)).toBe(5);
expect(bitset.findNext(5, 0)).toBe(10);
expect(bitset.findNext(10, 0)).toBe(20);
expect(bitset.findNext(20, 0)).toBe(30);
expect(bitset.findNext(30, 0)).toBe(40);
expect(bitset.findNext(40, 0)).toBe(64);
});
});

0 comments on commit fb39835

Please sign in to comment.