From d1a0e84841da554fb116533dea950d21c5c4a301 Mon Sep 17 00:00:00 2001 From: Nguyen Viet Dung <29406816+magnified103@users.noreply.github.com> Date: Thu, 7 Nov 2024 16:47:55 +0700 Subject: [PATCH] commit3 --- packages/node/src/sync/decoder.ts | 23 ----------------------- 1 file changed, 23 deletions(-) diff --git a/packages/node/src/sync/decoder.ts b/packages/node/src/sync/decoder.ts index 2eb6df3b..d33cddca 100644 --- a/packages/node/src/sync/decoder.ts +++ b/packages/node/src/sync/decoder.ts @@ -2,19 +2,11 @@ import type { Symbol } from "./symbol.js"; import type { CodedSymbol, HashedSymbol } from "./symbol.js"; export class Decoder> { - // Coded symbols received so far private cs: CodedSymbol[] = []; - // Set of source symbols that are exclusive to the decoder private local: CodingWindow; - // Set of source symbols that the decoder initially has private window: CodingWindow; - // Set of source symbols that are exclusive to the encoder private remote: CodingWindow; - // Indices of coded symbols that can be decoded, i.e., degree equal to -1 - // or 1 and sum of hash equal to hash of sum, or degree equal to 0 and sum - // of hash equal to 0 private decodable: number[] = []; - // Number of coded symbols that are decoded private decoded: number = 0; constructor() { @@ -23,42 +15,32 @@ export class Decoder> { this.remote = new CodingWindow(); } - // Decoded returns true if and only if every existing coded symbols d received - // so far have been decoded. public decoded(): boolean { return this.decoded === this.cs.length; } - // Local returns the list of source symbols that are present in B but not in A. public localSymbols(): HashedSymbol[] { return this.local.symbols; } - // Remote returns the list of source symbols that are present in A but not in B. public remoteSymbols(): HashedSymbol[] { return this.remote.symbols; } - // AddSymbol adds a source symbol to B, the Decoder's local set. public addSymbol(s: T): void { const th = new HashedSymbol(s, s.hash()); this.addHashedSymbol(th); } - // AddHashedSymbol adds a source symbol to B, the Decoder's local set. public addHashedSymbol(s: HashedSymbol): void { this.window.addHashedSymbol(s); } - // AddCodedSymbol passes the next coded symbol in A's sequence to the Decoder. public addCodedSymbol(c: CodedSymbol): void { - // Scan through decoded symbols to peel off matching ones c = this.window.applyWindow(c, "remove"); c = this.remote.applyWindow(c, "remove"); c = this.local.applyWindow(c, "add"); - // Insert the new coded symbol this.cs.push(c); - // Check if the coded symbol is decodable, and insert into decodable list if so if ((c.count === 1 || c.count === -1) && c.hash === c.symbol.hash()) { this.decodable.push(this.cs.length - 1); } else if (c.count === 0 && c.hash === 0) { @@ -66,13 +48,11 @@ export class Decoder> { } } - // Apply a new symbol and modify the corresponding coded symbols private applyNewSymbol(t: HashedSymbol, direction: number): RandomMapping { const m = new RandomMapping(t.hash, 0); while (m.lastIdx < this.cs.length) { const cidx = m.lastIdx; this.cs[cidx] = this.cs[cidx].apply(t, direction); - // Check if the coded symbol is now decodable if ( (this.cs[cidx].count === -1 || this.cs[cidx].count === 1) && this.cs[cidx].hash === this.cs[cidx].symbol.hash() @@ -84,14 +64,12 @@ export class Decoder> { return m; } - // TryDecode tries to decode all coded symbols received so far. public tryDecode(): void { for (const didx of this.decodable) { const cidx = this.decodable[didx]; const c = this.cs[cidx]; switch (c.count) { case 1: - // Allocate a symbol and then XOR with the sum const ns1 = new HashedSymbol(); ns1.symbol = ns1.symbol.xor(c.symbol); ns1.hash = c.hash; @@ -117,7 +95,6 @@ export class Decoder> { this.decodable = []; } - // Reset clears the decoder. public reset(): void { this.cs = []; this.decodable = [];