zeck 0.1.0 → 1.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +156 -19
- package/package.json +9 -9
- package/{zeckendorf_rs.d.ts → zeck.d.ts} +65 -45
- package/zeck.js +5 -0
- package/{zeckendorf_rs_bg.js → zeck_bg.js} +69 -49
- package/{zeckendorf_rs_bg.wasm → zeck_bg.wasm} +0 -0
- package/zeckendorf_rs.js +0 -5
package/README.md
CHANGED
|
@@ -6,6 +6,10 @@ A Rust library for compressing and decompressing data using the Zeckendorf repre
|
|
|
6
6
|
|
|
7
7
|
The Zeckendorf algorithm represents numbers as a sum of non-consecutive Fibonacci numbers. This library interprets input data as a big integer (either big-endian or little-endian), converts it to its Zeckendorf representation, and sometimes achieves compression. However, compression is not guaranteed; the algorithm may result in a larger representation depending on the input data. The library can automatically try both endian interpretations and select the one that produces the best compression.
|
|
8
8
|
|
|
9
|
+
**⚠️ Warning:** Compressing or decompressing files larger than 10KB (10,000 bytes) is unstable due to time and memory pressure. The library may experience performance issues, excessive memory usage, or failures when processing files exceeding this size.
|
|
10
|
+
|
|
11
|
+
**Command-line tools** (`zeck-compress` and `zeck-decompress`) are available and can be installed via `cargo install zeck`. See the [Binaries](#binaries) section for usage details.
|
|
12
|
+
|
|
9
13
|
## Features
|
|
10
14
|
|
|
11
15
|
- **Compression & Decompression**: Convert data to/from Zeckendorf representation
|
|
@@ -33,42 +37,59 @@ You can see a live demo of the WebAssembly module in action at <https://prizz.gi
|
|
|
33
37
|
|
|
34
38
|
Run:
|
|
35
39
|
```bash
|
|
36
|
-
cargo add
|
|
40
|
+
cargo add zeck
|
|
37
41
|
```
|
|
38
42
|
|
|
39
43
|
Or add this to your `Cargo.toml`:
|
|
40
44
|
|
|
41
45
|
```toml
|
|
42
46
|
[dependencies]
|
|
43
|
-
|
|
47
|
+
zeck = "0.1.0"
|
|
44
48
|
```
|
|
45
49
|
|
|
46
50
|
For plotting features:
|
|
47
51
|
|
|
48
52
|
```toml
|
|
49
53
|
[dependencies]
|
|
50
|
-
|
|
54
|
+
zeck = { version = "0.1.0", features = ["plotting"] }
|
|
51
55
|
```
|
|
52
56
|
|
|
53
57
|
### Install from GitHub (development version)
|
|
54
58
|
|
|
55
59
|
Run:
|
|
56
60
|
```bash
|
|
57
|
-
cargo add
|
|
61
|
+
cargo add zeck --git https://github.com/pRizz/zeckendorf
|
|
58
62
|
```
|
|
59
63
|
|
|
60
64
|
Or add this to your `Cargo.toml`:
|
|
61
65
|
|
|
62
66
|
```toml
|
|
63
67
|
[dependencies]
|
|
64
|
-
|
|
68
|
+
zeck = { git = "https://github.com/pRizz/zeckendorf" }
|
|
65
69
|
```
|
|
66
70
|
|
|
67
71
|
For plotting features:
|
|
68
72
|
|
|
69
73
|
```toml
|
|
70
74
|
[dependencies]
|
|
71
|
-
|
|
75
|
+
zeck = { git = "https://github.com/pRizz/zeckendorf", features = ["plotting"] }
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### Install from npm
|
|
79
|
+
|
|
80
|
+
Run:
|
|
81
|
+
```bash
|
|
82
|
+
npm install zeck
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
Or add this to your `package.json`:
|
|
86
|
+
|
|
87
|
+
```json
|
|
88
|
+
{
|
|
89
|
+
"dependencies": {
|
|
90
|
+
"zeck": "^0.1.0"
|
|
91
|
+
}
|
|
92
|
+
}
|
|
72
93
|
```
|
|
73
94
|
|
|
74
95
|
## Usage
|
|
@@ -78,7 +99,7 @@ zeckendorf = { git = "https://github.com/pRizz/zeckendorf", features = ["plottin
|
|
|
78
99
|
#### Big-Endian Interpretation
|
|
79
100
|
|
|
80
101
|
```rust
|
|
81
|
-
use
|
|
102
|
+
use zeck::{zeckendorf_compress_be, zeckendorf_decompress_be};
|
|
82
103
|
|
|
83
104
|
// Compress data (interpreted as big-endian integer)
|
|
84
105
|
let data = vec![12u8];
|
|
@@ -92,7 +113,7 @@ assert_eq!(data, decompressed);
|
|
|
92
113
|
#### Little-Endian Interpretation
|
|
93
114
|
|
|
94
115
|
```rust
|
|
95
|
-
use
|
|
116
|
+
use zeck::{zeckendorf_compress_le, zeckendorf_decompress_le};
|
|
96
117
|
|
|
97
118
|
// Compress data (interpreted as little-endian integer)
|
|
98
119
|
let data = vec![12u8];
|
|
@@ -106,7 +127,7 @@ assert_eq!(data, decompressed);
|
|
|
106
127
|
#### Automatic Best Compression
|
|
107
128
|
|
|
108
129
|
```rust
|
|
109
|
-
use
|
|
130
|
+
use zeck::{zeckendorf_compress_best, zeckendorf_decompress_be, zeckendorf_decompress_le, CompressionResult};
|
|
110
131
|
|
|
111
132
|
// Try both endian interpretations and get the best result
|
|
112
133
|
let data = vec![1, 0];
|
|
@@ -133,20 +154,20 @@ match result {
|
|
|
133
154
|
### Fibonacci Numbers
|
|
134
155
|
|
|
135
156
|
```rust
|
|
136
|
-
use
|
|
157
|
+
use zeck::memoized_slow_fibonacci_recursive;
|
|
137
158
|
|
|
138
159
|
// Calculate Fibonacci numbers (for indices up to 93)
|
|
139
160
|
let fib_10 = memoized_slow_fibonacci_recursive(10); // Returns 55
|
|
140
161
|
|
|
141
162
|
// For larger numbers, use BigInt versions
|
|
142
|
-
use
|
|
163
|
+
use zeck::fast_doubling_fibonacci_bigint;
|
|
143
164
|
let fib_100 = fast_doubling_fibonacci_bigint(100);
|
|
144
165
|
```
|
|
145
166
|
|
|
146
167
|
### Zeckendorf Representation
|
|
147
168
|
|
|
148
169
|
```rust
|
|
149
|
-
use
|
|
170
|
+
use zeck::memoized_zeckendorf_list_descending_for_integer;
|
|
150
171
|
|
|
151
172
|
// Get Zeckendorf representation as a list of Fibonacci indices
|
|
152
173
|
let zld = memoized_zeckendorf_list_descending_for_integer(12);
|
|
@@ -155,12 +176,128 @@ let zld = memoized_zeckendorf_list_descending_for_integer(12);
|
|
|
155
176
|
|
|
156
177
|
## Binaries
|
|
157
178
|
|
|
158
|
-
The project includes several utility binaries:
|
|
179
|
+
The project includes several utility binaries. The command-line compression tools (`zeck-compress` and `zeck-decompress`) can be installed globally via:
|
|
180
|
+
|
|
181
|
+
### Install from crates.io
|
|
182
|
+
|
|
183
|
+
```bash
|
|
184
|
+
cargo install zeck
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
### Install from GitHub (development version)
|
|
188
|
+
|
|
189
|
+
```bash
|
|
190
|
+
cargo install --git https://github.com/pRizz/zeckendorf zeck
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
After installation, you can use `zeck-compress` and `zeck-decompress` directly from your command line.
|
|
194
|
+
|
|
195
|
+
### Compression/Decompression Tools
|
|
196
|
+
|
|
197
|
+
**⚠️ Warning:** Compressing or decompressing files larger than 10KB (10,000 bytes) is unstable due to time and memory pressure. The library may experience performance issues, excessive memory usage, or failures when processing files exceeding this size.
|
|
198
|
+
|
|
199
|
+
#### zeck-compress
|
|
200
|
+
|
|
201
|
+
Compresses data using the Zeckendorf representation algorithm. Automatically adds `.zbe` extension for big-endian compression and `.zle` extension for little-endian compression.
|
|
202
|
+
|
|
203
|
+
```bash
|
|
204
|
+
zeck-compress [INPUT] [-o OUTPUT] [--endian ENDIAN] [-v]
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
**Options:**
|
|
208
|
+
- `INPUT`: Input file path (optional, reads from stdin if not specified)
|
|
209
|
+
- Shows a warning if reading from stdin and no data was piped in
|
|
210
|
+
- `-o, --output FILE`: Output file path (optional)
|
|
211
|
+
- If not specified and input is a file, uses the input filename with the appropriate extension (`.zbe` or `.zle`) appended
|
|
212
|
+
- If not specified and reading from stdin, writes to stdout
|
|
213
|
+
- The appropriate extension (`.zbe` for big-endian, `.zle` for little-endian) is automatically added unless the file already ends with `.zbe` or `.zle`
|
|
214
|
+
- `--endian ENDIAN`: Endianness to use (`big`, `little`, or `best`). Default: `best`
|
|
215
|
+
- `big`: Use big-endian interpretation (output will have `.zbe` extension)
|
|
216
|
+
- `little`: Use little-endian interpretation (output will have `.zle` extension)
|
|
217
|
+
- `best`: Try both and use the best result (default, extension added based on which was used)
|
|
218
|
+
- **Note:** When using `best`, if neither method produces compression (both result in larger or equal output), the tool will exit with an error showing compression statistics
|
|
219
|
+
- `-v, --verbose`: Show compression statistics (default: true, use `--no-verbose` to disable)
|
|
220
|
+
|
|
221
|
+
**Examples:**
|
|
222
|
+
```bash
|
|
223
|
+
# Compress a file (output filename automatically created from input with extension)
|
|
224
|
+
zeck-compress input.bin
|
|
225
|
+
# Creates input.bin.zbe or input.bin.zle depending on which endianness was used
|
|
226
|
+
|
|
227
|
+
# Compress with best endianness (statistics shown by default)
|
|
228
|
+
zeck-compress input.bin --endian best
|
|
229
|
+
|
|
230
|
+
# Compress with specific endianness (creates input.bin.zbe)
|
|
231
|
+
zeck-compress input.bin --endian big
|
|
232
|
+
|
|
233
|
+
# Compress to a specific output file
|
|
234
|
+
zeck-compress input.bin -o output
|
|
235
|
+
# Creates output.zbe or output.zle depending on which endianness was used
|
|
236
|
+
|
|
237
|
+
# Compress from stdin to stdout
|
|
238
|
+
cat input.bin | zeck-compress
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
**Note:** When writing to a file, the output filename is printed to stdout (e.g., "Compressed to: input.bin.zbe"). Verbose statistics are shown by default and include descriptive messages about compression ratios (e.g., "File was compressed by X.XX% (Y bytes -> Z bytes)"). A warning is shown when reading from stdin if no data was piped in.
|
|
242
|
+
|
|
243
|
+
#### zeck-decompress
|
|
244
|
+
|
|
245
|
+
Decompresses data that was compressed using the Zeckendorf representation algorithm. Automatically detects endianness from file extension (`.zbe` for big-endian, `.zle` for little-endian).
|
|
246
|
+
|
|
247
|
+
```bash
|
|
248
|
+
zeck-decompress [INPUT] [-o OUTPUT] [--endian ENDIAN] [-v]
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
**Options:**
|
|
252
|
+
- `INPUT`: Input file path (optional, reads from stdin if not specified)
|
|
253
|
+
- When reading from a file, endianness is automatically detected from file extension (`.zbe` for big-endian, `.zle` for little-endian)
|
|
254
|
+
- **If extension is not recognized, `--endian` is REQUIRED** (exits with error if not specified)
|
|
255
|
+
- **When reading from stdin, `--endian` is REQUIRED**
|
|
256
|
+
- Shows a warning if reading from stdin and no data was piped in
|
|
257
|
+
- `-o, --output FILE`: Output file path (optional)
|
|
258
|
+
- If not specified and input is a file, uses the input filename with `.zbe` or `.zle` extension removed
|
|
259
|
+
- If not specified and reading from stdin, writes to stdout
|
|
260
|
+
- `--endian ENDIAN`: Endianness used during compression (`big` or `little`)
|
|
261
|
+
- `big`: Decompress as big-endian
|
|
262
|
+
- `little`: Decompress as little-endian
|
|
263
|
+
- **REQUIRED when reading from stdin** (no input file specified)
|
|
264
|
+
- When reading from a file, this option overrides automatic detection from file extension
|
|
265
|
+
- `-v, --verbose`: Show decompression statistics (default: true, use `--no-verbose` to disable)
|
|
266
|
+
|
|
267
|
+
**Examples:**
|
|
268
|
+
```bash
|
|
269
|
+
# Decompress a file (endianness detected from .zbe extension, output filename automatically created)
|
|
270
|
+
zeck-decompress input.zbe
|
|
271
|
+
# Automatically uses big-endian decompression, creates output file "input"
|
|
272
|
+
|
|
273
|
+
# Decompress with little-endian file
|
|
274
|
+
zeck-decompress input.zle
|
|
275
|
+
# Automatically uses little-endian decompression, creates output file "input"
|
|
276
|
+
|
|
277
|
+
# Decompress to a specific output file
|
|
278
|
+
zeck-decompress input.zbe -o output.bin
|
|
279
|
+
# Automatically uses big-endian decompression
|
|
280
|
+
|
|
281
|
+
# Override automatic detection
|
|
282
|
+
zeck-decompress input.zbe --endian little -o output.bin
|
|
283
|
+
# Overrides the .zbe extension and uses little-endian
|
|
284
|
+
|
|
285
|
+
# Decompress from stdin to stdout (--endian is required)
|
|
286
|
+
cat input.zbe | zeck-decompress --endian big
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
**Note:** The endianness used for decompression must match the endianness used during compression. The file extension (`.zbe` or `.zle`) indicates which endianness was used, so decompression will automatically use the correct endianness when reading from a file. **If the input file doesn't have a recognized extension, `--endian` must be explicitly specified** (the tool will exit with an error if not provided). You can override automatic detection with the `--endian` flag if needed. **When reading from stdin, `--endian` must be explicitly specified** since there's no file extension to detect from.
|
|
290
|
+
|
|
291
|
+
**Additional features:**
|
|
292
|
+
- When writing to a file, the output filename is printed to stdout (e.g., "Compressed to: input.bin.zbe" or "Decompressed to: output.bin")
|
|
293
|
+
- Verbose statistics are shown by default (use `--no-verbose` to disable) and include descriptive messages about compression/decompression ratios
|
|
294
|
+
- Compression will exit with an error if the data cannot be compressed (when using `--endian best` and neither method produces compression)
|
|
295
|
+
- A warning is shown when reading from stdin if no data was piped in
|
|
159
296
|
|
|
160
297
|
### Main Playground
|
|
161
298
|
|
|
162
299
|
```bash
|
|
163
|
-
cargo run --release --bin
|
|
300
|
+
cargo run --release --bin zeck
|
|
164
301
|
```
|
|
165
302
|
|
|
166
303
|
A playground/scratchpad for testing library functions.
|
|
@@ -168,20 +305,20 @@ A playground/scratchpad for testing library functions.
|
|
|
168
305
|
### Generate Test Data
|
|
169
306
|
|
|
170
307
|
```bash
|
|
171
|
-
cargo run --release --bin
|
|
308
|
+
cargo run --release --bin zeck-generate-data --features development_tools -- <size_in_bytes> [filename]
|
|
172
309
|
```
|
|
173
310
|
|
|
174
311
|
Generates random test data files in the `generated_data/` directory.
|
|
175
312
|
|
|
176
313
|
Example:
|
|
177
314
|
```bash
|
|
178
|
-
cargo run --release --bin
|
|
315
|
+
cargo run --release --bin zeck-generate-data --features development_tools -- 1024 my_file.bin
|
|
179
316
|
```
|
|
180
317
|
|
|
181
318
|
### Generate Statistics
|
|
182
319
|
|
|
183
320
|
```bash
|
|
184
|
-
cargo run --release --bin
|
|
321
|
+
cargo run --release --bin zeck-generate-statistics --features plotting,development_tools
|
|
185
322
|
```
|
|
186
323
|
|
|
187
324
|
Generates comprehensive compression statistics and plots:
|
|
@@ -194,7 +331,7 @@ Generates comprehensive compression statistics and plots:
|
|
|
194
331
|
### Plot Compression Ratios
|
|
195
332
|
|
|
196
333
|
```bash
|
|
197
|
-
cargo run --release --bin plot --features plotting
|
|
334
|
+
cargo run --release --bin zeck-plot --features plotting,development_tools
|
|
198
335
|
```
|
|
199
336
|
|
|
200
337
|
Generates visualization plots of:
|
|
@@ -269,7 +406,7 @@ This avoids redundant Fibonacci numbers (F(0)=0 and F(1)=F(2)=1).
|
|
|
269
406
|
- Compression is not guaranteed—some inputs may result in larger output
|
|
270
407
|
- Compression effectiveness decreases as input size increases
|
|
271
408
|
- The library supports both big-endian and little-endian interpretations, but other byte orderings or word boundaries are not currently explored
|
|
272
|
-
-
|
|
409
|
+
- **⚠️ Warning:** Compressing or decompressing files larger than 10KB (10,000 bytes) is unstable due to time and memory pressure. The library may experience performance issues, excessive memory usage, or failures when processing files exceeding this size.
|
|
273
410
|
|
|
274
411
|
## License
|
|
275
412
|
|
package/package.json
CHANGED
|
@@ -5,23 +5,23 @@
|
|
|
5
5
|
"Peter Ryszkiewicz"
|
|
6
6
|
],
|
|
7
7
|
"description": "A Rust library for compressing and decompressing data using the Zeckendorf representation algorithm",
|
|
8
|
-
"version": "
|
|
8
|
+
"version": "1.0.7",
|
|
9
9
|
"license": "MIT",
|
|
10
10
|
"repository": {
|
|
11
11
|
"type": "git",
|
|
12
|
-
"url": "https://github.com/pRizz/zeckendorf"
|
|
12
|
+
"url": "https://github.com/pRizz/zeckendorf.git"
|
|
13
13
|
},
|
|
14
14
|
"files": [
|
|
15
|
-
"
|
|
16
|
-
"
|
|
17
|
-
"
|
|
18
|
-
"
|
|
15
|
+
"zeck_bg.wasm",
|
|
16
|
+
"zeck.js",
|
|
17
|
+
"zeck_bg.js",
|
|
18
|
+
"zeck.d.ts",
|
|
19
19
|
"LICENSE.txt"
|
|
20
20
|
],
|
|
21
|
-
"main": "
|
|
22
|
-
"types": "
|
|
21
|
+
"main": "zeck.js",
|
|
22
|
+
"types": "zeck.d.ts",
|
|
23
23
|
"sideEffects": [
|
|
24
|
-
"./
|
|
24
|
+
"./zeck.js",
|
|
25
25
|
"./snippets/*"
|
|
26
26
|
],
|
|
27
27
|
"keywords": [
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* # Examples
|
|
8
8
|
*
|
|
9
9
|
* ```
|
|
10
|
-
* # use
|
|
10
|
+
* # use zeck::bit_count_for_number;
|
|
11
11
|
* assert_eq!(bit_count_for_number(0), 0);
|
|
12
12
|
* assert_eq!(bit_count_for_number(1), 1); // 0b1
|
|
13
13
|
* assert_eq!(bit_count_for_number(2), 2); // 0b10
|
|
@@ -23,7 +23,7 @@ export function bit_count_for_number(n: number): number;
|
|
|
23
23
|
* # Examples
|
|
24
24
|
*
|
|
25
25
|
* ```
|
|
26
|
-
* # use
|
|
26
|
+
* # use zeck::efi_to_fi;
|
|
27
27
|
* assert_eq!(efi_to_fi(0), 2);
|
|
28
28
|
* assert_eq!(efi_to_fi(1), 3);
|
|
29
29
|
* assert_eq!(efi_to_fi(2), 4);
|
|
@@ -45,7 +45,7 @@ export function efi_to_fi(efi: bigint): bigint;
|
|
|
45
45
|
* # Examples
|
|
46
46
|
*
|
|
47
47
|
* ```
|
|
48
|
-
* # use
|
|
48
|
+
* # use zeck::ezba_from_ezld;
|
|
49
49
|
* assert_eq!(ezba_from_ezld(&[]), vec![0]);
|
|
50
50
|
* assert_eq!(ezba_from_ezld(&[0]), vec![1]); // 0th EFI is 2nd FI, which is 1
|
|
51
51
|
* assert_eq!(ezba_from_ezld(&[1]), vec![0, 1]); // 1st EFI is 3rd FI, which is 2
|
|
@@ -63,7 +63,7 @@ export function ezba_from_ezld(effective_zeckendorf_list_descending: BigUint64Ar
|
|
|
63
63
|
* # Examples
|
|
64
64
|
*
|
|
65
65
|
* ```
|
|
66
|
-
* # use
|
|
66
|
+
* # use zeck::ezba_to_ezla;
|
|
67
67
|
* assert_eq!(ezba_to_ezla(&[0, 0, 0, 0, 0, 0, 0, 0]), vec![]);
|
|
68
68
|
* assert_eq!(ezba_to_ezla(&[1, 0, 0, 0, 0, 0, 0, 0]), vec![0]);
|
|
69
69
|
* assert_eq!(ezba_to_ezla(&[1, 1, 1, 0, 0, 0, 0, 0]), vec![0, 2, 4]);
|
|
@@ -78,7 +78,7 @@ export function ezba_to_ezla(ezba_bits: Uint8Array): BigUint64Array;
|
|
|
78
78
|
* # Examples
|
|
79
79
|
*
|
|
80
80
|
* ```
|
|
81
|
-
* # use
|
|
81
|
+
* # use zeck::ezl_to_zl;
|
|
82
82
|
* assert_eq!(ezl_to_zl(&[0]), vec![2]);
|
|
83
83
|
* assert_eq!(ezl_to_zl(&[1]), vec![3]);
|
|
84
84
|
* assert_eq!(ezl_to_zl(&[2]), vec![4]);
|
|
@@ -92,7 +92,7 @@ export function ezl_to_zl(ezl: BigUint64Array): BigUint64Array;
|
|
|
92
92
|
* # Examples
|
|
93
93
|
*
|
|
94
94
|
* ```
|
|
95
|
-
* # use
|
|
95
|
+
* # use zeck::fi_to_efi;
|
|
96
96
|
* # use num_bigint::BigUint;
|
|
97
97
|
* # use num_traits::{One, Zero};
|
|
98
98
|
* assert_eq!(fi_to_efi(2), 0);
|
|
@@ -108,7 +108,7 @@ export function fi_to_efi(fi: bigint): bigint;
|
|
|
108
108
|
* # Examples
|
|
109
109
|
*
|
|
110
110
|
* ```
|
|
111
|
-
* # use
|
|
111
|
+
* # use zeck::highest_one_bit;
|
|
112
112
|
* assert_eq!(highest_one_bit(0), 0);
|
|
113
113
|
* assert_eq!(highest_one_bit(1), 1);
|
|
114
114
|
* assert_eq!(highest_one_bit(2), 2);
|
|
@@ -134,7 +134,7 @@ export function highest_one_bit(n: bigint): bigint;
|
|
|
134
134
|
* # Examples
|
|
135
135
|
*
|
|
136
136
|
* ```
|
|
137
|
-
* # use
|
|
137
|
+
* # use zeck::memoized_effective_fibonacci;
|
|
138
138
|
* # use num_bigint::BigUint;
|
|
139
139
|
* # use num_traits::{One, Zero};
|
|
140
140
|
* assert_eq!(memoized_effective_fibonacci(0), 1);
|
|
@@ -164,7 +164,7 @@ export function memoized_effective_fibonacci(efi: bigint): bigint;
|
|
|
164
164
|
* # Examples
|
|
165
165
|
*
|
|
166
166
|
* ```
|
|
167
|
-
* # use
|
|
167
|
+
* # use zeck::memoized_slow_fibonacci_recursive;
|
|
168
168
|
* // Base cases
|
|
169
169
|
* assert_eq!(memoized_slow_fibonacci_recursive(0), 0);
|
|
170
170
|
* assert_eq!(memoized_slow_fibonacci_recursive(1), 1);
|
|
@@ -192,7 +192,7 @@ export function memoized_slow_fibonacci_recursive(fi: bigint): bigint;
|
|
|
192
192
|
* # Examples
|
|
193
193
|
*
|
|
194
194
|
* ```
|
|
195
|
-
* # use
|
|
195
|
+
* # use zeck::memoized_zeckendorf_list_descending_for_integer;
|
|
196
196
|
* // Base cases
|
|
197
197
|
* assert_eq!(memoized_zeckendorf_list_descending_for_integer(0), vec![]);
|
|
198
198
|
* assert_eq!(memoized_zeckendorf_list_descending_for_integer(1), vec![2]);
|
|
@@ -225,7 +225,7 @@ export function memoized_zeckendorf_list_descending_for_integer(n: bigint): BigU
|
|
|
225
225
|
* # Examples
|
|
226
226
|
*
|
|
227
227
|
* ```
|
|
228
|
-
* # use
|
|
228
|
+
* # use zeck::pack_ezba_bits_to_bytes;
|
|
229
229
|
* assert_eq!(pack_ezba_bits_to_bytes(&[0]), vec![0]);
|
|
230
230
|
* assert_eq!(pack_ezba_bits_to_bytes(&[1]), vec![1]);
|
|
231
231
|
* assert_eq!(pack_ezba_bits_to_bytes(&[0, 1]), vec![0b10]);
|
|
@@ -241,7 +241,7 @@ export function pack_ezba_bits_to_bytes(ezba: Uint8Array): Uint8Array;
|
|
|
241
241
|
* # Examples
|
|
242
242
|
*
|
|
243
243
|
* ```
|
|
244
|
-
* # use
|
|
244
|
+
* # use zeck::unpack_bytes_to_ezba_bits;
|
|
245
245
|
* assert_eq!(unpack_bytes_to_ezba_bits(&[0]), vec![0, 0, 0, 0, 0, 0, 0, 0]);
|
|
246
246
|
* assert_eq!(unpack_bytes_to_ezba_bits(&[1]), vec![1, 0, 0, 0, 0, 0, 0, 0]);
|
|
247
247
|
* assert_eq!(unpack_bytes_to_ezba_bits(&[0b111]), vec![1, 1, 1, 0, 0, 0, 0, 0]);
|
|
@@ -255,76 +255,96 @@ export function unpack_bytes_to_ezba_bits(bytes: Uint8Array): Uint8Array;
|
|
|
255
255
|
*
|
|
256
256
|
* Assumes the input data is interpreted as a big endian integer. The output data is in little endian order, so the first bit and byte is the least significant bit and byte and the last bit and byte is the most significant bit and byte.
|
|
257
257
|
*
|
|
258
|
+
* # ⚠️ Warning
|
|
259
|
+
*
|
|
260
|
+
* **Compressing or decompressing data larger than 10KB (10,000 bytes) is unstable due to time and memory pressure.**
|
|
261
|
+
* The library may experience performance issues, excessive memory usage, or failures when processing data exceeding this size.
|
|
262
|
+
*
|
|
258
263
|
* TODO: Technically, the way the input data is interpreted is arbitrary; we could interpret it as little endian which could result in a more compact representation. We could go even further and interpret the data at different byte or word boundaries to see if it results in a more compact representation, and signify to the caller which interpretation was used. We probably need a better understanding of random distributions of data to determine what is the optimal interpretation. More investigation is needed here.
|
|
259
264
|
*
|
|
260
265
|
* # Examples
|
|
261
266
|
*
|
|
262
267
|
* ```
|
|
263
|
-
* # use
|
|
264
|
-
* assert_eq!(
|
|
265
|
-
* assert_eq!(
|
|
266
|
-
* assert_eq!(
|
|
267
|
-
* assert_eq!(
|
|
268
|
-
* assert_eq!(
|
|
269
|
-
* assert_eq!(
|
|
270
|
-
* assert_eq!(
|
|
268
|
+
* # use zeck::zeckendorf_compress_be_broken_do_not_use;
|
|
269
|
+
* assert_eq!(zeckendorf_compress_be_broken_do_not_use(&[0]), vec![0]);
|
|
270
|
+
* assert_eq!(zeckendorf_compress_be_broken_do_not_use(&[1]), vec![1]);
|
|
271
|
+
* assert_eq!(zeckendorf_compress_be_broken_do_not_use(&[12]), vec![0b111]);
|
|
272
|
+
* assert_eq!(zeckendorf_compress_be_broken_do_not_use(&[54]), vec![30]);
|
|
273
|
+
* assert_eq!(zeckendorf_compress_be_broken_do_not_use(&[55]), vec![0, 1]); // 55 is the 10 indexed Fibonacci number, which is the 8 indexed effective Fibonacci number, and therefore is the first number needing two bytes to contain these 8 bits, because there is 1 "use bit" and 7 "skip bits" in the effective zeckendorf bits ascending.
|
|
274
|
+
* assert_eq!(zeckendorf_compress_be_broken_do_not_use(&[255]), vec![33, 2]);
|
|
275
|
+
* assert_eq!(zeckendorf_compress_be_broken_do_not_use(&[1, 0]), vec![34, 2]);
|
|
271
276
|
* ```
|
|
272
277
|
*/
|
|
273
|
-
export function
|
|
278
|
+
export function zeckendorf_compress_be_broken_do_not_use(data: Uint8Array): Uint8Array;
|
|
274
279
|
|
|
275
280
|
/**
|
|
276
281
|
* Compresses a slice of bytes using the Zeckendorf algorithm.
|
|
277
282
|
*
|
|
278
283
|
* Assumes the input data is interpreted as a little endian integer. The output data is in little endian order, so the first bit and byte is the least significant bit and byte and the last bit and byte is the most significant bit and byte.
|
|
279
284
|
*
|
|
285
|
+
* # ⚠️ Warning
|
|
286
|
+
*
|
|
287
|
+
* **Compressing or decompressing data larger than 10KB (10,000 bytes) is unstable due to time and memory pressure.**
|
|
288
|
+
* The library may experience performance issues, excessive memory usage, or failures when processing data exceeding this size.
|
|
289
|
+
*
|
|
280
290
|
* # Examples
|
|
281
291
|
*
|
|
282
292
|
* ```
|
|
283
|
-
* # use
|
|
284
|
-
* assert_eq!(
|
|
285
|
-
* assert_eq!(
|
|
286
|
-
* assert_eq!(
|
|
287
|
-
* assert_eq!(
|
|
288
|
-
* assert_eq!(
|
|
289
|
-
* assert_eq!(
|
|
290
|
-
* assert_eq!(
|
|
293
|
+
* # use zeck::zeckendorf_compress_le_broken_do_not_use;
|
|
294
|
+
* assert_eq!(zeckendorf_compress_le_broken_do_not_use(&[0]), vec![0]);
|
|
295
|
+
* assert_eq!(zeckendorf_compress_le_broken_do_not_use(&[1]), vec![1]);
|
|
296
|
+
* assert_eq!(zeckendorf_compress_le_broken_do_not_use(&[12]), vec![0b111]);
|
|
297
|
+
* assert_eq!(zeckendorf_compress_le_broken_do_not_use(&[54]), vec![30]);
|
|
298
|
+
* assert_eq!(zeckendorf_compress_le_broken_do_not_use(&[55]), vec![0, 1]); // 55 is the 10 indexed Fibonacci number, which is the 8 indexed effective Fibonacci number, and therefore is the first number needing two bytes to contain these 8 bits, because there is 1 "use bit" and 7 "skip bits" in the effective zeckendorf bits ascending.
|
|
299
|
+
* assert_eq!(zeckendorf_compress_le_broken_do_not_use(&[255]), vec![33, 2]);
|
|
300
|
+
* assert_eq!(zeckendorf_compress_le_broken_do_not_use(&[0, 1]), vec![34, 2]);
|
|
291
301
|
* ```
|
|
292
302
|
*/
|
|
293
|
-
export function
|
|
303
|
+
export function zeckendorf_compress_le_broken_do_not_use(data: Uint8Array): Uint8Array;
|
|
294
304
|
|
|
295
305
|
/**
|
|
296
306
|
* Decompresses a slice of bytes compressed using the Zeckendorf algorithm, assuming the original data was compressed using the big endian bytes interpretation.
|
|
297
307
|
*
|
|
298
308
|
* Assume the original input data was interpreted as a big endian integer, for now. See the TODO in the [`zeckendorf_compress_be`] function for more information.
|
|
299
309
|
*
|
|
310
|
+
* # ⚠️ Warning
|
|
311
|
+
*
|
|
312
|
+
* **Compressing or decompressing data larger than 10KB (10,000 bytes) is unstable due to time and memory pressure.**
|
|
313
|
+
* The library may experience performance issues, excessive memory usage, or failures when processing data exceeding this size.
|
|
314
|
+
*
|
|
300
315
|
* # Examples
|
|
301
316
|
*
|
|
302
317
|
* ```
|
|
303
|
-
* # use
|
|
304
|
-
* assert_eq!(
|
|
305
|
-
* assert_eq!(
|
|
306
|
-
* assert_eq!(
|
|
307
|
-
* assert_eq!(
|
|
308
|
-
* assert_eq!(
|
|
318
|
+
* # use zeck::zeckendorf_decompress_be_broken_do_not_use;
|
|
319
|
+
* assert_eq!(zeckendorf_decompress_be_broken_do_not_use(&[0]), vec![0]);
|
|
320
|
+
* assert_eq!(zeckendorf_decompress_be_broken_do_not_use(&[1]), vec![1]);
|
|
321
|
+
* assert_eq!(zeckendorf_decompress_be_broken_do_not_use(&[0b111]), vec![12]);
|
|
322
|
+
* assert_eq!(zeckendorf_decompress_be_broken_do_not_use(&[33, 2]), vec![255]);
|
|
323
|
+
* assert_eq!(zeckendorf_decompress_be_broken_do_not_use(&[34, 2]), vec![1, 0]);
|
|
309
324
|
* ```
|
|
310
325
|
*/
|
|
311
|
-
export function
|
|
326
|
+
export function zeckendorf_decompress_be_broken_do_not_use(compressed_data: Uint8Array): Uint8Array;
|
|
312
327
|
|
|
313
328
|
/**
|
|
314
329
|
* Decompresses a slice of bytes compressed using the Zeckendorf algorithm, assuming the original data was compressed using the little endian bytes interpretation.
|
|
315
330
|
*
|
|
331
|
+
* # ⚠️ Warning
|
|
332
|
+
*
|
|
333
|
+
* **Compressing or decompressing data larger than 10KB (10,000 bytes) is unstable due to time and memory pressure.**
|
|
334
|
+
* The library may experience performance issues, excessive memory usage, or failures when processing data exceeding this size.
|
|
335
|
+
*
|
|
316
336
|
* # Examples
|
|
317
337
|
*
|
|
318
338
|
* ```
|
|
319
|
-
* # use
|
|
320
|
-
* assert_eq!(
|
|
321
|
-
* assert_eq!(
|
|
322
|
-
* assert_eq!(
|
|
323
|
-
* assert_eq!(
|
|
324
|
-
* assert_eq!(
|
|
339
|
+
* # use zeck::zeckendorf_decompress_le_broken_do_not_use;
|
|
340
|
+
* assert_eq!(zeckendorf_decompress_le_broken_do_not_use(&[0]), vec![0]);
|
|
341
|
+
* assert_eq!(zeckendorf_decompress_le_broken_do_not_use(&[1]), vec![1]);
|
|
342
|
+
* assert_eq!(zeckendorf_decompress_le_broken_do_not_use(&[0b111]), vec![12]);
|
|
343
|
+
* assert_eq!(zeckendorf_decompress_le_broken_do_not_use(&[33, 2]), vec![255]);
|
|
344
|
+
* assert_eq!(zeckendorf_decompress_le_broken_do_not_use(&[34, 2]), vec![0, 1]);
|
|
325
345
|
* ```
|
|
326
346
|
*/
|
|
327
|
-
export function
|
|
347
|
+
export function zeckendorf_decompress_le_broken_do_not_use(compressed_data: Uint8Array): Uint8Array;
|
|
328
348
|
|
|
329
349
|
/**
|
|
330
350
|
* An Effective Zeckendorf List (EZL) has a lowest EFI of 0, which is an FI of 2.
|
|
@@ -337,7 +357,7 @@ export function zeckendorf_decompress_le(compressed_data: Uint8Array): Uint8Arra
|
|
|
337
357
|
* # Examples
|
|
338
358
|
*
|
|
339
359
|
* ```
|
|
340
|
-
* # use
|
|
360
|
+
* # use zeck::zl_to_ezl;
|
|
341
361
|
* assert_eq!(zl_to_ezl(&[2]), vec![0]);
|
|
342
362
|
* assert_eq!(zl_to_ezl(&[3]), vec![1]);
|
|
343
363
|
* assert_eq!(zl_to_ezl(&[4]), vec![2]);
|
package/zeck.js
ADDED
|
@@ -51,7 +51,7 @@ let WASM_VECTOR_LEN = 0;
|
|
|
51
51
|
* # Examples
|
|
52
52
|
*
|
|
53
53
|
* ```
|
|
54
|
-
* # use
|
|
54
|
+
* # use zeck::bit_count_for_number;
|
|
55
55
|
* assert_eq!(bit_count_for_number(0), 0);
|
|
56
56
|
* assert_eq!(bit_count_for_number(1), 1); // 0b1
|
|
57
57
|
* assert_eq!(bit_count_for_number(2), 2); // 0b10
|
|
@@ -72,7 +72,7 @@ export function bit_count_for_number(n) {
|
|
|
72
72
|
* # Examples
|
|
73
73
|
*
|
|
74
74
|
* ```
|
|
75
|
-
* # use
|
|
75
|
+
* # use zeck::efi_to_fi;
|
|
76
76
|
* assert_eq!(efi_to_fi(0), 2);
|
|
77
77
|
* assert_eq!(efi_to_fi(1), 3);
|
|
78
78
|
* assert_eq!(efi_to_fi(2), 4);
|
|
@@ -99,7 +99,7 @@ export function efi_to_fi(efi) {
|
|
|
99
99
|
* # Examples
|
|
100
100
|
*
|
|
101
101
|
* ```
|
|
102
|
-
* # use
|
|
102
|
+
* # use zeck::ezba_from_ezld;
|
|
103
103
|
* assert_eq!(ezba_from_ezld(&[]), vec![0]);
|
|
104
104
|
* assert_eq!(ezba_from_ezld(&[0]), vec![1]); // 0th EFI is 2nd FI, which is 1
|
|
105
105
|
* assert_eq!(ezba_from_ezld(&[1]), vec![0, 1]); // 1st EFI is 3rd FI, which is 2
|
|
@@ -126,7 +126,7 @@ export function ezba_from_ezld(effective_zeckendorf_list_descending) {
|
|
|
126
126
|
* # Examples
|
|
127
127
|
*
|
|
128
128
|
* ```
|
|
129
|
-
* # use
|
|
129
|
+
* # use zeck::ezba_to_ezla;
|
|
130
130
|
* assert_eq!(ezba_to_ezla(&[0, 0, 0, 0, 0, 0, 0, 0]), vec![]);
|
|
131
131
|
* assert_eq!(ezba_to_ezla(&[1, 0, 0, 0, 0, 0, 0, 0]), vec![0]);
|
|
132
132
|
* assert_eq!(ezba_to_ezla(&[1, 1, 1, 0, 0, 0, 0, 0]), vec![0, 2, 4]);
|
|
@@ -150,7 +150,7 @@ export function ezba_to_ezla(ezba_bits) {
|
|
|
150
150
|
* # Examples
|
|
151
151
|
*
|
|
152
152
|
* ```
|
|
153
|
-
* # use
|
|
153
|
+
* # use zeck::ezl_to_zl;
|
|
154
154
|
* assert_eq!(ezl_to_zl(&[0]), vec![2]);
|
|
155
155
|
* assert_eq!(ezl_to_zl(&[1]), vec![3]);
|
|
156
156
|
* assert_eq!(ezl_to_zl(&[2]), vec![4]);
|
|
@@ -173,7 +173,7 @@ export function ezl_to_zl(ezl) {
|
|
|
173
173
|
* # Examples
|
|
174
174
|
*
|
|
175
175
|
* ```
|
|
176
|
-
* # use
|
|
176
|
+
* # use zeck::fi_to_efi;
|
|
177
177
|
* # use num_bigint::BigUint;
|
|
178
178
|
* # use num_traits::{One, Zero};
|
|
179
179
|
* assert_eq!(fi_to_efi(2), 0);
|
|
@@ -194,7 +194,7 @@ export function fi_to_efi(fi) {
|
|
|
194
194
|
* # Examples
|
|
195
195
|
*
|
|
196
196
|
* ```
|
|
197
|
-
* # use
|
|
197
|
+
* # use zeck::highest_one_bit;
|
|
198
198
|
* assert_eq!(highest_one_bit(0), 0);
|
|
199
199
|
* assert_eq!(highest_one_bit(1), 1);
|
|
200
200
|
* assert_eq!(highest_one_bit(2), 2);
|
|
@@ -225,7 +225,7 @@ export function highest_one_bit(n) {
|
|
|
225
225
|
* # Examples
|
|
226
226
|
*
|
|
227
227
|
* ```
|
|
228
|
-
* # use
|
|
228
|
+
* # use zeck::memoized_effective_fibonacci;
|
|
229
229
|
* # use num_bigint::BigUint;
|
|
230
230
|
* # use num_traits::{One, Zero};
|
|
231
231
|
* assert_eq!(memoized_effective_fibonacci(0), 1);
|
|
@@ -260,7 +260,7 @@ export function memoized_effective_fibonacci(efi) {
|
|
|
260
260
|
* # Examples
|
|
261
261
|
*
|
|
262
262
|
* ```
|
|
263
|
-
* # use
|
|
263
|
+
* # use zeck::memoized_slow_fibonacci_recursive;
|
|
264
264
|
* // Base cases
|
|
265
265
|
* assert_eq!(memoized_slow_fibonacci_recursive(0), 0);
|
|
266
266
|
* assert_eq!(memoized_slow_fibonacci_recursive(1), 1);
|
|
@@ -293,7 +293,7 @@ export function memoized_slow_fibonacci_recursive(fi) {
|
|
|
293
293
|
* # Examples
|
|
294
294
|
*
|
|
295
295
|
* ```
|
|
296
|
-
* # use
|
|
296
|
+
* # use zeck::memoized_zeckendorf_list_descending_for_integer;
|
|
297
297
|
* // Base cases
|
|
298
298
|
* assert_eq!(memoized_zeckendorf_list_descending_for_integer(0), vec![]);
|
|
299
299
|
* assert_eq!(memoized_zeckendorf_list_descending_for_integer(1), vec![2]);
|
|
@@ -333,7 +333,7 @@ export function memoized_zeckendorf_list_descending_for_integer(n) {
|
|
|
333
333
|
* # Examples
|
|
334
334
|
*
|
|
335
335
|
* ```
|
|
336
|
-
* # use
|
|
336
|
+
* # use zeck::pack_ezba_bits_to_bytes;
|
|
337
337
|
* assert_eq!(pack_ezba_bits_to_bytes(&[0]), vec![0]);
|
|
338
338
|
* assert_eq!(pack_ezba_bits_to_bytes(&[1]), vec![1]);
|
|
339
339
|
* assert_eq!(pack_ezba_bits_to_bytes(&[0, 1]), vec![0b10]);
|
|
@@ -358,7 +358,7 @@ export function pack_ezba_bits_to_bytes(ezba) {
|
|
|
358
358
|
* # Examples
|
|
359
359
|
*
|
|
360
360
|
* ```
|
|
361
|
-
* # use
|
|
361
|
+
* # use zeck::unpack_bytes_to_ezba_bits;
|
|
362
362
|
* assert_eq!(unpack_bytes_to_ezba_bits(&[0]), vec![0, 0, 0, 0, 0, 0, 0, 0]);
|
|
363
363
|
* assert_eq!(unpack_bytes_to_ezba_bits(&[1]), vec![1, 0, 0, 0, 0, 0, 0, 0]);
|
|
364
364
|
* assert_eq!(unpack_bytes_to_ezba_bits(&[0b111]), vec![1, 1, 1, 0, 0, 0, 0, 0]);
|
|
@@ -381,27 +381,32 @@ export function unpack_bytes_to_ezba_bits(bytes) {
|
|
|
381
381
|
*
|
|
382
382
|
* Assumes the input data is interpreted as a big endian integer. The output data is in little endian order, so the first bit and byte is the least significant bit and byte and the last bit and byte is the most significant bit and byte.
|
|
383
383
|
*
|
|
384
|
+
* # ⚠️ Warning
|
|
385
|
+
*
|
|
386
|
+
* **Compressing or decompressing data larger than 10KB (10,000 bytes) is unstable due to time and memory pressure.**
|
|
387
|
+
* The library may experience performance issues, excessive memory usage, or failures when processing data exceeding this size.
|
|
388
|
+
*
|
|
384
389
|
* TODO: Technically, the way the input data is interpreted is arbitrary; we could interpret it as little endian which could result in a more compact representation. We could go even further and interpret the data at different byte or word boundaries to see if it results in a more compact representation, and signify to the caller which interpretation was used. We probably need a better understanding of random distributions of data to determine what is the optimal interpretation. More investigation is needed here.
|
|
385
390
|
*
|
|
386
391
|
* # Examples
|
|
387
392
|
*
|
|
388
393
|
* ```
|
|
389
|
-
* # use
|
|
390
|
-
* assert_eq!(
|
|
391
|
-
* assert_eq!(
|
|
392
|
-
* assert_eq!(
|
|
393
|
-
* assert_eq!(
|
|
394
|
-
* assert_eq!(
|
|
395
|
-
* assert_eq!(
|
|
396
|
-
* assert_eq!(
|
|
394
|
+
* # use zeck::zeckendorf_compress_be_broken_do_not_use;
|
|
395
|
+
* assert_eq!(zeckendorf_compress_be_broken_do_not_use(&[0]), vec![0]);
|
|
396
|
+
* assert_eq!(zeckendorf_compress_be_broken_do_not_use(&[1]), vec![1]);
|
|
397
|
+
* assert_eq!(zeckendorf_compress_be_broken_do_not_use(&[12]), vec![0b111]);
|
|
398
|
+
* assert_eq!(zeckendorf_compress_be_broken_do_not_use(&[54]), vec![30]);
|
|
399
|
+
* assert_eq!(zeckendorf_compress_be_broken_do_not_use(&[55]), vec![0, 1]); // 55 is the 10 indexed Fibonacci number, which is the 8 indexed effective Fibonacci number, and therefore is the first number needing two bytes to contain these 8 bits, because there is 1 "use bit" and 7 "skip bits" in the effective zeckendorf bits ascending.
|
|
400
|
+
* assert_eq!(zeckendorf_compress_be_broken_do_not_use(&[255]), vec![33, 2]);
|
|
401
|
+
* assert_eq!(zeckendorf_compress_be_broken_do_not_use(&[1, 0]), vec![34, 2]);
|
|
397
402
|
* ```
|
|
398
403
|
* @param {Uint8Array} data
|
|
399
404
|
* @returns {Uint8Array}
|
|
400
405
|
*/
|
|
401
|
-
export function
|
|
406
|
+
export function zeckendorf_compress_be_broken_do_not_use(data) {
|
|
402
407
|
const ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_malloc);
|
|
403
408
|
const len0 = WASM_VECTOR_LEN;
|
|
404
|
-
const ret = wasm.
|
|
409
|
+
const ret = wasm.zeckendorf_compress_be_broken_do_not_use(ptr0, len0);
|
|
405
410
|
var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
406
411
|
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
407
412
|
return v2;
|
|
@@ -412,25 +417,30 @@ export function zeckendorf_compress_be(data) {
|
|
|
412
417
|
*
|
|
413
418
|
* Assumes the input data is interpreted as a little endian integer. The output data is in little endian order, so the first bit and byte is the least significant bit and byte and the last bit and byte is the most significant bit and byte.
|
|
414
419
|
*
|
|
420
|
+
* # ⚠️ Warning
|
|
421
|
+
*
|
|
422
|
+
* **Compressing or decompressing data larger than 10KB (10,000 bytes) is unstable due to time and memory pressure.**
|
|
423
|
+
* The library may experience performance issues, excessive memory usage, or failures when processing data exceeding this size.
|
|
424
|
+
*
|
|
415
425
|
* # Examples
|
|
416
426
|
*
|
|
417
427
|
* ```
|
|
418
|
-
* # use
|
|
419
|
-
* assert_eq!(
|
|
420
|
-
* assert_eq!(
|
|
421
|
-
* assert_eq!(
|
|
422
|
-
* assert_eq!(
|
|
423
|
-
* assert_eq!(
|
|
424
|
-
* assert_eq!(
|
|
425
|
-
* assert_eq!(
|
|
428
|
+
* # use zeck::zeckendorf_compress_le_broken_do_not_use;
|
|
429
|
+
* assert_eq!(zeckendorf_compress_le_broken_do_not_use(&[0]), vec![0]);
|
|
430
|
+
* assert_eq!(zeckendorf_compress_le_broken_do_not_use(&[1]), vec![1]);
|
|
431
|
+
* assert_eq!(zeckendorf_compress_le_broken_do_not_use(&[12]), vec![0b111]);
|
|
432
|
+
* assert_eq!(zeckendorf_compress_le_broken_do_not_use(&[54]), vec![30]);
|
|
433
|
+
* assert_eq!(zeckendorf_compress_le_broken_do_not_use(&[55]), vec![0, 1]); // 55 is the 10 indexed Fibonacci number, which is the 8 indexed effective Fibonacci number, and therefore is the first number needing two bytes to contain these 8 bits, because there is 1 "use bit" and 7 "skip bits" in the effective zeckendorf bits ascending.
|
|
434
|
+
* assert_eq!(zeckendorf_compress_le_broken_do_not_use(&[255]), vec![33, 2]);
|
|
435
|
+
* assert_eq!(zeckendorf_compress_le_broken_do_not_use(&[0, 1]), vec![34, 2]);
|
|
426
436
|
* ```
|
|
427
437
|
* @param {Uint8Array} data
|
|
428
438
|
* @returns {Uint8Array}
|
|
429
439
|
*/
|
|
430
|
-
export function
|
|
440
|
+
export function zeckendorf_compress_le_broken_do_not_use(data) {
|
|
431
441
|
const ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_malloc);
|
|
432
442
|
const len0 = WASM_VECTOR_LEN;
|
|
433
|
-
const ret = wasm.
|
|
443
|
+
const ret = wasm.zeckendorf_compress_le_broken_do_not_use(ptr0, len0);
|
|
434
444
|
var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
435
445
|
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
436
446
|
return v2;
|
|
@@ -441,23 +451,28 @@ export function zeckendorf_compress_le(data) {
|
|
|
441
451
|
*
|
|
442
452
|
* Assume the original input data was interpreted as a big endian integer, for now. See the TODO in the [`zeckendorf_compress_be`] function for more information.
|
|
443
453
|
*
|
|
454
|
+
* # ⚠️ Warning
|
|
455
|
+
*
|
|
456
|
+
* **Compressing or decompressing data larger than 10KB (10,000 bytes) is unstable due to time and memory pressure.**
|
|
457
|
+
* The library may experience performance issues, excessive memory usage, or failures when processing data exceeding this size.
|
|
458
|
+
*
|
|
444
459
|
* # Examples
|
|
445
460
|
*
|
|
446
461
|
* ```
|
|
447
|
-
* # use
|
|
448
|
-
* assert_eq!(
|
|
449
|
-
* assert_eq!(
|
|
450
|
-
* assert_eq!(
|
|
451
|
-
* assert_eq!(
|
|
452
|
-
* assert_eq!(
|
|
462
|
+
* # use zeck::zeckendorf_decompress_be_broken_do_not_use;
|
|
463
|
+
* assert_eq!(zeckendorf_decompress_be_broken_do_not_use(&[0]), vec![0]);
|
|
464
|
+
* assert_eq!(zeckendorf_decompress_be_broken_do_not_use(&[1]), vec![1]);
|
|
465
|
+
* assert_eq!(zeckendorf_decompress_be_broken_do_not_use(&[0b111]), vec![12]);
|
|
466
|
+
* assert_eq!(zeckendorf_decompress_be_broken_do_not_use(&[33, 2]), vec![255]);
|
|
467
|
+
* assert_eq!(zeckendorf_decompress_be_broken_do_not_use(&[34, 2]), vec![1, 0]);
|
|
453
468
|
* ```
|
|
454
469
|
* @param {Uint8Array} compressed_data
|
|
455
470
|
* @returns {Uint8Array}
|
|
456
471
|
*/
|
|
457
|
-
export function
|
|
472
|
+
export function zeckendorf_decompress_be_broken_do_not_use(compressed_data) {
|
|
458
473
|
const ptr0 = passArray8ToWasm0(compressed_data, wasm.__wbindgen_malloc);
|
|
459
474
|
const len0 = WASM_VECTOR_LEN;
|
|
460
|
-
const ret = wasm.
|
|
475
|
+
const ret = wasm.zeckendorf_decompress_be_broken_do_not_use(ptr0, len0);
|
|
461
476
|
var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
462
477
|
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
463
478
|
return v2;
|
|
@@ -466,23 +481,28 @@ export function zeckendorf_decompress_be(compressed_data) {
|
|
|
466
481
|
/**
|
|
467
482
|
* Decompresses a slice of bytes compressed using the Zeckendorf algorithm, assuming the original data was compressed using the little endian bytes interpretation.
|
|
468
483
|
*
|
|
484
|
+
* # ⚠️ Warning
|
|
485
|
+
*
|
|
486
|
+
* **Compressing or decompressing data larger than 10KB (10,000 bytes) is unstable due to time and memory pressure.**
|
|
487
|
+
* The library may experience performance issues, excessive memory usage, or failures when processing data exceeding this size.
|
|
488
|
+
*
|
|
469
489
|
* # Examples
|
|
470
490
|
*
|
|
471
491
|
* ```
|
|
472
|
-
* # use
|
|
473
|
-
* assert_eq!(
|
|
474
|
-
* assert_eq!(
|
|
475
|
-
* assert_eq!(
|
|
476
|
-
* assert_eq!(
|
|
477
|
-
* assert_eq!(
|
|
492
|
+
* # use zeck::zeckendorf_decompress_le_broken_do_not_use;
|
|
493
|
+
* assert_eq!(zeckendorf_decompress_le_broken_do_not_use(&[0]), vec![0]);
|
|
494
|
+
* assert_eq!(zeckendorf_decompress_le_broken_do_not_use(&[1]), vec![1]);
|
|
495
|
+
* assert_eq!(zeckendorf_decompress_le_broken_do_not_use(&[0b111]), vec![12]);
|
|
496
|
+
* assert_eq!(zeckendorf_decompress_le_broken_do_not_use(&[33, 2]), vec![255]);
|
|
497
|
+
* assert_eq!(zeckendorf_decompress_le_broken_do_not_use(&[34, 2]), vec![0, 1]);
|
|
478
498
|
* ```
|
|
479
499
|
* @param {Uint8Array} compressed_data
|
|
480
500
|
* @returns {Uint8Array}
|
|
481
501
|
*/
|
|
482
|
-
export function
|
|
502
|
+
export function zeckendorf_decompress_le_broken_do_not_use(compressed_data) {
|
|
483
503
|
const ptr0 = passArray8ToWasm0(compressed_data, wasm.__wbindgen_malloc);
|
|
484
504
|
const len0 = WASM_VECTOR_LEN;
|
|
485
|
-
const ret = wasm.
|
|
505
|
+
const ret = wasm.zeckendorf_decompress_le_broken_do_not_use(ptr0, len0);
|
|
486
506
|
var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
487
507
|
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
488
508
|
return v2;
|
|
@@ -499,7 +519,7 @@ export function zeckendorf_decompress_le(compressed_data) {
|
|
|
499
519
|
* # Examples
|
|
500
520
|
*
|
|
501
521
|
* ```
|
|
502
|
-
* # use
|
|
522
|
+
* # use zeck::zl_to_ezl;
|
|
503
523
|
* assert_eq!(zl_to_ezl(&[2]), vec![0]);
|
|
504
524
|
* assert_eq!(zl_to_ezl(&[3]), vec![1]);
|
|
505
525
|
* assert_eq!(zl_to_ezl(&[4]), vec![2]);
|
|
Binary file
|