-
Notifications
You must be signed in to change notification settings - Fork 12
/
index.d.ts
229 lines (193 loc) · 6.3 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
export class ResourcePool {
constructor();
/** @deprecated Should not be used externally! */
allocate(parent: object, size: number): ArrayBuffer;
/** @deprecated Should not be used externally! */
release(buf: ArrayBuffer): void;
}
/** @deprecated Use {@link ResourcePool} instead */
export const ArrayBufferPool = ResourcePool;
export type ScaledFreq = number;
export type Bit = 0 | 1;
export interface AnsOptions {
outBits: number;
precision: number;
}
export interface AnsOutput {
state: number;
buf: number[];
}
export class AnsEncoder {
constructor(options: AnsOptions);
writeBit(bit: Bit, predictedFreq: ScaledFreq): void;
finish(): AnsOutput;
}
export class AnsDecoder {
constructor(output: AnsOutput, options: AnsOptions);
readBit(predictedFreq: ScaledFreq): Bit;
}
export interface Model {
predict(context?: number): ScaledFreq;
update(actualBit: Bit, context?: number): void;
flushByte(currentByte: number, inBits: number): void;
release?(): void;
}
export interface DirectContextModelOptions {
inBits: number;
contextBits: number;
precision: number;
modelMaxCount: number;
modelRecipBaseCount: number;
resourcePool?: ResourcePool;
/** @deprecated Use {@link DirectContextModelOptions.resourcePool} instead */
arrayBufferPool?: ResourcePool;
}
export class DirectContextModel implements Model {
constructor(options: DirectContextModelOptions);
predict(context?: number): ScaledFreq;
update(actualBit: Bit, context?: number): void;
flushByte(currentByte: number, inBits: number): void;
release(): void;
}
export interface SparseContextModelOptions extends DirectContextModelOptions {
sparseSelector: number;
}
export class SparseContextModel implements DirectContextModel {
constructor(options: SparseContextModelOptions);
predict(context?: number): ScaledFreq;
update(actualBit: Bit, context?: number): void;
flushByte(currentByte: number, inBits: number): void;
release(): void;
}
export interface LogisticMixModelOptions {
recipLearningRate: number;
precision: number;
}
export class LogisticMixModel implements Model {
constructor(models: Model[], options: LogisticMixModelOptions);
predict(context?: number): ScaledFreq;
update(actualBit: Bit, context?: number): void;
flushByte(currentByte: number, inBits: number): void;
release(): void;
}
export interface DefaultModelOptions extends DirectContextModelOptions, LogisticMixModelOptions {
sparseSelectors: number[];
modelQuotes: boolean;
}
export class DefaultModel implements LogisticMixModel {
constructor(options: DefaultModelOptions);
predict(context?: number): ScaledFreq;
update(actualBit: Bit, context?: number): void;
flushByte(currentByte: number, inBits: number): void;
release(): void;
readonly quotesSeen: Set<number>;
}
export interface CompressOptions extends AnsOptions {
inBits: number;
preset?: number[];
inputEndsWithByte?: number;
calculateByteEntropy?: boolean;
}
export interface DefaultModelCompressOptions extends CompressOptions, DefaultModelOptions {
disableWasm?: boolean;
}
export interface Output {
inputLength: number;
state: number;
buf: number[];
}
export interface OutputExtra extends Output {
bufLengthInBytes: number;
byteEntropy?: number[];
}
export interface DefaultModelOutputExtra extends OutputExtra {
quotesSeen: Set<number>;
}
export function compressWithModel(input: ArrayLike<number>, model: Model, options: CompressOptions): OutputExtra;
export function compressWithDefaultModel(input: ArrayLike<number>, options: DefaultModelCompressOptions): DefaultModelOutputExtra;
export function decompressWithModel(output: Output, model: Model, options: CompressOptions): number[];
export interface OptimizerProgressInfo<Params = number[]> {
pass: string;
passRatio?: number;
current: Params;
currentSize: number;
currentRejected: boolean;
best: Params;
bestSize: number[];
bestUpdated: boolean;
}
export interface OptimizerResult<Params = number[]> {
elapsedMsecs: number;
best: Params;
bestSize: number[];
}
export function defaultSparseSelectors(numContexts?: number): number[];
export const enum InputType {
JS = 'js',
GLSL = 'glsl',
HTML = 'html',
Text = 'text',
Binary = 'binary',
}
export const enum InputAction {
Eval = 'eval',
JSON = 'json',
String = 'string',
Write = 'write',
Array = 'array',
Uint8Array = 'u8array',
Base64 = 'base64',
}
export interface Input {
data: string | ArrayLike<number>;
type: InputType;
action: InputAction;
}
export const enum DynamicModelFlags {
Quotes = 1 << 0,
}
export interface PackerOptions {
sparseSelectors?: number[];
maxMemoryMB?: number;
contextBits?: number;
precision?: number;
modelMaxCount?: number;
modelRecipBaseCount?: number;
resourcePool?: ResourcePool;
/** @deprecated Use {@link PackerOptions.resourcePool} instead */
arrayBufferPool?: ResourcePool;
recipLearningRate?: number;
numAbbreviations?: number;
dynamicModels?: number; // bit flags out of DynamicModelFlags
allowFreeVars?: boolean;
}
export interface OptimizedPackerOptions {
sparseSelectors: number[];
precision?: number;
modelMaxCount?: number;
modelRecipBaseCount?: number;
recipLearningRate?: number;
numAbbreviations?: number;
/** @deprecated Replaced by {@link OptimizedPackerOptions.dynamicModels}, no longer used */
preferTextOverJS?: boolean;
dynamicModels?: number;
}
export class Packer {
constructor(inputs: Input[], options: PackerOptions);
readonly memoryUsageMB: number;
makeDecoder(): Packed;
optimize(
progress?: (info: OptimizerProgressInfo<OptimizedPackerOptions>) => undefined | boolean | Promise<undefined | boolean>,
): Promise<OptimizerResult<OptimizedPackerOptions>>;
optimize(
level: number,
progress?: (info: OptimizerProgressInfo<OptimizedPackerOptions>) => undefined | boolean | Promise<undefined | boolean>,
): Promise<OptimizerResult<OptimizedPackerOptions>>;
}
export interface Packed {
readonly firstLine: string;
readonly firstLineLengthInBytes: number;
readonly secondLine: string;
readonly freeVars: string[];
estimateLength(): number;
}