Skip to content

Commit

Permalink
Formatting fix
Browse files Browse the repository at this point in the history
  • Loading branch information
magnified103 committed Nov 13, 2024
1 parent 7383a94 commit d240281
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 13 deletions.
2 changes: 1 addition & 1 deletion packages/node/src/riblt/decoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export class Decoder<T extends SourceSymbol> extends CodingPrefix<T> {
addCodedSymbol(
index: number,
localSymbol: CodedSymbol<T>,
remoteSymbol: CodedSymbol<T>
remoteSymbol: CodedSymbol<T>,
): void {
this.extendPrefix(index + 1);
this.codedSymbols[index].apply(localSymbol, localSymbol.count);
Expand Down
8 changes: 4 additions & 4 deletions packages/node/src/riblt/encoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
HashedSymbol,
type SymbolFactory,
type CodedSymbol
} from "./symbol.js"
} from "./symbol.js";


class SymbolMapping {
Expand Down Expand Up @@ -98,15 +98,15 @@ export class CodingPrefix<T extends SourceSymbol> {

addSymbol(symbol: T, direction = 1): void {
const hashedSymbol = new HashedSymbol<T>(
this.symbolFactory.cloneSource(symbol)
this.symbolFactory.cloneSource(symbol),
);
const mapping = new RandomMapping(hashedSymbol.checksum, 0);

this.sourceSymbols.push(hashedSymbol);
this.sourceSymbolDirections.push(direction);
this.mapGenerators.push(mapping);
this.queue.push(
new SymbolMapping(this.sourceSymbols.length - 1, mapping.lastIdx)
new SymbolMapping(this.sourceSymbols.length - 1, mapping.lastIdx),
);
}

Expand All @@ -129,7 +129,7 @@ export class CodingPrefix<T extends SourceSymbol> {
this.maps(
codedIdx,
this.sourceSymbols[sourceIdx],
this.sourceSymbolDirections[sourceIdx]
this.sourceSymbolDirections[sourceIdx],
);
mapping.codedIdx = this.mapGenerators[sourceIdx].nextIndex();
}
Expand Down
1 change: 0 additions & 1 deletion packages/node/src/riblt/symbol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ export interface SourceSymbol {
toString(): string;
}


export class HashedSymbol<T extends SourceSymbol> {
sum: T;
checksum: Uint8Array;
Expand Down
16 changes: 9 additions & 7 deletions packages/node/tests/riblt.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as crypto from 'node:crypto';
import * as crypto from "node:crypto";
import { beforeEach, describe, expect, test } from "vitest";
import { Decoder } from "../src/riblt/decoder.js";
import { Encoder } from "../src/riblt/encoder.js";
Expand All @@ -19,7 +19,7 @@ class VertexSymbol implements SourceSymbol {
hash(): Uint8Array {
return new Uint8Array(
crypto
.createHash('sha1')
.createHash("sha1")
.update(new Uint32Array([this.data]))
.digest(),
);
Expand All @@ -34,7 +34,6 @@ class VertexSymbol implements SourceSymbol {
}
}


class VertexSymbolFactory extends SymbolFactory<VertexSymbol> {
emptySource(): VertexSymbol {
return new VertexSymbol(0);
Expand All @@ -53,11 +52,9 @@ class VertexSymbolFactory extends SymbolFactory<VertexSymbol> {
}
}


describe("RIBLT test", async () => {
const factory = new VertexSymbolFactory();


test.each([10, 20, 40, 100, 1000, 10000, 50000, 100000, 300000])(
"d=%i",
async (d) => {
Expand Down Expand Up @@ -98,7 +95,11 @@ describe("RIBLT test", async () => {
remoteEncoder.producePrefix(sequenceSize);
// console.log(`localEncoder[${sequenceSize - 1}]: ${localEncoder.codedSymbols[sequenceSize - 1]}`);
// console.log(`remoteEncoder[${sequenceSize - 1}]: ${remoteEncoder.codedSymbols[sequenceSize - 1]}`);
localDecoder.addCodedSymbol(sequenceSize - 1, localEncoder.codedSymbols[sequenceSize - 1], remoteEncoder.codedSymbols[sequenceSize - 1]);
localDecoder.addCodedSymbol(
sequenceSize - 1,
localEncoder.codedSymbols[sequenceSize - 1],
remoteEncoder.codedSymbols[sequenceSize - 1]
);
// console.log(`localDecoder[${sequenceSize - 1}]: ${localDecoder.codedSymbols[sequenceSize - 1]}`);
} while (!localDecoder.tryDecode());

Expand All @@ -107,5 +108,6 @@ describe("RIBLT test", async () => {
// console.log(localDecoder.remaining);

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

0 comments on commit d240281

Please sign in to comment.