Skip to content

Commit

Permalink
Biome formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
magnified103 committed Nov 13, 2024
1 parent d240281 commit 51c2b06
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 11 deletions.
1 change: 0 additions & 1 deletion packages/node/src/riblt/decoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import type {
SymbolFactory,
} from "./symbol.js";


export class Decoder<T extends SourceSymbol> extends CodingPrefix<T> {
decodedLocalSymbols: T[];
decodedRemoteSymbols: T[];
Expand Down
5 changes: 2 additions & 3 deletions packages/node/src/riblt/encoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ import {
type SourceSymbol,
HashedSymbol,
type SymbolFactory,
type CodedSymbol
type CodedSymbol,
} from "./symbol.js";


class SymbolMapping {
sourceIdx: number;
codedIdx: number;
Expand Down Expand Up @@ -101,7 +100,7 @@ export class CodingPrefix<T extends SourceSymbol> {
this.symbolFactory.cloneSource(symbol),
);
const mapping = new RandomMapping(hashedSymbol.checksum, 0);

this.sourceSymbols.push(hashedSymbol);
this.sourceSymbolDirections.push(direction);
this.mapGenerators.push(mapping);
Expand Down
11 changes: 8 additions & 3 deletions packages/node/src/riblt/mapping.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
import * as crypto from "node:crypto";

function rotl(x: bigint, k: bigint) {
return BigInt.asUintN(64, ((x << k) | (x >> (64n - k))));
return BigInt.asUintN(64, (x << k) | (x >> (64n - k)));
}

export class RandomMapping {
private s: BigUint64Array;
lastIdx: number;

constructor(seed: Uint8Array, lastIdx = 0) {
this.s = new BigUint64Array(crypto.createHash("sha256").update(seed).digest().buffer);
this.s = new BigUint64Array(
crypto.createHash("sha256").update(seed).digest().buffer,
);
this.lastIdx = lastIdx;
}

nextIndex(): number {
// https://prng.di.unimi.it/xoshiro256starstar.c
const result = BigInt.asUintN(64, rotl(BigInt.asUintN(64, this.s[1] * 5n), 7n) * 9n);
const result = BigInt.asUintN(
64,
rotl(BigInt.asUintN(64, this.s[1] * 5n), 7n) * 9n,
);

const t = BigInt.asUintN(64, this.s[1] << 17n);

Expand Down
7 changes: 3 additions & 4 deletions packages/node/tests/riblt.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { Decoder } from "../src/riblt/decoder.js";
import { Encoder } from "../src/riblt/encoder.js";
import { type SourceSymbol, SymbolFactory } from "../src/riblt/symbol.js";


class VertexSymbol implements SourceSymbol {
data: number;

Expand Down Expand Up @@ -98,7 +97,7 @@ describe("RIBLT test", async () => {
localDecoder.addCodedSymbol(
sequenceSize - 1,
localEncoder.codedSymbols[sequenceSize - 1],
remoteEncoder.codedSymbols[sequenceSize - 1]
remoteEncoder.codedSymbols[sequenceSize - 1],
);
// console.log(`localDecoder[${sequenceSize - 1}]: ${localDecoder.codedSymbols[sequenceSize - 1]}`);
} while (!localDecoder.tryDecode());
Expand All @@ -107,7 +106,7 @@ describe("RIBLT test", async () => {
// console.log(localDecoder.decodedRemoteSymbols);
// console.log(localDecoder.remaining);

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

0 comments on commit 51c2b06

Please sign in to comment.