Skip to content

Commit

Permalink
Use heap top replacement instead of pop+push
Browse files Browse the repository at this point in the history
  • Loading branch information
magnified103 committed Nov 14, 2024
1 parent 2cc0ce7 commit 25600b7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
11 changes: 4 additions & 7 deletions packages/node/src/riblt/encoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,10 @@ class MappingHeap {
this.fixTail();
}

pop(): SymbolMapping {
set top(mapping: SymbolMapping) {
if (this.heap.length === 0) throw Error("Heap is empty");
const root = this.heap[0];
this.heap[0] = this.heap[this.heap.length - 1];
this.heap.pop();
this.heap[0] = mapping;
this.fixHead();
return root;
}

get top(): SymbolMapping {
Expand Down Expand Up @@ -121,7 +118,7 @@ export class CodingPrefix<T extends SourceSymbol> {

computePrefix(size: number): void {
while (this.queue.size > 0 && this.queue.top.codedIdx < size) {
const mapping = this.queue.pop();
const mapping = this.queue.top;
while (mapping.codedIdx < size) {
const sourceIdx = mapping.sourceIdx;
const codedIdx = mapping.codedIdx;
Expand All @@ -132,7 +129,7 @@ export class CodingPrefix<T extends SourceSymbol> {
);
mapping.codedIdx = this.mapGenerators[sourceIdx].nextIndex();
}
this.queue.push(mapping);
this.queue.top = mapping;
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions packages/node/tests/riblt.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class VertexSymbolFactory extends SymbolFactory<VertexSymbol> {
describe("RIBLT test", async () => {
const factory = new VertexSymbolFactory();

test.each([10, 20, 40, 100, 1000, 10000, 50000, 100000])(
test.each([10, 20, 40, 100, 1000, 10000, 50000, 100000, 200000])(
"d=%i",
async (d) => {
const nlocal = d >> 1;
Expand Down Expand Up @@ -124,7 +124,7 @@ describe("RIBLT test", async () => {
expect(symbolState[symbol.data]).toBe(SymbolState.Remote);
}

console.log(`${sequenceSize / d} symbols/diff`);
console.log(`${sequenceSize} symbols, ${(sequenceSize / d).toFixed(3)} symbols/diff`);
},
);
});

0 comments on commit 25600b7

Please sign in to comment.