Skip to content

Commit d45eeb5

Browse files
committed
style: spelling and formatting
Signed-off-by: Neko Ayaka <[email protected]>
1 parent 1e72747 commit d45eeb5

File tree

4 files changed

+23
-12
lines changed

4 files changed

+23
-12
lines changed

cspell.config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ words:
66
- Attributify
77
- composables
88
- Nuxt
9+
- Soliton
910
- timeseries
1011
- unocss
1112
- wechat

utils/lt-code/decoder.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,24 +100,28 @@ export class LtDecoder {
100100
if (this.decodedData.some(block => block == null)) {
101101
return
102102
}
103-
const indiceSize = this.meta.data.length
103+
104+
const indicesSize = this.meta.data.length
104105
const blocks = this.decodedData as Uint8Array[]
105106
const decodedData = new Uint8Array(this.meta.bytes)
107+
106108
blocks.forEach((block, i) => {
107-
const start = i * indiceSize
108-
if (start + indiceSize > decodedData.length) {
109+
const start = i * indicesSize
110+
if (start + indicesSize > decodedData.length) {
109111
for (let j = 0; j < decodedData.length - start; j++) {
110112
decodedData[start + j] = block[j]!
111113
}
112114
}
113115
else {
114-
decodedData.set(block, i * indiceSize)
116+
decodedData.set(block, i * indicesSize)
115117
}
116118
})
119+
117120
const checksum = getChecksum(decodedData, this.meta.k)
118121
if (checksum !== this.meta.checksum) {
119122
throw new Error('Checksum mismatch')
120123
}
124+
121125
return decodedData
122126
}
123127
}

utils/lt-code/encoder.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import type { EncodedBlock } from './shared'
22
import { getChecksum } from './checksum'
33

4-
export function createEncoder(data: Uint8Array, indiceSize: number) {
5-
return new LtEncoder(data, indiceSize)
4+
export function createEncoder(data: Uint8Array, indicesSize: number) {
5+
return new LtEncoder(data, indicesSize)
66
}
77

88
export class LtEncoder {
@@ -13,20 +13,20 @@ export class LtEncoder {
1313

1414
constructor(
1515
public readonly data: Uint8Array,
16-
public readonly indiceSize: number,
16+
public readonly indicesSize: number,
1717
) {
18-
this.indices = sliceData(data, indiceSize)
18+
this.indices = sliceData(data, indicesSize)
1919
this.k = this.indices.length
2020
this.checksum = getChecksum(data, this.k)
2121
this.bytes = data.length
2222
}
2323

2424
createBlock(indices: number[]): EncodedBlock {
25-
const data = new Uint8Array(this.indiceSize)
25+
const data = new Uint8Array(this.indicesSize)
2626
for (const index of indices) {
27-
const indice = this.indices[index]!
28-
for (let i = 0; i < this.indiceSize; i++) {
29-
data[i] = data[i]! ^ indice[i]!
27+
const indicesIndex = this.indices[index]!
28+
for (let i = 0; i < this.indicesSize; i++) {
29+
data[i] = data[i]! ^ indicesIndex[i]!
3030
}
3131
}
3232

@@ -58,6 +58,7 @@ function sliceData(data: Uint8Array, blockSize: number): Uint8Array[] {
5858
block.set(data.slice(i, i + blockSize))
5959
blocks.push(block)
6060
}
61+
6162
return blocks
6263
}
6364

@@ -95,5 +96,6 @@ function getRandomIndices(k: number, degree: number): number[] {
9596
const randomIndex = Math.floor(Math.random() * k)
9697
indices.add(randomIndex)
9798
}
99+
98100
return Array.from(indices)
99101
}

utils/lt-code/shared.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export function blockToBinary(block: EncodedBlock): Uint8Array {
3737

3838
export function binaryToBlock(binary: Uint8Array): EncodedBlock {
3939
const degree = new Uint32Array(binary.buffer, 0, 4)[0]!
40+
4041
const headerRest = Array.from(new Uint32Array(binary.buffer, 4, degree + 3))
4142
const indices = headerRest.slice(0, degree)
4243
const [
@@ -45,6 +46,7 @@ export function binaryToBlock(binary: Uint8Array): EncodedBlock {
4546
checksum,
4647
] = headerRest.slice(degree) as [number, number, number]
4748
const data = binary.slice(4 * (degree + 4))
49+
4850
return {
4951
k,
5052
bytes,
@@ -59,6 +61,7 @@ export function xorUint8Array(a: Uint8Array, b: Uint8Array): Uint8Array {
5961
for (let i = 0; i < a.length; i++) {
6062
result[i] = a[i]! ^ b[i]!
6163
}
64+
6265
return result
6366
}
6467

@@ -67,5 +70,6 @@ export function stringToUint8Array(str: string): Uint8Array {
6770
for (let i = 0; i < str.length; i++) {
6871
data[i] = str.charCodeAt(i)
6972
}
73+
7074
return data
7175
}

0 commit comments

Comments
 (0)