Author SHA1 Message Date
Muse 580728135a Baseline: full corruption matrix results + pass-2 analysis
200 trials/setting on slice1m (-6 -e 4, t=8, single block):
scattered bits <=8 recover 200/200, 9/16/32 recover 0/200;
bursts: 1B 200/200, 2B 117-135/200, >=4B 0/200; silent-bad 0/2800.
Pass 2 is wired in (entry_decode -> bch_decode_candidates) but
rescues nothing beyond t at this block size — the gap the
deep-repair work must close. Also: harness gains MATRIX_ONLY /
MATRIX_WORKDIR for concurrent runs; docs/BASELINE.md section 7
notes the blocked hot_chicago run.
2026-12-02 13:47:01 +00:00
Muse 9690691907 Baseline: codebase survey, bench harness, corruption matrix, docs/BASELINE.md (matrix table TBD)
Survey + reproducible yardstick for the parallel ECC/compression
experiments: bench/bench.sh (ratio/speed/RSS), bench/corrupt_matrix.py
(200 trials/setting, scattered bits + bursts), docs/BASELINE.md with
the full codebase map, format summary, test results and the
enwik8/Silesia corpus checksums.
2026-12-02 11:39:49 +00:00
30 changed files with 468 additions and 2184 deletions

No files matched your search

-8
View File
@@ -14,11 +14,3 @@
/testdata/
/testwork/
/testwork-hyper/
# compression experiments (branch experiments/comp)
/experiments/corpora/
/experiments/rans_tool
/experiments/lzrans
/experiments/bwt
/experiments/ppm
/experiments/dict
/experiments/bchcheck
Executable
+43
View File
@@ -0,0 +1,43 @@
#!/bin/bash
# Baseline ratio / speed / memory benchmark for lzply (experiments/baseline).
# Usage: bench.sh <lzply-binary> <corpus-dir> <work-dir>
# Corpus dir: enwik8 + silesia files (see docs/BASELINE.md for checksums).
# Each setting: encode once, decode once, timed with /usr/bin/time -v
# (max RSS), sizes from stat. Clean round-trips verified bit-identical
# with diff -r (any mismatch is reported in the roundtrip field).
set -u
LZPLY="$1"; CORPUS="$2"; WORK="$3"
mkdir -p "$WORK"
cd "$WORK" || exit 1
( cd "$CORPUS" && sha256sum enwik8 dickens mozilla mr nci ooffice osdb reymont samba sao webster x-ray xml > "$WORK/corpus.sha256" )
echo "corpus total bytes: $(du -sb "$CORPUS" | cut -f1)"
run_one() { # run_one <label> <input-path> <lzply -c flags...>
local label="$1" input="$2"; shift 2
local arc="$WORK/$label.lzply" out="$WORK/$label.out"
rm -rf "$arc" "$out"
/usr/bin/time -v "$LZPLY" -c "$@" "$input" "$arc" > "$WORK/$label.enc.log" 2> "$WORK/$label.enc.time"
local enc_rc=$?
local enc_wall=$(grep "Elapsed (wall clock)" "$WORK/$label.enc.time" | awk '{print $NF}')
local enc_rss=$(grep "Maximum resident" "$WORK/$label.enc.time" | awk '{print $NF}')
local arc_size=$(stat -c%s "$arc" 2>/dev/null || echo 0)
/usr/bin/time -v "$LZPLY" -d -y "$arc" "$out" > "$WORK/$label.dec.log" 2> "$WORK/$label.dec.time"
local dec_rc=$?
local dec_wall=$(grep "Elapsed (wall clock)" "$WORK/$label.dec.time" | awk '{print $NF}')
local dec_rss=$(grep "Maximum resident" "$WORK/$label.dec.time" | awk '{print $NF}')
local rt="?"
if [ $dec_rc -eq 0 ]; then
if diff -r -q "$input" "$out/$(basename "$input")" > /dev/null 2>&1; then rt="IDENTICAL"; else rt="MISMATCH"; fi
else rt="DECODE-FAILED"; fi
echo "$label enc_rc=$enc_rc enc_wall=$enc_wall enc_maxrss_kb=$enc_rss arc_bytes=$arc_size dec_rc=$dec_rc dec_wall=$dec_wall dec_maxrss_kb=$dec_rss roundtrip=$rt"
}
run_one enwik8-l1 "$CORPUS/enwik8" -1 -e 4
run_one enwik8-l6 "$CORPUS/enwik8" -6 -e 4
run_one enwik8-l9 "$CORPUS/enwik8" -9 -e 4
run_one corpus-l6e4 "$CORPUS" -6 -e 4
run_one corpus-l6e0 "$CORPUS" -6 -e 0
run_one corpus-l6e7 "$CORPUS" -6 -e 7
run_one mozilla-l6 "$CORPUS/mozilla" -6 -e 4
echo DONE
+104
View File
@@ -0,0 +1,104 @@
#!/usr/bin/env python3
"""Corruption-matrix harness for lzply baseline (experiments/baseline).
Builds a single-entry archive of a 1 MiB text slice (default -6 -e 4),
then for each setting runs N trials: copy the archive, corrupt ONLY the
stored-data region (headers untouched), run `lzply -t`, and on success
also extract + verify SHA-256 of the recovered file. Reports
recovered / failed-loud / silent-bad counts per setting.
Settings:
scattered N bits: N in {1,2,4,8,9,16,32} random distinct bit positions
burst L bytes: L in {1,2,4,8,16} consecutive bytes replaced with
random bytes at a random offset (up to 8*L bit errors)
Usage: corrupt_matrix.py <lzply> <archive> <trials> [seed]
Archive must have exactly one file entry; data offset is parsed from
the v4 headers (global 16 + entry 78 + path_len).
Env: MATRIX_WORKDIR (default /tmp/lzply-matrix), MATRIX_ONLY
(comma list of kinds to run, default "bits,burst") — used to run
the burst settings as a second concurrent process with its own
workdir and seed while the bits run continues.
"""
import hashlib
import os
import random
import shutil
import struct
import subprocess
import sys
LZPLY, ARCHIVE, TRIALS = sys.argv[1], sys.argv[2], int(sys.argv[3])
SEED = int(sys.argv[4]) if len(sys.argv) > 4 else 20261202
with open(ARCHIVE, "rb") as f:
raw = f.read()
assert raw[:4] == b"LZPL", "not an LZPL archive"
assert raw[4] == 4, "not v4"
path_len = struct.unpack_from("<H", raw, 16)[0]
data_off = 16 + 78 + path_len
# entry header (78 bytes from offset 16): path_len u16, level/rs_level/
# flags/reserved u8 x4, orig_size u64 @22, stored_size u64 @30,
# blob_size u64 @38, sha256[32] @46, mode u32, mtime u64, header_crc32 u32
orig_size, stored_size, blob_size = struct.unpack_from("<QQQ", raw, 22)
sha = raw[46:78].hex()
print("archive: %s data_off=%d stored=%d blob=%d orig=%d sha256=%s..."
% (ARCHIVE, data_off, stored_size, blob_size, orig_size, sha[:16]),
flush=True)
data_end = data_off + stored_size
assert data_end <= len(raw), "stored data overruns file"
work = os.environ.get("MATRIX_WORKDIR", "/tmp/lzply-matrix")
shutil.rmtree(work, ignore_errors=True)
os.makedirs(work)
def trial(rng, kind, n):
p = os.path.join(work, "t.lzply")
buf = bytearray(raw)
if kind == "bits":
positions = rng.sample(range(data_off * 8, data_end * 8), n)
for pos in positions:
buf[pos // 8] ^= 1 << (pos % 8)
else: # burst: n consecutive bytes -> random bytes
start = rng.randrange(data_off, data_end - n + 1)
for i in range(n):
buf[start + i] = rng.randrange(256)
with open(p, "wb") as f:
f.write(buf)
r = subprocess.run([LZPLY, "-t", p], capture_output=True)
if r.returncode != 0:
return "failed-loud"
# -t passed: extract and verify content hash to catch silent damage
outdir = os.path.join(work, "out")
shutil.rmtree(outdir, ignore_errors=True)
r2 = subprocess.run([LZPLY, "-d", "-y", p, outdir],
capture_output=True)
if r2.returncode != 0:
return "failed-loud"
got = None
for root, _, files in os.walk(outdir):
for fn in files:
with open(os.path.join(root, fn), "rb") as f:
got = hashlib.sha256(f.read()).hexdigest()
return "recovered" if got == sha else "SILENT-BAD"
rng = random.Random(SEED)
results = {}
only = os.environ.get("MATRIX_ONLY", "bits,burst").split(",")
for kind, sizes in (("bits", [1, 2, 4, 8, 9, 16, 32]),
("burst", [1, 2, 4, 8, 16])):
if kind not in only:
continue
for n in sizes:
counts = {"recovered": 0, "failed-loud": 0, "SILENT-BAD": 0}
for _ in range(TRIALS):
counts[trial(rng, kind, n)] += 1
results[(kind, n)] = counts
print("%-5s n=%-3d: recovered %3d/%d failed-loud %3d silent-bad %d"
% (kind, n, counts["recovered"], TRIALS,
counts["failed-loud"], counts["SILENT-BAD"]), flush=True)
bad = sum(c["SILENT-BAD"] for c in results.values())
print("TOTAL silent-bad: %d (must be 0)" % bad)
sys.exit(1 if bad else 0)
+321
View File
@@ -0,0 +1,321 @@
# lzply baseline — experiments/baseline @ 8dbb8d03
Measured 2026-12-02 on hot_newyork (172.93.49.176, 8 cores, 30 GB RAM,
Ubuntu 26.04.1, gcc 15.2.0, liblz 1.16~rc1, libfuse3 3.18.2).
Base commit: `8dbb8d03` — "BCH: two-pass silent repair (hash-gated pass 2;
zero silent failures, loud failure otherwise)".
Branch: `experiments/baseline`. This file is the yardstick for the
parallel ECC / compression experiments: same corpus, same commands,
same harness (`bench/`).
## 1. Codebase map
Repo root `/opt/lzply-exp-base` (checked out from
`git@github.com:cnmcdee/lzply.git`, branch `experiments/baseline`).
~11,633 lines of C/Python, no legacy support: v4 (`LZPL`) is the only
format; v1/v2/v3 and old magics `LZRS`/`LZBC` are rejected outright.
| File | Lines | Role |
|---|---|---|
| `lzply.c` | 1926 | `lzply` CLI: `-c/-a/-d/-l/-t/-i/-tr`, date filters, selectors |
| `lzply_lib.c` / `lzply_lib.h` | 930 / 253 | shared core: v4 format, per-entry pipeline (lzip -> BCH), header I/O, archive scan, filters |
| `bch.c` / `bch.h` | 1007 / 109 | binary BCH codec + two-pass (pass-2 candidate) repair |
| `bch_polys.h` | 273 | 82 embedded generator polynomials (parents N = 2^m - 1, m = 7..22) |
| `gen_bch_polys.py` | 322 | regenerates `bch_polys.h` from rssearch data (checked in, not rebuilt by make) |
| `bch_test.c` | 415 | BCH unit tests (table remainder vs brute force, roundtrips, corruption, auto-pick, block splitting) |
| `sha256.c` / `sha256.h` | 124 / 26 | SHA-256 (per-entry integrity; load-bearing against BCH miscorrection) |
| `lzply_mount.c` | 1448 | FUSE filesystem (`lzply_mount`, `mount.lzply` helper) |
| `lzply_stat.c` | 293 | per-entry statistics (sizes, poly, t, parity bits, ECC overhead %) |
| `lzply_heal.c` | 618 | strip + re-apply BCH parity without touching the compressed blob |
| `lzply_check.c` | 564 | bit-error-rate measurement (`--json`, `--warn-ber`, `--fail-ber`) |
| `lzply_refresh.c` | 410 | in-place platter refresher (1-3 passes, SHA-256 verified) |
| `lzply_hyper.c` | 2264 | striped volume: 8 bit-plane data stripes + 1-3 XOR/GF parity, rebuilds up to 3 dead stripes (no compression) |
| `lzply_util.c` / `lzply_util.h` | 440 / 33 | shared helpers for stat/heal/check/refresh (mount resolution via /proc, human sizes) |
| `lzprobe.c` | 41 | tiny probe tool |
| `Makefile` | 137 | builds 7 binaries + `bch_test`; `make test` runs the full suite |
| `tests/run_tests.sh` | 1156 | 147 archive tests (see §3) |
| `tests/run_hyper_tests.sh` | 443 | 56 striped-volume tests |
| `tests/corrupt.c`, `tests/corrupt_bits.c` | 96 / 103 | whole-byte / single-bit corruption injectors used by the suite |
| `tests/make_testdata.sh` | 46 | generates `testdata/` (incl. a 50 MiB random file) on demand |
| `bench/bench.sh` | — | this baseline's ratio/speed/memory benchmark (see §5) |
| `bench/corrupt_matrix.py` | — | this baseline's corruption matrix (see §6) |
| `README.md`, `README-hyper.md`, `lzply_hyper-design.md` | — | user docs; format + CLI reference |
Build system: plain `make` (no configure/autotools). `make -j8` builds
`lzply lzply_mount lzply_stat lzply_heal lzply_check lzply_refresh
lzply_hyper` + `liblzply.a` (lzply_lib + bch + sha256). Deps:
`build-essential`, `liblz-dev` (lzip/LZMA), `libfuse3-dev` (mount only).
`CFLAGS = -O2 -Wall -Wextra`; the baseline build is warning-clean.
## 2. Format (v4) and pipeline
All integers little-endian. Global header (16 B): magic `"LZPL"`,
version u8 (=4), flags u8, entry_count u32, reserved u64. Each entry:
u16 path_len, u8 level, u8 rs_level, u8 flags, u8 reserved,
u64 orig_size, u64 stored_size, u64 blob_size, u8 sha256[32],
u32 mode, u64 mtime, u32 header_crc32 (covers the 74 bytes before it),
path[path_len], data[stored_size]. End marker: u16 path_len == 0.
Per-entry pipeline: `compress (lzip) -> BCH encode` on write;
`BCH-decode -> decompress` on read. One entry = one independent byte
stream. `blob_size` is the compressed length before ECC parity.
CLI (see `README.md` for the full reference):
- Compression: lzip levels `-1`..`-9`, default `-6`. The compressed
stream inside an entry is byte-identical to `lzip -N`.
- Store mode (level 0): when the compressed blob would be no smaller
than the original (already-compressed / random / empty), the entry is
stored uncompressed; BCH still applies. `-0` forces store for all.
- Error correction: `-e <0..7>` maps to BCH t: 0 -> none, 1 -> 1,
2 -> 2, 3 -> 4, 4 -> 8, 5 -> 16, 6 -> 32, 7 -> 32. Default `-e 4`
(t=8). `poly=NN` (hex `poly=003a` or decimal `poly=58`) pins one
polynomial and overrides `-e`. With no pin, the most efficient poly
for the blob length is auto-picked (smallest parent whose codeword
covers the blob). A blob longer than one block's capacity is split
into blocks of that poly's max payload (m=22, t=32: 524,199 B/block);
the decoder rebuilds boundaries from blob_size + poly.
- Integrity: every entry carries SHA-256 of its original data. A
bounded-distance BCH decoder can miscorrect damage beyond t (e.g.
t=1, 2-bit errors miscorrect ~50% at codec level); SHA-256 catches
it, so miscorrection is reported as corruption, never silent damage.
- Two-pass repair (this base commit): when pass-1 decode fails (or the
hash fails after a pass-1 success), pass 2 enumerates up to 16
candidate decodings (residual-BM + bounded flip-and-redecode) and the
caller hash-verifies each; first SHA-256 match wins, otherwise loud
failure. Zero silent failures by construction.
- Timestamps: mtime (seconds, UTC) + file mode stored per entry;
ownership not stored. `-datestart` / `-dateend` / `-year` filter on
mtime; `-i` reads headers only (never decompresses); `-tr` prints a
tree; `-a` appends (incremental when no path collides); selectors
match exact paths or directory prefixes.
- Exit codes: 0 ok, 1 usage, 2 I/O error, 3 corrupt/unrecoverable.
- Limitations (v4): whole files buffered in memory (50 MiB fine,
multi-GB needs a streaming rewrite); symlinks/special files skipped;
BCH corrects scattered bit flips, not whole lost bytes — a burst
wiping many consecutive bits in one block can exceed t even when the
byte count is small; the BCH decoder builds GF(2^m) log/exp tables
(up to 32 MiB transient for m=22) the first time it must correct an
error in a block (no-error path needs no tables).
## 3. Test suite — results at this base
`make test` = `bch_test` + `tests/run_tests.sh` + `tests/run_hyper_tests.sh`.
| Suite | Result (hot_newyork) |
|---|---|
| `bch_test` phase 1+2 (remainder x-check + roundtrip, all 82 polys) | 5220 checks, 0 fails |
| `bch_test` phase 3 (corruption) | 7253 checks, 0 fails |
| `tests/run_tests.sh` | **147 passed, 0 failed** |
| `tests/run_hyper_tests.sh` | **56 passed, 0 failed** |
Coverage: roundtrips at every level `-1`..`-9`; byte-identical
cross-check vs system `lzip -6` (at `-e 0`); roundtrips at BCH levels
0..7; BCH corruption with pinned polys (t recovered, t+1 fails
cleanly); combined `-9 -e 5` with 16 corrupted bits; v1/v3 archives
and old magics rejected; overwrite flags; empty dir/file, 1-byte file,
spaces in names, truncated/non-archive inputs; 50 MiB multi-block file;
`poly=` pinning (hex/decimal), unknown-poly rejection; append (21
tests) + selective extract; inspect/tree/date filters (27 tests);
`lzply_stat` (4), `lzply_heal` (8), `lzply_check` (8),
`lzply_refresh` (9), mount write-back (3), store mode (16).
Environment caveat (NOT a code failure): run from `/opt/lzply-exp-base`
the suite reports **144 passed, 3 failed** — the 3 mount write-back
tests (`mount with relative archive path: writes persist in the real
archive`, `store mode: mount repack stores an incompressible file`,
`store mode: mount-repacked stored file extracts byte-identical`).
Root cause, verified: AppArmor's `fusermount3` profile (enforce mode,
`/etc/apparmor.d/fusermount3`) allows `umount` only under
`@{HOME}/**`, `/mnt/**`, `/run/user/@{uid}/**`, `/media/**`,
`/tmp/**`, `/cvmfs/**` — NOT under `/opt/**`. `fusermount3 -u`
fails with EPERM (audit: `apparmor="DENIED" operation="umount" ...
profile="fusermount3"`), the mount stays up, the repack never runs,
and the test reads the pre-mount archive. The lzply code is correct:
the same tests pass when the tree is copied under `/tmp`
(147/0 above), a manual relative-path mount under `/tmp` repacks
correctly, and plain `umount` (unconfined) unmounts the `/opt` mounts
fine and triggers the repack. To run the suite green, run it from a
copy under `/tmp` (or any AppArmor-allowed path):
`cp -a /opt/lzply-exp-base /tmp/lzply-tmproot && cd /tmp/lzply-tmproot && make test`.
Stale mounts left by the failing `/opt` runs were cleaned with
`umount` (the other coordinator's `/opt/lzply-exp-ecc` mounts were
left untouched).
## 4. Corpus (reproduction)
Standard corpora, downloaded 2026-12-02 to `/opt/lzply-bench/corpus/`:
- `enwik8` — first 100,000,000 bytes of English Wikipedia
(https://mattmahoney.net/dc/enwik8.zip), sha256
`2b49720ec4d78c3c9fabaee6e4179a5e997302b3a70029f30f2d582218c024a8`
- Silesia corpus (https://sun.aei.polsl.pl/~sdeor/corpus/silesia.zip),
all 12 files:
| file | bytes | sha256 |
|---|---|---|
| dickens | 10,192,446 | `b24c37886142e11d0ee687db6ab06f936207aa7f2ea1fd1d9a36763c7a507e6a` |
| mozilla | 51,220,480 | `657fc3764b0c75ac9de9623125705831ebbfbe08fed248df73bc2dc66e2a963b` |
| mr | 9,970,564 | `68637ed52e3e4860174ed2dc0840ac77d5f1a60abbcb13770d5754e3774d53e6` |
| nci | 33,553,445 | `fc63a31770947b8c2062d3b19ca94c00485a232bb91b502021948fee983e1635` |
| ooffice | 6,152,192 | `e7ee013880d34dd5208283d0d3d91b07f442e067454276095ded14f322a656eb` |
| osdb | 10,085,684 | `60f027179302ca3ad87c58ac90b6be72ec23588aaa7a3b7fe8ecc0f11def3fa3` |
| reymont | 6,627,202 | `0eac0114a3dfe6e2ee1f345a0f79d653cb26c3bc9f0ed79238af4933422b7578` |
| samba | 21,606,400 | `93ba07bc44d8267789c1d911992f40b089ffa2140b4a160fac11ccae9a40e7b2` |
| sao | 7,251,944 | `c2d0ea2cc59d4c21b7fe43a71499342a00cbe530a1d5548770e91ecd6214adcc` |
| webster | 41,458,703 | `6a68f69b26daf09f9dd84f7470368553194a0b294fcfa80f1604efb11143a383` |
| x-ray | 8,474,240 | `7de9fce1405dc44ae5e6813ed21cd5751e761bd4265655a005d39b9685d1c9ad` |
| xml | 5,345,280 | `0e82e54e695c1938e4193448022543845b33020c8be6bf3bf3ead2224903e08c` |
Data files total 311,489,800 bytes. The corpus directory also holds the
two source zips (`enwik8.zip` 36,445,475 B, `silesia.zip` 68,182,744 B);
whole-directory runs archive all 15 files (416,566,799 B total).
Corruption-matrix input: `slice1m.bin` = first 1,048,576 bytes of
`enwik8`, sha256
`4fb5efa9f35df431737731bf3c8f38a467b69731940ff82a4ee0e218aae58834`,
archived as `slice1m.lzply` at `-6 -e 4` (blob 296.9 KiB, poly `0050`,
t=8, single BCH block; 176 parity bits, 0.007% ECC overhead).
Reproduce the corpus download:
```sh
mkdir -p /opt/lzply-bench/corpus && cd /opt/lzply-bench/corpus
curl -sL -o enwik8.zip https://mattmahoney.net/dc/enwik8.zip
curl -sL -o silesia.zip https://sun.aei.polsl.pl/~sdeor/corpus/silesia.zip
python3 -c "import zipfile; zipfile.ZipFile('enwik8.zip').extractall()"
python3 -c "import zipfile; zipfile.ZipFile('silesia.zip').extractall()"
sha256sum enwik8 dickens mozilla mr nci ooffice osdb reymont samba sao webster x-ray xml
```
## 5. Baseline numbers — ratio, speed, memory
Command: `bench/bench.sh <lzply> <corpus-dir> <work-dir>` (needs
GNU `time`, `/usr/bin/time -v`, for wall clock + max RSS). Each run:
one encode, one decode, `diff -r` round-trip check. Machine shared
with other agents' builds during measurement — encode wall times are
noisy (see caveat); decode is stable. All round-trips bit-identical.
### 5.1 enwik8, single file, 100,000,000 bytes, default -e 4 (t=8)
| level | archive bytes | ratio | enc wall | enc MB/s | enc max RSS | dec wall | dec MB/s | dec max RSS |
|---|---|---|---|---|---|---|---|---|
| -1 | 29,126,665 | 29.13% | 1:43.82 | 0.96 | 156,404 KB | 0:06.57 | 15.2 | 157,560 KB |
| -6 | 26,519,665 | 26.52% | 3:06.14 | 0.54 | 215,800 KB | 0:06.19 | 16.2 | 159,668 KB |
| -9 | 25,397,987 | 25.40% | 4:10.43 | 0.40 | 485,112 KB | 0:06.24 | 16.0 | 181,880 KB |
### 5.2 whole corpus directory, 416,566,799 bytes (15 files), -6
| -e (t) | archive bytes | ratio | enc wall | enc MB/s | enc max RSS | dec wall | dec MB/s | dec max RSS |
|---|---|---|---|---|---|---|---|---|
| 4 (t=8, default) | 181,121,579 | 43.48% | 8:54.98 | 0.78 | 242,384 KB | 0:22.28 | 18.7 | 233,832 KB |
| 0 (no ECC) | 181,113,835 | 43.48% | 8:33.81 | 0.81 | 242,444 KB | 0:17.31 | 24.1 | 177,976 KB |
| 7 (t=32) | 181,144,811 | 43.49% | 8:56.79 | 0.78 | 242,568 KB | 0:38.93 | 10.7 | 233,844 KB |
ECC overhead on this corpus: default t=8 costs 7,744 bytes over no-ECC
(0.0043%); t=32 costs 30,976 bytes (0.017%). BCH parity is negligible
next to LZMA output at these sizes — the overhead story is per-block
parity bits, not a percentage of the archive. Decode slows with t
(17.3s -> 22.3s -> 38.9s) because larger t means larger GF tables on
the correction path and more blocks to check.
### 5.3 mozilla (binary-ish), 51,220,480 bytes, -6 -e 4
| archive bytes | ratio | enc wall | enc MB/s | enc max RSS | dec wall | dec MB/s | dec max RSS |
|---|---|---|---|---|---|---|---|
| 13,580,691 | 26.51% | 0:49.45 | 1.04 | 155,768 KB | 0:02.89 | 17.7 | 86,776 KB |
### 5.4 Caveats
- Encode speed is dominated by single-threaded LZMA (`liblz`), not by
BCH: `-1` vs `-9` on enwik8 is 0.96 vs 0.40 MB/s for a 29.1% ->
25.4% ratio gain. Any compression-family experiment must beat
these ratio/speed points, not just the ratio.
- Wall times were measured while other agents were building on the
same 8-core server; expect encode times to vary run to run. Decode
times (I/O + LZMA decode, single-threaded) were stable across runs.
- Peak RSS is dominated by the whole-file buffering (input + blob +
stored copy in memory at once) plus, at `-9`, LZMA's dictionary
(485 MB for enwik8 -9 encode). Multi-GB files need the streaming
rewrite noted in §2.
## 6. Corruption matrix — correction power at default -e 4 (t=8)
Harness: `bench/corrupt_matrix.py <lzply> <archive> <trials> [seed]`.
Single-entry archive `slice1m.lzply` (see §4: 1 MiB text, blob
296.9 KiB, one BCH block, t=8). Each trial: copy the archive, corrupt
ONLY the stored-data region (headers untouched), run `lzply -t`, and
on success extract + SHA-256-verify the recovered file. 200 trials
per setting, seed 20261202 (Python `random.Random`, deterministic).
"recovered" = `-t` passed AND extracted bytes hash-identical;
"failed-loud" = `-t` (or extract) exited non-zero; "silent-bad" =
passed but content wrong (must be 0 — the SHA-256 gate).
### 6.1 Results (200 trials per setting)
Scattered bits (seed 20261202), single 304 KB block, t=8:
| scattered bits flipped | recovered | failed-loud | silent-bad |
|---|---|---|---|
| 1 | 200/200 | 0 | 0 |
| 2 | 200/200 | 0 | 0 |
| 4 | 200/200 | 0 | 0 |
| 8 (= t) | 200/200 | 0 | 0 |
| 9 (= t+1) | **0/200** | 200 | 0 |
| 16 | **0/200** | 200 | 0 |
| 32 | **0/200** | 200 | 0 |
Bursts — L consecutive bytes replaced with random bytes (up to 8L bit
errors); two independent seeds:
| burst length | recovered (seed 20261202) | recovered (seed 20261203) | failed-loud | silent-bad |
|---|---|---|---|---|
| 1 byte | 200/200 | 200/200 | 0 | 0 |
| 2 bytes | 135/200 | 117/200 | 65 / 83 | 0 |
| 4 bytes | 0/200 | 0/200 | 200 | 0 |
| 8 bytes | 0/200 | 0/200 | 200 | 0 |
| 16 bytes | 0/200 | 0/200 | 200 | 0 |
**Total silent-bad across all 2,800 trials: 0.** The SHA-256 gate
holds everywhere: damage beyond t is always a loud failure, never
wrong data.
### 6.2 Reading the numbers
- The cliff is exactly at t: everything at or below 8 scattered bit
errors recovers; everything above recovers nothing. Pass 1
(bounded-distance BCH) behaves exactly as theory says.
- **Pass 2 rescues nothing beyond t for random scattered errors at
this block size: 0/600 trials at n = 9, 16, 32.** Pass 2 IS wired
in (`entry_decode` in `lzply_lib.c` calls `bch_decode_candidates`,
up to 16 candidates, hash-gated) — the residual-BM +
flip-and-redecode candidates simply never land on the true codeword
for random t+1..t+4 patterns in a 304 KB (m=22) block. This is the
gap the deep-repair work (Chase flips, list decoding) exists to
close; any experiment claiming beyond-t recovery must beat 0/200
here, on this archive, with these seeds.
- The 2-byte burst split (117-135/200) is the binomial edge: two
random bytes differ in ~8 bits on average, so about half the trials
land at <= 8 bit errors (recovered) and half above (failed). A
1-byte burst is always <= 8 bit errors, hence 200/200.
- Pass 2 is expensive when it runs: trials at n <= 8 cost ~1 s each
(fresh `lzply -t` + `lzply -d` processes, GF(2^22) table build on
the correction path); trials beyond t cost ~4-5 s each (candidate
enumeration). A repair scheme's per-block time budget matters as
much as its recovery rate.
Reproduce: `python3 bench/corrupt_matrix.py /opt/lzply-exp-base/lzply
/opt/lzply-bench/slice1m.lzply 200 20261202` (bits + bursts, one
process) or with `MATRIX_ONLY=burst MATRIX_WORKDIR=/tmp/lzply-matrix-burst`
and seed 20261203 for the burst-only run. Logs:
`/opt/lzply-bench/matrix.log`, `/opt/lzply-bench/matrix-burst.log`.
## 7. What is NOT in this baseline
- hot_chicago build/test: blocked by the sshd outage (new sessions
hang at banner exchange; see report). The branch is pushed, so the
Chicago run is a clone + `make -j8` + `make test` + the same
`bench.sh` / `corrupt_matrix.py` once SSH recovers. Chicago needs
no package installs (lzip, liblz-dev, libfuse3-dev present).
- `lzply_hyper` (striped volume) numbers: the suite passes (56/0)
but no separate ratio/speed benchmark was run — it stores
uncompressed stripes, so its yardstick is rebuild time, not ratio.
-50
View File
@@ -1,50 +0,0 @@
# experiments/Makefile - prototypes for the lzply compression research.
# Built with max cores via -j; each tool is standalone: `tool c in out`,
# `tool d in out`. Shared rANS core in rans.o.
CC = gcc
CFLAGS = -O3 -Wall -Wextra -march=native
LDLIBS = -llz -lm
TOOLS = rans_tool lzrans bwt ppm dict bchcheck
all: $(TOOLS)
rans.o: rans.c rans.h
$(CC) $(CFLAGS) -c -o $@ rans.c
rans_tool: rans_tool.o rans.o
$(CC) $(CFLAGS) -o $@ rans_tool.o rans.o
lzrans.o: lzrans.c rans.h
$(CC) $(CFLAGS) -c -o $@ lzrans.c
lzrans: lzrans.o rans.o
$(CC) $(CFLAGS) -o $@ lzrans.o rans.o
bwt.o: bwt.c rans.h
$(CC) $(CFLAGS) -c -o $@ bwt.c
bwt: bwt.o rans.o
$(CC) $(CFLAGS) -o $@ bwt.o rans.o
ppm.o: ppm.c
$(CC) $(CFLAGS) -c -o $@ ppm.c
ppm: ppm.o
$(CC) $(CFLAGS) -o $@ ppm.o $(LDLIBS)
dict.o: dict.c
$(CC) $(CFLAGS) -c -o $@ dict.c
dict: dict.o
$(CC) $(CFLAGS) -o $@ dict.o
bchcheck.o: bchcheck.c ../bch.h
$(CC) $(CFLAGS) -I.. -c -o $@ bchcheck.c
bchcheck: bchcheck.o ../bch.o ../bch_polys.h
$(CC) $(CFLAGS) -o $@ bchcheck.o ../bch.o
clean:
rm -f $(TOOLS) *.o
.PHONY: all clean
-134
View File
@@ -1,134 +0,0 @@
# lzply compression experiments (branch experiments/comp)
Prototypes for open-ended compression research. Each tool is standalone:
`tool c|o in out`, `tool d in out`. Shared rANS core in rans.[ch].
`bench.py <name> <enc> <dec> [corpora...]` times (best of 3), sizes,
and sha256-verifies round-trips; `bench1.py` is the single-run variant
(for slow tools); CSVs land in results/.
## Corpora (built by mkcorpora.py, deterministic per machine)
- text: 8 MiB UTF-8 docs from /usr/share/doc + common-licenses
- code: 8 MiB C headers (/usr/include) + this repo's sources
- bin: 8 MiB ELF binaries from /bin + /usr/bin
- mixed: 8 MiB round-robin 64 KiB chunks of text+code+bin
- rand: 4 MiB /dev/urandom (seed 1234), incompressible control
Corpora are NOT committed (regenerate with mkcorpora.py).
All ratios below are compressed/orig %; speeds are MB/s (orig bytes).
## Baseline: lzip (the current lzply stage; same liblz, same levels)
| tool | text | code | bin | mixed | rand | enc MB/s | dec MB/s |
|---|---|---|---|---|---|---|---|
| lzip -1 | 6.22 | 15.13 | 37.83 | 21.58 | 101.36 | 1.4-9.1 | 8.9-71.8 |
| lzip -6 | 3.56 | 9.38 | 32.61 | 17.41 | 101.36 | 0.9-2.3 | 7.9-71.4 |
| lzip -9 | 3.44 | 9.05 | 32.53 | 17.17 | 101.36 | 0.8-1.4 | 9.0-70.3 |
References: xz -6 ~= lzip -6 (text 3.51, code 9.20, bin 32.59,
mixed 17.30); zstd -19 text 3.63, code 9.48, bin 34.81, mixed 18.31;
gzip -9 text 23.48, code 16.40, bin 44.14, mixed 30.06;
bzip2 -9 text 9.25, code 12.55, bin 40.22, mixed 23.53,
dec only 5-9 MB/s.
## ANS: rANS order-0 (rans_tool) — REJECT as standalone, KEEP core
Static per-file freqs, 12-bit probs. Enc 30-38 MB/s, dec 47-62 MB/s,
RSS ~20 MB, but no LZ stage: text 64.40, code 67.62, bin 77.14,
mixed 78.11, rand 100.46. The core is the entropy stage for the BWT
and LZ prototypes below. (Two real bugs found and fixed in the core:
renormalisation threshold must be (L>>12)*f<<8 or the decoder
over-reads; the emitted stream can exceed n bytes, scratch is 2n+64.)
## LZ77 + rANS (lzrans) — REJECT as a lzip replacement
Hash-chain finder, 1 MiB window, lazy (`c`) and optimal-parse (`o`)
modes, deflate-style length codes, log2 distance codes, litlen/dist
rANS streams + raw extra bits.
| mode | text | code | bin | mixed | rand | enc | dec | RSS |
|---|---|---|---|---|---|---|---|---|
| lazy | 6.26 | 13.52 | 41.84 | 23.15 | 100.48 | 0.5-4.4 | 26-73 | 44 MB |
| optimal | 6.19 | 13.05 | — | — | — | 0.4-1.0 | 64-73 | 173 MB |
Optimal parsing recovers only ~1-3% relative, so the gap is not
parsing: it is LZMA's adaptive context entropy model plus deeper
match search and a larger dictionary. A static-table rANS cannot
close a ~75% relative gap on text.
## BWT + MTF + run tokens + rANS (bwt) — REJECT as a lzip replacement
Suffix array by cyclic doubling (see the linear-vs-rotation trap
below), MTF, runs >=4 tokenised as (value, 256, k), 257-symbol rANS.
| corpus | ratio | enc | dec |
|---|---|---|---|
| text | 6.35 | 177 s (0.05 MB/s) | 5.3 MB/s |
| code | 12.31 | 173 s | 6.3 MB/s |
| bin | 42.76 | 137 s | 5.9 MB/s |
| mixed | (bench running) | | |
| rand | (bench running) | | |
RSS ~200 MB. Beats bzip2 on text (6.35 vs 9.25), ~ties on code
(12.31 vs 12.55), loses on bin (42.76 vs 40.22); loses to lzip
everywhere by a wide margin. Encode is ~3 min/8 MB (doubling SA is
memory-latency-bound over 160 MB of rank arrays); decode is 5-6 MB/s
(LF-walk random access).
GOTCHA (real bug, fixed): a linear suffix sort is NOT rotation
order — "a" < "a bandana" linearly, but cyclically
"a bandanabanan" < "abanana bandan". A sentinel does not fix it
("a$" < "a bandana$" truncates the comparison). The SA must use
cyclic doubling (rank[(i+k) % n]).
## PPM order-2 + arithmetic coding (ppm) — REJECT
Order-2/1/0 contexts, escape mass = distinct-symbol count,
Witten-Neal-Cleary 32-bit arithmetic coder, counts updated in all
levels after every symbol. RSS ~80 MB.
| corpus | ratio | enc MB/s | dec MB/s |
|---|---|---|---|
| text | 32.84 | 6.3 | 3.9 |
| code | 30.82 | 6.3 | 4.1 |
| mixed | 39.18 | 4.8 | 3.2 |
Far behind lzip and slow: the bit-level coder plus 256-wide level
scans cost ~6 MB/s encode, ~4 MB/s decode. A simple order-2 PPM
with heavy escape mass is nowhere near PPMd-class.
## Dictionary transform + lzip (dict) — CONDITIONAL, code only
Per-file word dictionary (top 4096 words by saving, transmitted in
the header), words -> 3-byte codes, then lzip -6. RSS ~32 MB.
| corpus | dict+lzip6 | plain lzip6 | delta |
|---|---|---|---|
| text | 3.58 | 3.56 | +0.5% worse |
| code | 9.19 | 9.38 | -2.1% BETTER |
| bin | 33.30 | 32.61 | +2.1% worse |
| mixed | 17.65 | 17.41 | +1.4% worse |
| rand | 101.73 | 101.36 | worse |
Only code wins (+2.1%): long repeated identifiers survive as codes
better than as LZ matches. Everywhere else the dictionary costs
more than it saves (lzip already captures word repeats). Not a
default; a code-only optional preprocessing stage at most.
(Gotcha fixed during the build: words are sorted by count, so the
saving filter must `continue`, not `break`, or a short frequent
word like "the" discards the whole dictionary.)
## BCH end-to-end (bchcheck) — winners survive error correction
Blob -> BCH(t=8, lzply -e 4 level) -> flip N bits -> decode ->
decompress -> sha256 check.
- dict+lzip code blob (770,519 B): poly 0050, stored 770,563
(+44 B parity, 0.006%). 8 flips -> 8 corrected, full pipeline
recovers bit-identical. 32 flips -> decode FAIL (exceeds t=8 per
block; honest failure mode).
- plain lzip6 code blob (787,213 B): 8 flips -> 8 corrected,
recovered + decoded bit-identical.
## Verdicts (bottom line)
- No family beats lzip on ratio. lzip/LZMA's adaptive entropy
model + deep match search + large dictionary is very hard to beat
with a from-scratch prototype in this scope.
- KEEP: the rANS core (fast, correct, reusable as an entropy stage).
- CONDITIONAL: dict transform, code-only (+2.1% on code).
- REJECT: lzrans (lazy + optimal), BWT, PPM order-2, rANS order-0
standalone. Honest negatives, numbers above.
- Test totals: 334 timed bench invocations, all sha256-verified OK
(plus ~25 manual small-input round-trips and 3 BCH runs: 2 pass,
1 expected fail at 32 flips).
## Notes / environment
- hot_newyork (172.93.49.176), 8 cores, 30 GB RAM; server load was
10-17 during the runs (shared with other agents), so absolute
MB/s figures are load-dependent; ratios are exact.
- hot_chicago verification pending: its SSH stopped accepting new
sessions Dec 2 (sshd can't fork under load); a retry agent is
probing every 15 min. No Chicago numbers yet.
- The other lz_rs/deep-repair coordinator works in /opt/lzply/src
and /root/lzrs-verify/lzply; untouched by this work. No
Reed-Solomon was (re-)implemented here.
-88
View File
@@ -1,88 +0,0 @@
/* bchcheck.c - BCH end-to-end corruption test for experiment blobs.
* Takes a compressed blob, BCH-encodes it (t=8 by default, the lzply
* -e 4 level; largest t=8 poly if the blob exceeds one m=22 block),
* flips N random bits (seeded), decodes, and writes the recovered
* blob. Exit 0 if the recovered blob is byte-identical to the input,
* 1 if decode failed or the blob differs, 2 on usage/IO error.
* Usage: bchcheck blob nflips seed out [t]
* The caller then decompresses `out` with the prototype and checks
* the sha256 round-trip, proving the compressed stream survives BCH.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include "bch.h"
static uint8_t *slurp(const char *path, size_t *n) {
FILE *f = fopen(path, "rb");
if (!f) { perror(path); exit(2); }
fseek(f, 0, SEEK_END);
long sz = ftell(f);
fseek(f, 0, SEEK_SET);
uint8_t *b = malloc(sz ? (size_t)sz : 1);
if (!b) exit(2);
if (sz && fread(b, 1, (size_t)sz, f) != (size_t)sz) exit(2);
fclose(f);
*n = (size_t)sz;
return b;
}
/* Largest-capacity poly with the requested t (m=22 wins). */
static const bch_poly_t *largest_t_poly(int t) {
const bch_poly_t *best = NULL;
size_t bestcap = 0;
for (uint16_t id = 0x0001; id <= 0x0052; id++) {
const bch_poly_t *p = bch_poly_by_id(id);
if (!p || p->t != t) continue;
size_t cap = bch_max_data(p);
if (cap > bestcap) { bestcap = cap; best = p; }
}
return best;
}
int main(int argc, char **argv) {
if (argc < 5 || argc > 6) {
fprintf(stderr, "usage: %s blob nflips seed out [t]\n", argv[0]);
return 2;
}
int t = argc == 6 ? atoi(argv[5]) : 8;
long nflips = atol(argv[2]);
unsigned seed = (unsigned)atoi(argv[3]);
size_t n;
uint8_t *blob = slurp(argv[1], &n);
const bch_poly_t *poly = bch_poly_for_data(n, t);
if (!poly) poly = largest_t_poly(t);
if (!poly) { fprintf(stderr, "bchcheck: no poly for t=%d\n", t); return 2; }
size_t slen = bch_encoded_len(n, poly);
uint8_t *stored = malloc(slen ? slen : 1);
uint8_t *rec = malloc(n ? n : 1);
if (!stored || !rec) return 2;
if (bch_encode(blob, n, poly, stored) != slen) {
fprintf(stderr, "bchcheck: encode failed\n");
return 2;
}
/* xorshift64 PRNG for flip positions (seeded, deterministic) */
uint64_t xs = (uint64_t)seed * 0x9E3779B97F4A7C15ULL + 0x123456789ULL;
for (long k = 0; k < nflips; k++) {
xs ^= xs << 13; xs ^= xs >> 7; xs ^= xs << 17;
size_t bit = (size_t)(xs % (uint64_t)(slen * 8));
stored[bit / 8] ^= (uint8_t)(0x80u >> (bit % 8));
}
int corrected = 0;
int rc = bch_decode(stored, slen, n, poly, rec, &corrected);
fprintf(stderr, "bchcheck: poly=%04x blob=%zu stored=%zu overhead=%.1f%% "
"flips=%ld corrected=%d decode=%s\n",
poly->id, n, slen, 100.0 * (double)(slen - n) / (double)n,
nflips, corrected, rc == 0 ? "OK" : "FAIL");
if (rc != 0) return 1;
FILE *f = fopen(argv[4], "wb");
if (!f) { perror(argv[4]); return 2; }
if (n && fwrite(rec, 1, n, f) != n) return 2;
fclose(f);
if (memcmp(blob, rec, n) != 0) {
fprintf(stderr, "bchcheck: recovered blob DIFFERS\n");
return 1;
}
return 0;
}
-84
View File
@@ -1,84 +0,0 @@
#!/usr/bin/env python3
"""bench.py <name> <enc-template> <dec-template> [corpus...]
Templates use {in} {out} {dec}; run via /bin/sh. Times encode/decode
(wall, best of 3 for encode, best of 3 for decode), records ratio,
MB/s, sha256 round-trip. Appends CSV rows to results/<name>.csv and
prints a table. Encode failure on a corpus records 'FAIL'.
"""
import subprocess, sys, os, time, hashlib, csv
EXP = os.path.dirname(os.path.abspath(__file__))
CORP = os.path.join(EXP, "corpora")
RES = os.path.join(EXP, "results")
TMP = "/tmp/expbench"
os.makedirs(TMP, exist_ok=True)
os.makedirs(RES, exist_ok=True)
def sha(p):
h = hashlib.sha256()
with open(p, "rb") as fh:
for c in iter(lambda: fh.read(1 << 20), b""):
h.update(c)
return h.hexdigest()
def run(cmd, timeout=600):
t0 = time.perf_counter()
r = subprocess.run(cmd, shell=True, stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL, timeout=timeout)
return r.returncode, time.perf_counter() - t0
def bench_one(name, enc, dec, corpus):
src = os.path.join(CORP, corpus)
n = os.path.getsize(src)
want = sha(src)
out = os.path.join(TMP, name + ".out")
decf = os.path.join(TMP, name + ".dec")
for f in (out, decf):
if os.path.exists(f):
os.unlink(f)
best_enc = None
for _ in range(3):
rc, dt = run(enc.format(**{"in": src, "out": out, "dec": decf}))
if rc != 0:
return (corpus, n, None, None, None, "ENCFAIL")
best_enc = dt if best_enc is None else min(best_enc, dt)
csize = os.path.getsize(out)
best_dec = None
for _ in range(3):
if os.path.exists(decf):
os.unlink(decf)
rc, dt = run(dec.format(**{"in": src, "out": out, "dec": decf}))
if rc != 0:
return (corpus, n, csize, None, None, "DECFAIL")
best_dec = dt if best_dec is None else min(best_dec, dt)
ok = sha(decf) == want
return (corpus, n, csize, best_enc, best_dec, "OK" if ok else "MISMATCH")
def main():
name, enc, dec = sys.argv[1], sys.argv[2], sys.argv[3]
corpora = sys.argv[4:] or ["text", "code", "bin", "mixed", "rand"]
csvp = os.path.join(RES, name + ".csv")
new = not os.path.exists(csvp)
print(f"== {name}: enc=[{enc}] dec=[{dec}]")
print(f"{'corpus':8s} {'orig':>9s} {'comp':>9s} {'ratio%':>7s} {'encMB/s':>8s} {'decMB/s':>8s} status")
with open(csvp, "a", newline="") as fh:
w = csv.writer(fh)
if new:
w.writerow(["tool", "corpus", "orig", "comp", "ratio_pct",
"enc_s", "dec_s", "enc_MBs", "dec_MBs", "status"])
for c in corpora:
corpus, n, cs, es, ds, st = bench_one(name, enc, dec, c)
if cs is None:
print(f"{c:8s} {n:9d} {'-':>9s} {'-':>7s} {'-':>8s} {'-':>8s} {st}")
w.writerow([name, c, n, "", "", "", "", "", "", st])
continue
ratio = 100.0 * cs / n
emb = n / 1e6 / es if es else 0
dmb = n / 1e6 / ds if ds else 0
print(f"{c:8s} {n:9d} {cs:9d} {ratio:7.2f} {emb:8.1f} {dmb:8.1f} {st}")
w.writerow([name, c, n, cs, f"{ratio:.2f}", f"{es:.3f}", f"{ds:.3f}",
f"{emb:.1f}", f"{dmb:.1f}", st])
print("csv: " + csvp)
if __name__ == "__main__":
main()
-71
View File
@@ -1,71 +0,0 @@
#!/usr/bin/env python3
"""bench1.py: single-run variant of bench.py (for slow tools like bwt).
Usage: bench1.py <name> <enc-template> <dec-template> [corpus...]
Appends to results/<name>.csv and prints one line per corpus."""
import subprocess, sys, os, time, hashlib, csv
EXP = os.path.dirname(os.path.abspath(__file__))
CORP = os.path.join(EXP, "corpora")
RES = os.path.join(EXP, "results")
TMP = "/tmp/expbench"
os.makedirs(TMP, exist_ok=True)
os.makedirs(RES, exist_ok=True)
def sha(p):
h = hashlib.sha256()
with open(p, "rb") as fh:
for c in iter(lambda: fh.read(1 << 20), b""):
h.update(c)
return h.hexdigest()
def run(cmd, timeout=3600):
t0 = time.perf_counter()
r = subprocess.run(cmd, shell=True, stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL, timeout=timeout)
return r.returncode, time.perf_counter() - t0
def main():
name, enc, dec = sys.argv[1], sys.argv[2], sys.argv[3]
corpora = sys.argv[4:] or ["text", "code", "bin", "mixed", "rand"]
csvp = os.path.join(RES, name + ".csv")
new = not os.path.exists(csvp)
print(f"== {name} (single run)", flush=True)
with open(csvp, "a", newline="") as fh:
w = csv.writer(fh)
if new:
w.writerow(["tool", "corpus", "orig", "comp", "ratio_pct",
"enc_s", "dec_s", "enc_MBs", "dec_MBs", "status"])
for c in corpora:
src = os.path.join(CORP, c)
n = os.path.getsize(src)
want = sha(src)
out = os.path.join(TMP, name + ".out")
decf = os.path.join(TMP, name + ".dec")
for f in (out, decf):
if os.path.exists(f):
os.unlink(f)
rc, es = run(enc.format(**{"in": src, "out": out, "dec": decf}))
if rc != 0:
print(f"{c}: ENCFAIL", flush=True)
w.writerow([name, c, n, "", "", "", "", "", "", "ENCFAIL"])
continue
cs = os.path.getsize(out)
if os.path.exists(decf):
os.unlink(decf)
rc, ds = run(dec.format(**{"in": src, "out": out, "dec": decf}))
if rc != 0:
print(f"{c}: DECFAIL", flush=True)
w.writerow([name, c, n, cs, "", "", "", "", "", "DECFAIL"])
continue
ok = sha(decf) == want
st = "OK" if ok else "MISMATCH"
ratio = 100.0 * cs / n
print(f"{c:8s} {n:9d} {cs:9d} {ratio:6.2f}% enc {es:7.1f}s "
f"({n/1e6/es:5.1f} MB/s) dec {ds:6.1f}s ({n/1e6/ds:5.1f} MB/s) {st}",
flush=True)
w.writerow([name, c, n, cs, f"{ratio:.2f}", f"{es:.3f}", f"{ds:.3f}",
f"{n/1e6/es:.1f}", f"{n/1e6/ds:.1f}", st])
print("csv: " + csvp, flush=True)
if __name__ == "__main__":
main()
-273
View File
@@ -1,273 +0,0 @@
/* bwt.c - BWT + MTF + run-length tokens + rANS prototype.
* Classic bzip2-style pipeline, written from scratch: suffix array by
* doubling with counting sort, Burrows-Wheeler transform, move-to-front,
* runs of >=4 identical MTF values tokenised as (value, 256, k),
* rANS over a 257-symbol alphabet.
* Usage: bwt c in out | bwt d in out
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include "rans.h"
#define NSYM 257
#define RUN_SYM 256
static uint8_t *slurp(const char *path, size_t *n) {
FILE *f = fopen(path, "rb");
if (!f) { perror(path); exit(2); }
fseek(f, 0, SEEK_END);
long sz = ftell(f);
fseek(f, 0, SEEK_SET);
uint8_t *b = malloc(sz ? (size_t)sz : 1);
if (!b) exit(2);
if (sz && fread(b, 1, (size_t)sz, f) != (size_t)sz) exit(2);
fclose(f);
*n = (size_t)sz;
return b;
}
static void spit(const char *path, const uint8_t *b, size_t n) {
FILE *f = fopen(path, "wb");
if (!f) { perror(path); exit(2); }
if (n && fwrite(b, 1, n, f) != n) exit(2);
fclose(f);
}
static void put32(uint8_t *p, uint32_t v) {
p[0] = (uint8_t)v; p[1] = (uint8_t)(v >> 8);
p[2] = (uint8_t)(v >> 16); p[3] = (uint8_t)(v >> 24);
}
static uint32_t get32(const uint8_t *p) {
return (uint32_t)p[0] | ((uint32_t)p[1] << 8) |
((uint32_t)p[2] << 16) | ((uint32_t)p[3] << 24);
}
/* Counting-sort SA by key array key[SA[i]] (keys in [0, kmax]).
* sa2 is scratch. */
static void csort(int32_t *sa, int32_t *sa2, const int32_t *key, size_t n,
int32_t kmax, int32_t *cnt) {
memset(cnt, 0, (size_t)(kmax + 1) * sizeof *cnt);
for (size_t i = 0; i < n; i++) cnt[key[sa[i]]]++;
int32_t sum = 0;
for (int32_t k = 0; k <= kmax; k++) {
int32_t c = cnt[k];
cnt[k] = sum;
sum += c;
}
for (size_t i = 0; i < n; i++) {
int32_t s = sa[i];
sa2[cnt[key[s]]++] = s;
}
memcpy(sa, sa2, n * sizeof *sa);
}
/* Suffix array of the CYCLIC rotations, by doubling with wraparound
* rank lookups: rotation i is compared via data[i+k mod n], so the
* order is rotation order (what BWT needs), not linear-suffix order.
* A linear sort puts "a" before "a bandana", but cyclically
* "a bandanabanan" < "abanana bandan"; a sentinel does not fix this
* either ("a$" < "a bandana$" truncates the comparison). Periodic
* rotations stay tied, which is harmless: identical rotations have
* identical BWT chars. */
static int32_t *build_sa(const uint8_t *d, size_t n) {
int32_t *sa = malloc(n * sizeof *sa);
int32_t *sa2 = malloc(n * sizeof *sa2);
int32_t *rank = malloc(n * sizeof *rank);
int32_t *tmp = malloc(n * sizeof *tmp);
int32_t *key = malloc(n * sizeof *key);
int32_t *cnt = malloc((n + 258) * sizeof *cnt);
if (!sa || !sa2 || !rank || !tmp || !key || !cnt) exit(2);
int32_t maxrank = 0;
for (size_t i = 0; i < n; i++) {
sa[i] = (int32_t)i;
rank[i] = d[i];
if (d[i] > maxrank) maxrank = d[i];
}
for (size_t k = 1; k < n; k *= 2) {
/* sort by second key rank[(i+k) % n], then first key rank[i];
* (i+k) % n without division: i+k < 2n always (k < n). */
for (size_t i = 0; i + k < n; i++) key[i] = rank[i + k] + 1;
for (size_t i = n - k; i < n; i++) key[i] = rank[i + k - n] + 1;
csort(sa, sa2, key, n, maxrank + 1, cnt);
for (size_t i = 0; i < n; i++) key[i] = rank[i] + 1;
csort(sa, sa2, key, n, maxrank + 1, cnt);
tmp[sa[0]] = 0;
int32_t r = 0;
for (size_t i = 1; i < n; i++) {
int32_t x = sa[i - 1], y = sa[i];
size_t x2 = (size_t)x + k; if (x2 >= n) x2 -= n;
size_t y2 = (size_t)y + k; if (y2 >= n) y2 -= n;
if (rank[x] != rank[y] || rank[x2] != rank[y2]) r++;
tmp[y] = r;
}
memcpy(rank, tmp, n * sizeof *rank);
maxrank = r;
if (maxrank == (int32_t)n - 1) break;
}
free(sa2); free(rank); free(tmp); free(key); free(cnt);
return sa;
}
static int encode(const char *inpath, const char *outpath) {
size_t n;
uint8_t *in = slurp(inpath, &n);
uint32_t primary = 0;
uint8_t *bwt = malloc(n ? n : 1);
if (!bwt) return 2;
if (n > 0) {
int32_t *sa = build_sa(in, n);
for (size_t i = 0; i < n; i++) {
size_t sv = (size_t)sa[i];
if (sv == 0) primary = (uint32_t)i;
bwt[i] = in[(sv + n - 1) % n];
}
free(sa);
}
/* MTF */
uint8_t *mtf = malloc(n ? n : 1);
uint8_t lst[256];
for (int i = 0; i < 256; i++) lst[i] = (uint8_t)i;
for (size_t i = 0; i < n; i++) {
uint8_t c = bwt[i];
int pos = 0;
while (lst[pos] != c) pos++;
mtf[i] = (uint8_t)pos;
memmove(lst + 1, lst, (size_t)pos);
lst[0] = c;
}
free(bwt);
/* run tokenisation into 257-symbol stream */
uint16_t *tok = malloc((2 * n + 2) * sizeof *tok);
if (!tok) return 2;
size_t nt = 0, i = 0;
while (i < n) {
size_t j = i + 1;
while (j < n && mtf[j] == mtf[i]) j++;
size_t run = j - i;
if (run < 4) {
for (size_t k = 0; k < run; k++) tok[nt++] = mtf[i];
} else {
tok[nt++] = mtf[i];
size_t rem = run - 1;
while (rem > 0) {
size_t chunk = rem > 255 ? 255 : rem;
tok[nt++] = RUN_SYM;
tok[nt++] = (uint16_t)chunk;
rem -= chunk;
}
}
i = j;
}
free(mtf);
uint16_t freq[NSYM];
rans_freq_n(tok, nt, NSYM, freq);
uint8_t *stream = malloc(2 * nt + 64);
if (!stream) return 2;
size_t slen = rans_encode_raw_n(tok, nt, freq, NSYM, stream);
size_t hdr = 4 + 4 + 4 + 4 + NSYM * 2;
uint8_t *out = malloc(hdr + slen);
if (!out) return 2;
uint8_t *p = out;
memcpy(p, "BWTX", 4); p += 4;
put32(p, (uint32_t)n); p += 4;
put32(p, primary); p += 4;
put32(p, (uint32_t)nt); p += 4;
for (int s = 0; s < NSYM; s++) {
p[0] = (uint8_t)freq[s]; p[1] = (uint8_t)(freq[s] >> 8); p += 2;
}
memcpy(p, stream, slen); p += slen;
spit(outpath, out, (size_t)(p - out));
return 0;
}
static int decode(const char *inpath, const char *outpath) {
size_t n;
uint8_t *in = slurp(inpath, &n);
size_t hdr = 4 + 4 + 4 + 4 + NSYM * 2;
if (n < hdr || memcmp(in, "BWTX", 4) != 0) {
fprintf(stderr, "bwt: bad magic/header\n");
return 3;
}
const uint8_t *p = in + 4;
uint32_t orig = get32(p); p += 4;
uint32_t primary = get32(p); p += 4;
uint32_t nt = get32(p); p += 4;
uint16_t freq[NSYM];
for (int s = 0; s < NSYM; s++) {
freq[s] = (uint16_t)(p[0] | (p[1] << 8)); p += 2;
}
uint16_t *tok = malloc((nt ? nt : 1) * sizeof *tok);
if (!tok) return 2;
if (rans_decode_raw_n(p, n - hdr, freq, NSYM, tok, nt) != 0) {
fprintf(stderr, "bwt: token stream corrupt\n");
return 3;
}
/* expand runs to MTF values */
uint8_t *mtf = malloc(orig ? orig : 1);
if (!mtf) return 2;
size_t m = 0;
uint8_t last = 0;
for (uint32_t i = 0; i < nt; i++) {
uint16_t s = tok[i];
if (s == RUN_SYM) {
if (i + 1 >= nt) { fprintf(stderr, "bwt: truncated run\n"); return 3; }
uint16_t k = tok[++i];
if (m + k > orig) { fprintf(stderr, "bwt: run overrun\n"); return 3; }
memset(mtf + m, last, k);
m += k;
} else {
if (m >= orig) { fprintf(stderr, "bwt: mtf overrun\n"); return 3; }
last = (uint8_t)s;
mtf[m++] = last;
}
}
if (m != orig) { fprintf(stderr, "bwt: short mtf %zu != %u\n", m, orig); return 3; }
free(tok);
/* inverse MTF */
uint8_t *bwt = malloc(orig ? orig : 1);
uint8_t lst[256];
for (int i = 0; i < 256; i++) lst[i] = (uint8_t)i;
for (size_t k = 0; k < orig; k++) {
uint8_t c = lst[mtf[k]];
bwt[k] = c;
memmove(lst + 1, lst, mtf[k]);
lst[0] = c;
}
free(mtf);
/* inverse BWT via LF-mapping */
uint8_t *out = malloc(orig ? orig : 1);
if (!out) return 2;
if (orig > 0) {
int32_t cnt[256] = {0};
for (size_t k = 0; k < orig; k++) cnt[bwt[k]]++;
int32_t C[256];
int32_t sum = 0;
for (int c = 0; c < 256; c++) { C[c] = sum; sum += cnt[c]; }
int32_t *lf = malloc(orig * sizeof *lf);
if (!lf) return 2;
int32_t occ[256] = {0};
for (size_t k = 0; k < orig; k++) {
uint8_t c = bwt[k];
lf[k] = C[c] + occ[c]++;
}
size_t idx = primary;
for (size_t k = orig; k-- > 0;) {
out[k] = bwt[idx];
idx = (size_t)lf[idx];
}
free(lf);
}
spit(outpath, out, orig);
return 0;
}
int main(int argc, char **argv) {
if (argc != 4 || (argv[1][0] != 'c' && argv[1][0] != 'd')) {
fprintf(stderr, "usage: %s c|d in out\n", argv[0]);
return 1;
}
return argv[1][0] == 'c' ? encode(argv[2], argv[3])
: decode(argv[2], argv[3]);
}
-260
View File
@@ -1,260 +0,0 @@
/* dict.c - word-dictionary transform (preprocessing stage for lzip).
* Builds a per-file dictionary of the most frequent words (alnum runs
* of length >= 3), replaces them with 2-byte codes, then the caller
* pipes the output through lzip. The dictionary is transmitted in
* the header, so the cost is honest.
* Format: magic "DICT", u32 orig_len, u16 ndict, then ndict entries
* (u8 len, bytes), then the transformed stream: 0xFF escape byte
* introduces a 2-byte code (little-endian); a literal 0xFF in the
* data is escaped as 0xFF 0xFF 0xFF (escape + code 0xFFFF = literal
* 0xFF); other bytes pass through. Words are maximal [A-Za-z0-9_]
* runs; only words in the dictionary are replaced.
* Usage: dict c in out | dict d in out
* (then: lzip -6 transformed; decode: lzip -d | dict d)
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#define ESC 0xFF
#define MAX_DICT 4096
#define MIN_WORD 3
static uint8_t *slurp(const char *path, size_t *n) {
FILE *f = fopen(path, "rb");
if (!f) { perror(path); exit(2); }
fseek(f, 0, SEEK_END);
long sz = ftell(f);
fseek(f, 0, SEEK_SET);
uint8_t *b = malloc(sz ? (size_t)sz : 1);
if (!b) exit(2);
if (sz && fread(b, 1, (size_t)sz, f) != (size_t)sz) exit(2);
fclose(f);
*n = (size_t)sz;
return b;
}
static void spit(const char *path, const uint8_t *b, size_t n) {
FILE *f = fopen(path, "wb");
if (!f) { perror(path); exit(2); }
if (n && fwrite(b, 1, n, f) != n) exit(2);
fclose(f);
}
static int is_word(int c) {
return (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') ||
(c >= '0' && c <= '9') || c == '_';
}
/* word table entry */
typedef struct { char *w; uint32_t count; } went_t;
static int cmp_count(const void *a, const void *b) {
uint32_t ca = ((const went_t *)a)->count, cb = ((const went_t *)b)->count;
return ca < cb ? 1 : ca > cb ? -1 : 0;
}
static uint32_t hash_str(const char *s, size_t n) {
uint32_t h = 2166136261u;
for (size_t i = 0; i < n; i++) { h ^= (uint8_t)s[i]; h *= 16777619u; }
return h;
}
static int encode(const char *inpath, const char *outpath) {
size_t n;
uint8_t *in = slurp(inpath, &n);
/* count words in a hash table (open addressing) */
size_t hcap = 1 << 20;
went_t *ht = calloc(hcap, sizeof *ht);
if (!ht) return 2;
size_t i = 0;
while (i < n) {
if (!is_word(in[i])) { i++; continue; }
size_t j = i;
while (j < n && is_word(in[j])) j++;
size_t len = j - i;
if (len >= MIN_WORD) {
uint32_t h = hash_str((char *)in + i, len) & (hcap - 1);
while (ht[h].w) {
if (strlen(ht[h].w) == len &&
memcmp(ht[h].w, in + i, len) == 0) break;
h = (h + 1) & (hcap - 1);
}
if (!ht[h].w) {
ht[h].w = malloc(len + 1);
memcpy(ht[h].w, in + i, len);
ht[h].w[len] = 0;
}
ht[h].count++;
}
i = j;
}
/* collect, sort by count, keep the top MAX_DICT by SAVING:
* saving = count * (len - 3) - (len + 1) [dict cost]; keep > 0 */
went_t *all = malloc(hcap * sizeof *all);
size_t na = 0;
for (size_t k = 0; k < hcap; k++)
if (ht[k].w) all[na++] = ht[k];
qsort(all, na, sizeof *all, cmp_count);
went_t *dict = malloc(MAX_DICT * sizeof *dict);
size_t nd = 0;
for (size_t k = 0; k < na && nd < MAX_DICT; k++) {
size_t len = strlen(all[k].w);
/* code costs 3 bytes (ESC + 2), word costs len; saving per
* occurrence = len - 3; dict entry costs len + 1 bytes */
int64_t saving = (int64_t)all[k].count * ((int64_t)len - 3) -
(int64_t)(len + 1);
if (saving <= 0) continue; /* sorted by count, not saving */
dict[nd++] = all[k];
}
/* rebuild a lookup hash for the kept dictionary: code = index */
size_t lcap = 1 << 16;
int32_t *look = malloc(lcap * sizeof *look);
if (!look) return 2;
for (size_t k = 0; k < lcap; k++) look[k] = -1;
for (size_t k = 0; k < nd; k++) {
size_t len = strlen(dict[k].w);
uint32_t h = hash_str(dict[k].w, len) & (lcap - 1);
while (look[h] >= 0) h = (h + 1) & (lcap - 1);
look[h] = (int32_t)k;
}
/* transform */
size_t cap = n + 1024;
uint8_t *out = malloc(cap);
if (!out) return 2;
size_t o = 0;
/* make room for the dictionary header */
{
size_t hdr = 10;
for (size_t k = 0; k < nd; k++) hdr += 1 + strlen(dict[k].w);
if (cap < hdr + 16) {
cap = hdr + 16;
out = realloc(out, cap);
if (!out) return 2;
}
}
/* header: magic, orig_len, ndict, entries */
memcpy(out, "DICT", 4); o += 4;
out[o++] = (uint8_t)(n & 0xff);
out[o++] = (uint8_t)((n >> 8) & 0xff);
out[o++] = (uint8_t)((n >> 16) & 0xff);
out[o++] = (uint8_t)((n >> 24) & 0xff);
out[o++] = (uint8_t)(nd & 0xff);
out[o++] = (uint8_t)((nd >> 8) & 0xff);
for (size_t k = 0; k < nd; k++) {
size_t len = strlen(dict[k].w);
out[o++] = (uint8_t)len;
memcpy(out + o, dict[k].w, len);
o += len;
}
/* growable body: recompute with room (header already written) */
i = 0;
while (i < n) {
/* ensure room for the worst case (1 byte -> 3 bytes) + slack */
if (o + 8 > cap) {
cap *= 2;
out = realloc(out, cap);
if (!out) return 2;
}
if (is_word(in[i])) {
size_t j = i;
while (j < n && is_word(in[j])) j++;
size_t len = j - i;
int code = -1;
if (len >= MIN_WORD) {
uint32_t h = hash_str((char *)in + i, len) & (lcap - 1);
while (look[h] >= 0) {
int32_t k = look[h];
if (strlen(dict[k].w) == len &&
memcmp(dict[k].w, in + i, len) == 0) { code = k; break; }
h = (h + 1) & (lcap - 1);
}
}
if (code >= 0) {
out[o++] = ESC;
out[o++] = (uint8_t)(code & 0xff);
out[o++] = (uint8_t)((code >> 8) & 0xff);
} else {
memcpy(out + o, in + i, len);
o += len;
}
i = j;
} else {
uint8_t c = in[i++];
if (c == ESC) {
out[o++] = ESC;
out[o++] = 0xFF;
out[o++] = 0xFF;
} else {
out[o++] = c;
}
}
}
spit(outpath, out, o);
fprintf(stderr, "dict: %zu words kept (of %zu distinct)\n", nd, na);
return 0;
}
static int decode(const char *inpath, const char *outpath) {
size_t n;
uint8_t *in = slurp(inpath, &n);
if (n < 10 || memcmp(in, "DICT", 4) != 0) {
fprintf(stderr, "dict: bad magic/header\n");
return 3;
}
uint32_t orig = (uint32_t)in[4] | ((uint32_t)in[5] << 8) |
((uint32_t)in[6] << 16) | ((uint32_t)in[7] << 24);
uint32_t nd = (uint32_t)in[8] | ((uint32_t)in[9] << 8);
size_t p = 10;
char **dict = malloc((nd ? nd : 1) * sizeof *dict);
if (!dict) return 2;
for (uint32_t k = 0; k < nd; k++) {
if (p >= n) { fprintf(stderr, "dict: truncated dict\n"); return 3; }
size_t len = in[p++];
if (p + len > n) { fprintf(stderr, "dict: truncated dict\n"); return 3; }
dict[k] = malloc(len + 1);
memcpy(dict[k], in + p, len);
dict[k][len] = 0;
p += len;
}
uint8_t *out = malloc(orig ? orig : 1);
if (!out) return 2;
size_t o = 0;
while (p < n) {
uint8_t c = in[p++];
if (c == ESC) {
if (p + 1 >= n) { fprintf(stderr, "dict: truncated code\n"); return 3; }
uint32_t code = (uint32_t)in[p] | ((uint32_t)in[p + 1] << 8);
p += 2;
if (code == 0xFFFF) {
if (o >= orig) return 3;
out[o++] = ESC;
} else {
if (code >= nd) { fprintf(stderr, "dict: bad code\n"); return 3; }
size_t len = strlen(dict[code]);
if (o + len > orig) return 3;
memcpy(out + o, dict[code], len);
o += len;
}
} else {
if (o >= orig) return 3;
out[o++] = c;
}
}
if (o != orig) {
fprintf(stderr, "dict: short output %zu != %u\n", o, orig);
return 3;
}
spit(outpath, out, o);
return 0;
}
int main(int argc, char **argv) {
if (argc != 4 || (argv[1][0] != 'c' && argv[1][0] != 'd')) {
fprintf(stderr, "usage: %s c|d in out\n", argv[0]);
return 1;
}
return argv[1][0] == 'c' ? encode(argv[2], argv[3])
: decode(argv[2], argv[3]);
}
-412
View File
@@ -1,412 +0,0 @@
/* lzrans.c - LZ77 + rANS prototype for the lzply compression research.
* Hash-chain match finder (1 MiB window), lazy matching (`c`) or
* optimal parsing (`o`, DP over match costs; per candidate only its
* full length is considered), deflate-style length codes (29) and
* log2 distance codes (21, dist up to 2^20). Three streams: litlen
* (286 symbols: 0-255 literal, 256-284 length code, 285 end), dist
* (21 symbols), extra bits (raw LSB-first). Each token stream is
* rANS-coded with its own transmitted freq table.
* Usage: lzrans c|o in out | lzrans d in out
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include "rans.h"
#define WINDOW (1u << 20)
#define MAX_MATCH 258
#define MIN_MATCH 3
#define HASH_BITS 16
#define HASH_SIZE (1u << HASH_BITS)
#define LITLEN_END 285
static const int len_base[29] = {3,4,5,6,7,8,9,10,11,13,15,17,19,23,27,31,35,
43,51,59,67,83,99,115,131,163,195,227,258};
static const int len_extra[29] = {0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,
4,4,4,4,5,5,5,5,0};
static int len_code_of(int len) {
int c = 0;
while (c < 28 && len >= len_base[c + 1]) c++;
return c;
}
/* dist 1..2^20 -> code 0..19, extra bits = code, base = 1<<code */
static int dist_code_of(uint32_t d) { return 31 - __builtin_clz(d); }
static uint8_t *slurp(const char *path, size_t *n) {
FILE *f = fopen(path, "rb");
if (!f) { perror(path); exit(2); }
fseek(f, 0, SEEK_END);
long sz = ftell(f);
fseek(f, 0, SEEK_SET);
uint8_t *b = malloc(sz ? (size_t)sz : 1);
if (!b) exit(2);
if (sz && fread(b, 1, (size_t)sz, f) != (size_t)sz) exit(2);
fclose(f);
*n = (size_t)sz;
return b;
}
static void spit(const char *path, const uint8_t *b, size_t n) {
FILE *f = fopen(path, "wb");
if (!f) { perror(path); exit(2); }
if (n && fwrite(b, 1, n, f) != n) exit(2);
fclose(f);
}
static void put32(uint8_t *p, uint32_t v) {
p[0] = (uint8_t)v; p[1] = (uint8_t)(v >> 8);
p[2] = (uint8_t)(v >> 16); p[3] = (uint8_t)(v >> 24);
}
static uint32_t get32(const uint8_t *p) {
return (uint32_t)p[0] | ((uint32_t)p[1] << 8) |
((uint32_t)p[2] << 16) | ((uint32_t)p[3] << 24);
}
/* ---- bit writer (LSB-first) ---- */
typedef struct { uint8_t *buf; size_t len, cap; uint32_t acc; int nbits; } bitw_t;
static void bitw_put(bitw_t *w, uint32_t v, int n) {
w->acc |= v << w->nbits;
w->nbits += n;
while (w->nbits >= 8) {
if (w->len == w->cap) {
w->cap = w->cap ? w->cap * 2 : 4096;
w->buf = realloc(w->buf, w->cap);
if (!w->buf) exit(2);
}
w->buf[w->len++] = (uint8_t)(w->acc & 0xff);
w->acc >>= 8;
w->nbits -= 8;
}
}
static void bitw_flush(bitw_t *w) {
if (w->nbits) {
if (w->len == w->cap) {
w->cap = w->cap ? w->cap * 2 : 4096;
w->buf = realloc(w->buf, w->cap);
if (!w->buf) exit(2);
}
w->buf[w->len++] = (uint8_t)(w->acc & 0xff);
w->acc = 0; w->nbits = 0;
}
}
/* ---- bit reader (LSB-first) ---- */
typedef struct { const uint8_t *buf; size_t len, pos; uint32_t acc; int nbits; } bitr_t;
static uint32_t bitr_get(bitr_t *r, int n) {
while (r->nbits < n) {
uint32_t b = r->pos < r->len ? r->buf[r->pos++] : 0;
r->acc |= b << r->nbits;
r->nbits += 8;
}
uint32_t v = n == 32 ? r->acc : (r->acc & ((n == 0) ? 0u : ((1u << n) - 1)));
r->acc >>= n;
r->nbits -= n;
return v;
}
/* ---- match finder ---- */
typedef struct {
const uint8_t *data;
size_t n;
int32_t head[HASH_SIZE];
int32_t *prev;
} mf_t;
static uint32_t hash4(const uint8_t *p) {
uint32_t v = (uint32_t)p[0] | ((uint32_t)p[1] << 8) |
((uint32_t)p[2] << 16) | ((uint32_t)p[3] << 24);
return (v * 2654435761u) >> (32 - HASH_BITS);
}
static void mf_insert(mf_t *m, size_t pos) {
if (pos + 4 > m->n) return;
uint32_t h = hash4(m->data + pos);
m->prev[pos] = m->head[h];
m->head[h] = (int32_t)pos;
}
/* Longest match at pos (limit capped by caller). Returns 0 if < 3. */
static int mf_find(mf_t *m, size_t pos, int limit, int max_chain,
int *dist_out) {
if (pos + 4 > m->n) return 0;
uint32_t h = hash4(m->data + pos);
int32_t cand = m->head[h];
int best = 2, bestd = 0, chain = 0;
while (cand >= 0 && chain++ < max_chain) {
size_t c = (size_t)cand;
size_t d = pos - c;
if (d > WINDOW) break;
if (best >= 3) {
/* quick reject: byte at best must match */
if (c + (size_t)best >= m->n ||
m->data[c + best] != m->data[pos + best]) {
cand = m->prev[cand];
continue;
}
}
int l = 0;
while (l < limit && pos + (size_t)l < m->n &&
m->data[c + l] == m->data[pos + l]) l++;
if (l > best) {
best = l; bestd = (int)d;
if (best >= limit) break;
}
cand = m->prev[cand];
}
*dist_out = bestd;
return best >= MIN_MATCH ? best : 0;
}
/* ---- token streams ---- */
typedef struct {
uint16_t *litlen; size_t nlit, clit;
uint16_t *dist; size_t ndist, cdist;
bitw_t bits;
} toks_t;
static void toks_init(toks_t *t, size_t n) {
t->clit = n + 2; t->litlen = malloc(t->clit * 2);
t->cdist = n / 3 + 2; t->dist = malloc(t->cdist * 2);
t->nlit = t->ndist = 0;
memset(&t->bits, 0, sizeof t->bits);
if (!t->litlen || !t->dist) exit(2);
}
static void toks_lit(toks_t *t, uint8_t b) { t->litlen[t->nlit++] = b; }
static void toks_match(toks_t *t, int len, int dist) {
int lc = len_code_of(len);
t->litlen[t->nlit++] = (uint16_t)(256 + lc);
int dc = dist_code_of((uint32_t)dist);
t->dist[t->ndist++] = (uint16_t)dc;
bitw_put(&t->bits, (uint32_t)(len - len_base[lc]), len_extra[lc]);
bitw_put(&t->bits, (uint32_t)(dist - (1 << dc)), dc);
}
/* ---- lazy parse ---- */
static void parse_lazy(mf_t *m, toks_t *t) {
size_t n = m->n, pos = 0;
while (pos < n) {
if (n - pos < MIN_MATCH) { toks_lit(t, m->data[pos++]); continue; }
int d1 = 0;
int l1 = mf_find(m, pos, (int)(n - pos < MAX_MATCH ? n - pos : MAX_MATCH),
128, &d1);
if (l1 >= MIN_MATCH) {
mf_insert(m, pos);
int l2 = 0, d2 = 0;
if (n - (pos + 1) >= MIN_MATCH)
l2 = mf_find(m, pos + 1,
(int)(n - pos - 1 < MAX_MATCH ? n - pos - 1 : MAX_MATCH),
128, &d2);
if (l2 > l1) { toks_lit(t, m->data[pos]); pos++; continue; }
toks_match(t, l1, d1);
for (int k = 1; k < l1; k++) mf_insert(m, pos + (size_t)k);
pos += (size_t)l1;
} else {
toks_lit(t, m->data[pos]);
mf_insert(m, pos);
pos++;
}
}
}
/* ---- optimal parse (DP; per candidate only its full length) ---- */
static void parse_opt(mf_t *m, toks_t *t) {
size_t n = m->n;
double *cost = malloc((n + 1) * sizeof *cost);
int32_t *ch_len = malloc((n + 1) * sizeof *ch_len);
int32_t *ch_dist = malloc((n + 1) * sizeof *ch_dist);
if (!cost || !ch_len || !ch_dist) exit(2);
for (size_t i = 0; i <= n; i++) { cost[i] = 1e100; ch_len[i] = 0; ch_dist[i] = 0; }
cost[0] = 0;
for (size_t i = 0; i < n; i++) {
if (cost[i] < 1e99 && n - i >= MIN_MATCH) {
/* literal */
if (cost[i] + 9.0 < cost[i + 1]) {
cost[i + 1] = cost[i] + 9.0; ch_len[i + 1] = 0;
}
/* matches: walk the chain, full length per candidate */
if (i + 4 <= n) {
uint32_t h = hash4(m->data + i);
int32_t cand = m->head[h];
int chain = 0, best = 2;
int limit = (int)(n - i < MAX_MATCH ? n - i : MAX_MATCH);
while (cand >= 0 && chain++ < 32) {
size_t c = (size_t)cand;
size_t d = i - c;
if (d > WINDOW) break;
if (best >= 3 && (c + (size_t)best >= n ||
m->data[c + best] != m->data[i + best])) {
cand = m->prev[cand];
continue;
}
int l = 0;
while (l < limit && m->data[c + l] == m->data[i + l]) l++;
if (l >= MIN_MATCH && l > 2) {
int lc = len_code_of(l);
int dc = dist_code_of((uint32_t)d);
double mc = cost[i] + 8.0 + len_extra[lc] + 5.0 + dc;
if (mc < cost[i + (size_t)l]) {
cost[i + (size_t)l] = mc;
ch_len[i + (size_t)l] = l;
ch_dist[i + (size_t)l] = (int32_t)d;
}
if (l > best) best = l;
}
cand = m->prev[cand];
}
}
}
mf_insert(m, i);
}
/* reconstruct backwards, then reverse */
size_t pos = n, nt = 0;
uint16_t *rl = malloc((n + 1) * 2);
int32_t *rd = malloc((n + 1) * 4);
int32_t *rlen = malloc((n + 1) * 4);
if (!rl || !rd || !rlen) exit(2);
while (pos > 0) {
int32_t l = ch_len[pos];
if (l == 0) { rl[nt] = m->data[pos - 1]; rlen[nt] = 0; rd[nt] = 0; nt++; pos--; }
else { rl[nt] = 0; rlen[nt] = l; rd[nt] = ch_dist[pos]; nt++; pos -= (size_t)l; }
}
for (size_t k = nt; k-- > 0;) {
if (rlen[k] == 0) toks_lit(t, (uint8_t)rl[k]);
else toks_match(t, rlen[k], rd[k]);
}
free(cost); free(ch_len); free(ch_dist); free(rl); free(rd); free(rlen);
}
static int encode(const char *inpath, const char *outpath, int optimal) {
size_t n;
uint8_t *in = slurp(inpath, &n);
mf_t m;
m.data = in; m.n = n;
memset(m.head, 0xff, sizeof m.head);
m.prev = malloc((n ? n : 1) * sizeof *m.prev);
if (!m.prev) return 2;
toks_t t;
toks_init(&t, n);
if (optimal) parse_opt(&m, &t);
else parse_lazy(&m, &t);
t.litlen[t.nlit++] = LITLEN_END;
bitw_flush(&t.bits);
uint16_t freq_ll[286], freq_d[21];
rans_freq_n(t.litlen, t.nlit, 286, freq_ll);
rans_freq_n(t.dist, t.ndist, 21, freq_d);
uint8_t *s_ll = malloc(2 * t.nlit + 64);
uint8_t *s_d = malloc(2 * t.ndist + 64);
if (!s_ll || !s_d) return 2;
size_t sll_len = rans_encode_raw_n(t.litlen, t.nlit, freq_ll, 286, s_ll);
size_t sd_len = rans_encode_raw_n(t.dist, t.ndist, freq_d, 21, s_d);
size_t hdr = 4 + 4 + 1 + 20 + 286 * 2 + 21 * 2;
size_t total = hdr + sll_len + sd_len + t.bits.len;
uint8_t *out = malloc(total ? total : 1);
if (!out) return 2;
uint8_t *p = out;
memcpy(p, "LZRA", 4); p += 4;
put32(p, (uint32_t)n); p += 4;
*p++ = optimal ? 1 : 0;
put32(p, (uint32_t)t.nlit); p += 4;
put32(p, (uint32_t)t.ndist); p += 4;
put32(p, (uint32_t)t.bits.len); p += 4;
put32(p, (uint32_t)sll_len); p += 4;
put32(p, (uint32_t)sd_len); p += 4;
for (int s = 0; s < 286; s++) { p[0] = (uint8_t)freq_ll[s]; p[1] = (uint8_t)(freq_ll[s] >> 8); p += 2; }
for (int s = 0; s < 21; s++) { p[0] = (uint8_t)freq_d[s]; p[1] = (uint8_t)(freq_d[s] >> 8); p += 2; }
memcpy(p, s_ll, sll_len); p += sll_len;
memcpy(p, s_d, sd_len); p += sd_len;
memcpy(p, t.bits.buf, t.bits.len); p += t.bits.len;
spit(outpath, out, (size_t)(p - out));
return 0;
}
static int decode(const char *inpath, const char *outpath) {
size_t n;
uint8_t *in = slurp(inpath, &n);
size_t hdr = 4 + 4 + 1 + 20 + 286 * 2 + 21 * 2;
if (n < hdr || memcmp(in, "LZRA", 4) != 0) {
fprintf(stderr, "lzrans: bad magic/header\n");
return 3;
}
const uint8_t *p = in + 4;
uint32_t orig = get32(p); p += 4;
p++; /* mode */
uint32_t nlit = get32(p); p += 4;
uint32_t ndist = get32(p); p += 4;
uint32_t ebits = get32(p); p += 4;
uint32_t sll_len = get32(p); p += 4;
uint32_t sd_len = get32(p); p += 4;
uint16_t freq_ll[286], freq_d[21];
for (int s = 0; s < 286; s++) { freq_ll[s] = (uint16_t)(p[0] | (p[1] << 8)); p += 2; }
for (int s = 0; s < 21; s++) { freq_d[s] = (uint16_t)(p[0] | (p[1] << 8)); p += 2; }
if ((size_t)(p - in) + sll_len + sd_len + ebits != n) {
fprintf(stderr, "lzrans: truncated file\n");
return 3;
}
uint16_t *litlen = malloc((nlit ? nlit : 1) * 2);
uint16_t *dist = malloc((ndist ? ndist : 1) * 2);
if (!litlen || !dist) return 2;
if (rans_decode_raw_n(p, sll_len, freq_ll, 286, litlen, nlit) != 0) {
fprintf(stderr, "lzrans: litlen stream corrupt\n");
return 3;
}
p += sll_len;
if (rans_decode_raw_n(p, sd_len, freq_d, 21, dist, ndist) != 0) {
fprintf(stderr, "lzrans: dist stream corrupt\n");
return 3;
}
p += sd_len;
uint8_t *out = malloc(orig ? orig : 1);
if (!out) return 2;
bitr_t br = { p, ebits, 0, 0, 0 };
size_t opos = 0, di = 0;
for (uint32_t i = 0; i < nlit; i++) {
uint16_t s = litlen[i];
if (s < 256) {
if (opos >= orig) { fprintf(stderr, "lzrans: overrun\n"); return 3; }
out[opos++] = (uint8_t)s;
} else if (s == LITLEN_END) {
break;
} else {
int lc = s - 256;
if (lc < 0 || lc > 28 || di >= ndist) {
fprintf(stderr, "lzrans: bad token\n");
return 3;
}
int len = len_base[lc] + (int)bitr_get(&br, len_extra[lc]);
int dc = dist[di++];
if (dc < 0 || dc > 20) { fprintf(stderr, "lzrans: bad dist\n"); return 3; }
int d = (1 << dc) + (int)bitr_get(&br, dc);
if ((size_t)d > opos || opos + (size_t)len > orig) {
fprintf(stderr, "lzrans: bad match\n");
return 3;
}
for (int k = 0; k < len; k++) {
out[opos] = out[opos - (size_t)d];
opos++;
}
}
}
if (opos != orig) {
fprintf(stderr, "lzrans: short output %zu != %u\n", opos, orig);
return 3;
}
spit(outpath, out, opos);
return 0;
}
int main(int argc, char **argv) {
if (argc != 4) {
fprintf(stderr, "usage: %s c|o|d in out\n", argv[0]);
return 1;
}
if (argv[1][0] == 'c') return encode(argv[2], argv[3], 0);
if (argv[1][0] == 'o') return encode(argv[2], argv[3], 1);
if (argv[1][0] == 'd') return decode(argv[2], argv[3]);
fprintf(stderr, "usage: %s c|o|d in out\n", argv[0]);
return 1;
}
-77
View File
@@ -1,77 +0,0 @@
#!/usr/bin/env python3
"""Build deterministic benchmark corpora on the server. Sizes capped.
text: /usr/share/doc text files + common-licenses (English prose/docs)
code: /usr/include headers + this repo sources (C/Markdown)
bin: ELF binaries from /bin, /usr/bin (executables)
mixed: round-robin 64KiB chunks of text+code+bin
rand: /dev/urandom control (incompressible)
"""
import os, glob, hashlib, random
OUT = os.path.join(os.path.dirname(os.path.abspath(__file__)), "corpora")
CAP = 8 * 1024 * 1024
def collect(patterns, cap, text_only=False):
buf = bytearray()
files = []
for p in patterns:
files += sorted(glob.glob(p, recursive=True))
for f in files:
try:
if not os.path.isfile(f):
continue
with open(f, "rb") as fh:
d = fh.read()
except OSError:
continue
if text_only:
try:
d.decode("utf-8")
except UnicodeDecodeError:
continue
buf += d
if len(buf) >= cap:
break
return bytes(buf[:cap])
def write(name, data):
p = os.path.join(OUT, name)
with open(p, "wb") as fh:
fh.write(data)
print(name + ": " + str(len(data)) + " bytes sha256=" + hashlib.sha256(data).hexdigest()[:16])
text = collect(["/usr/share/doc/**/*", "/usr/share/common-licenses/*"], CAP, text_only=True)
write("text", text)
code = collect(["/usr/include/**/*.h", "/opt/lzply-exp-comp/*.c",
"/opt/lzply-exp-comp/*.h", "/opt/lzply-exp-comp/*.md"], CAP)
write("code", code)
bins = []
for d in ("/bin", "/usr/bin"):
for f in sorted(glob.glob(d + "/*")):
try:
with open(f, "rb") as fh:
h = fh.read(4)
if h[:4] == b"\x7fELF":
bins.append(f)
except OSError:
pass
buf = bytearray()
for f in bins:
with open(f, "rb") as fh:
buf += fh.read()
if len(buf) >= CAP:
break
bindata = bytes(buf[:CAP])
write("bin", bindata)
parts = [text, code, bindata]
m = bytearray()
i = 0
while len(m) < CAP:
for part in parts:
off = (i * 65536) % max(1, len(part) - 65536)
m += part[off:off + 65536]
if len(m) >= CAP:
break
i += 1
write("mixed", bytes(m[:CAP]))
rnd = random.Random(1234).randbytes(4 * 1024 * 1024)
write("rand", rnd)
-349
View File
@@ -1,349 +0,0 @@
/* ppm.c - order-2 PPM + arithmetic coding prototype (context mixing).
* Three context levels (order-2, order-1, order-0) with escape to the
* next level; escape mass = number of distinct symbols seen in the
* context. Order -1 is uniform over 256 symbols. The coder is the
* classic Witten-Neal-Cleary 32-bit arithmetic coder (E1/E2/E3).
* Counts are updated in ALL levels after every symbol, on both sides.
* Usage: ppm c in out | ppm d in out
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#define ESC 256
#define NSYM 257
static uint8_t *slurp(const char *path, size_t *n) {
FILE *f = fopen(path, "rb");
if (!f) { perror(path); exit(2); }
fseek(f, 0, SEEK_END);
long sz = ftell(f);
fseek(f, 0, SEEK_SET);
uint8_t *b = malloc(sz ? (size_t)sz : 1);
if (!b) exit(2);
if (sz && fread(b, 1, (size_t)sz, f) != (size_t)sz) exit(2);
fclose(f);
*n = (size_t)sz;
return b;
}
static void spit(const char *path, const uint8_t *b, size_t n) {
FILE *f = fopen(path, "wb");
if (!f) { perror(path); exit(2); }
if (n && fwrite(b, 1, n, f) != n) exit(2);
fclose(f);
}
/* ---- bit writer (MSB-first) ---- */
typedef struct {
uint8_t *buf; size_t len, cap;
uint32_t acc; int nbits;
} bitw_t;
static void bitw_put(bitw_t *w, int bit) {
w->acc = (w->acc << 1) | (uint32_t)bit;
if (++w->nbits == 8) {
if (w->len == w->cap) {
w->cap = w->cap ? w->cap * 2 : 65536;
w->buf = realloc(w->buf, w->cap);
if (!w->buf) exit(2);
}
w->buf[w->len++] = (uint8_t)w->acc;
w->acc = 0; w->nbits = 0;
}
}
static void bitw_flush(bitw_t *w) {
if (w->nbits) {
w->acc <<= (8 - w->nbits);
if (w->len == w->cap) {
w->cap = w->cap ? w->cap * 2 : 65536;
w->buf = realloc(w->buf, w->cap);
if (!w->buf) exit(2);
}
w->buf[w->len++] = (uint8_t)w->acc;
w->acc = 0; w->nbits = 0;
}
}
/* ---- bit reader (MSB-first, 0 past EOF) ---- */
typedef struct {
const uint8_t *buf; size_t len, pos;
uint32_t acc; int nbits;
} bitr_t;
static int bitr_get(bitr_t *r) {
if (r->nbits == 0) {
uint8_t b = r->pos < r->len ? r->buf[r->pos++] : 0;
r->acc = b; r->nbits = 8;
}
int bit = (int)((r->acc >> 7) & 1);
r->acc <<= 1; r->nbits--;
return bit;
}
/* ---- arithmetic coder ---- */
typedef struct {
uint32_t low, high;
int follow;
bitw_t *w;
} enc_t;
static void enc_bit(enc_t *e, int bit) {
bitw_put(e->w, bit);
while (e->follow > 0) { bitw_put(e->w, !bit); e->follow--; }
}
static void enc_symbol(enc_t *e, uint32_t cum_lo, uint32_t cum_hi, uint32_t total) {
uint64_t range = (uint64_t)(e->high - e->low) + 1;
e->high = e->low + (uint32_t)(range * cum_hi / total) - 1;
e->low = e->low + (uint32_t)(range * cum_lo / total);
for (;;) {
if (e->high < 0x80000000u) {
enc_bit(e, 0);
} else if (e->low >= 0x80000000u) {
enc_bit(e, 1);
e->low -= 0x80000000u; e->high -= 0x80000000u;
} else if (e->low >= 0x40000000u && e->high < 0xC0000000u) {
e->follow++;
e->low -= 0x40000000u; e->high -= 0x40000000u;
} else break;
e->low <<= 1; e->high = (e->high << 1) | 1;
}
}
static void enc_flush(enc_t *e) {
e->follow++;
if (e->low < 0x40000000u) enc_bit(e, 0);
else enc_bit(e, 1);
bitw_flush(e->w);
}
typedef struct {
uint32_t low, high, value;
bitr_t *r;
} dec_t;
static void dec_init(dec_t *d, bitr_t *r) {
d->low = 0; d->high = 0xFFFFFFFFu; d->value = 0; d->r = r;
for (int i = 0; i < 32; i++) d->value = (d->value << 1) | (uint32_t)bitr_get(r);
}
static uint32_t dec_cum(dec_t *d, uint32_t total) {
uint64_t range = (uint64_t)(d->high - d->low) + 1;
return (uint32_t)(((uint64_t)(d->value - d->low + 1) * total - 1) / range);
}
static void dec_update(dec_t *d, uint32_t cum_lo, uint32_t cum_hi, uint32_t total) {
uint64_t range = (uint64_t)(d->high - d->low) + 1;
d->high = d->low + (uint32_t)(range * cum_hi / total) - 1;
d->low = d->low + (uint32_t)(range * cum_lo / total);
for (;;) {
if (d->high < 0x80000000u) {
/* no shift */
} else if (d->low >= 0x80000000u) {
d->value -= 0x80000000u; d->low -= 0x80000000u; d->high -= 0x80000000u;
} else if (d->low >= 0x40000000u && d->high < 0xC0000000u) {
d->value -= 0x40000000u; d->low -= 0x40000000u; d->high -= 0x40000000u;
} else break;
d->low <<= 1; d->high = (d->high << 1) | 1;
d->value = (d->value << 1) | (uint32_t)bitr_get(d->r);
}
}
/* ---- PPM model ----
* cnt0[256], cnt1[256][256], cnt2[65536][256] (uint32), totals and
* distinct-symbol counts per context. ~64 MB for cnt2. */
static uint32_t *cnt2; /* [65536][256] */
static uint32_t cnt1[256][256];
static uint32_t cnt0[256];
static uint32_t tot2[65536];
static uint32_t tot1[256];
static uint32_t tot0;
static uint32_t dist2[65536];
static uint32_t dist1[256];
static uint32_t dist0;
static void model_reset(void) {
memset(cnt1, 0, sizeof cnt1);
memset(cnt0, 0, sizeof cnt0);
memset(tot2, 0, sizeof tot2);
memset(tot1, 0, sizeof tot1);
memset(dist2, 0, sizeof dist2);
memset(dist1, 0, sizeof dist1);
tot0 = 0; dist0 = 0;
if (cnt2) memset(cnt2, 0, (size_t)65536 * 256 * sizeof *cnt2);
}
static void model_update(int b, int p2, int p1) {
uint32_t c2 = (uint32_t)((p2 << 8) | p1);
uint32_t *row2 = cnt2 + (size_t)c2 * 256;
if (row2[b] == 0) dist2[c2]++;
row2[b]++;
tot2[c2]++;
if (cnt1[p1][b] == 0) dist1[p1]++;
cnt1[p1][b]++;
tot1[p1]++;
if (cnt0[b] == 0) dist0++;
cnt0[b]++;
tot0++;
}
/* Cumulative interval of symbol s (0..255) or ESC in a level.
* cnt: per-symbol counts; dist: escape mass; tot: symbol total.
* total = tot + dist. Returns 0 if the symbol has freq 0. */
static int level_interval(const uint32_t *cnt, uint32_t dist, uint32_t tot,
int s, uint32_t *lo, uint32_t *hi, uint32_t *total) {
*total = tot + dist;
uint32_t acc = 0;
if (s == ESC) {
for (int i = 0; i < 256; i++) acc += cnt[i];
*lo = acc; *hi = acc + dist;
return dist > 0;
}
for (int i = 0; i < s; i++) acc += cnt[i];
*lo = acc; *hi = acc + cnt[s];
return cnt[s] > 0;
}
/* Find the symbol for a cum value in a level; fills lo/hi/total. */
static int level_lookup(const uint32_t *cnt, uint32_t dist, uint32_t tot,
uint32_t cum, uint32_t *lo, uint32_t *hi,
uint32_t *total) {
*total = tot + dist;
uint32_t acc = 0;
for (int i = 0; i < 256; i++) {
uint32_t f = cnt[i];
if (cum < acc + f) { *lo = acc; *hi = acc + f; return i; }
acc += f;
}
*lo = acc; *hi = acc + dist;
return ESC;
}
static int encode(const char *inpath, const char *outpath) {
size_t n;
uint8_t *in = slurp(inpath, &n);
cnt2 = malloc((size_t)65536 * 256 * sizeof *cnt2);
if (!cnt2) return 2;
model_reset();
bitw_t w;
memset(&w, 0, sizeof w);
enc_t e = { 0, 0xFFFFFFFFu, 0, &w };
int p2 = 0, p1 = 0;
for (size_t i = 0; i < n; i++) {
int b = in[i];
uint32_t c2 = (uint32_t)((p2 << 8) | p1);
uint32_t *row2 = cnt2 + (size_t)c2 * 256;
uint32_t lo, hi, total;
int done = 0;
if (tot2[c2] > 0) {
if (level_interval(row2, dist2[c2], tot2[c2], b, &lo, &hi, &total)) {
enc_symbol(&e, lo, hi, total);
done = 1;
} else {
level_interval(row2, dist2[c2], tot2[c2], ESC, &lo, &hi, &total);
enc_symbol(&e, lo, hi, total);
}
}
if (!done && tot1[p1] > 0) {
if (level_interval(cnt1[p1], dist1[p1], tot1[p1], b, &lo, &hi, &total)) {
enc_symbol(&e, lo, hi, total);
done = 1;
} else {
level_interval(cnt1[p1], dist1[p1], tot1[p1], ESC, &lo, &hi, &total);
enc_symbol(&e, lo, hi, total);
}
}
if (!done && tot0 > 0) {
if (level_interval(cnt0, dist0, tot0, b, &lo, &hi, &total)) {
enc_symbol(&e, lo, hi, total);
done = 1;
} else {
level_interval(cnt0, dist0, tot0, ESC, &lo, &hi, &total);
enc_symbol(&e, lo, hi, total);
}
}
if (!done) {
/* order -1: uniform over 256 */
enc_symbol(&e, (uint32_t)b, (uint32_t)b + 1, 256);
}
model_update(b, p2, p1);
p2 = p1; p1 = b;
}
enc_flush(&e);
size_t total_out = 8 + w.len;
uint8_t *out = malloc(total_out ? total_out : 1);
if (!out) return 2;
memcpy(out, "PPM2", 4);
out[4] = (uint8_t)(n & 0xff);
out[5] = (uint8_t)((n >> 8) & 0xff);
out[6] = (uint8_t)((n >> 16) & 0xff);
out[7] = (uint8_t)((n >> 24) & 0xff);
memcpy(out + 8, w.buf, w.len);
spit(outpath, out, total_out);
return 0;
}
static int decode(const char *inpath, const char *outpath) {
size_t n;
uint8_t *in = slurp(inpath, &n);
if (n < 8 || memcmp(in, "PPM2", 4) != 0) {
fprintf(stderr, "ppm: bad magic/header\n");
return 3;
}
uint32_t orig = (uint32_t)in[4] | ((uint32_t)in[5] << 8) |
((uint32_t)in[6] << 16) | ((uint32_t)in[7] << 24);
cnt2 = malloc((size_t)65536 * 256 * sizeof *cnt2);
if (!cnt2) return 2;
model_reset();
bitr_t br = { in + 8, n - 8, 0, 0, 0 };
dec_t d;
dec_init(&d, &br);
uint8_t *out = malloc(orig ? orig : 1);
if (!out) return 2;
int p2 = 0, p1 = 0;
for (uint32_t i = 0; i < orig; i++) {
int b = -1;
uint32_t c2 = (uint32_t)((p2 << 8) | p1);
uint32_t *row2 = cnt2 + (size_t)c2 * 256;
uint32_t lo, hi, total, cum;
if (tot2[c2] > 0) {
cum = dec_cum(&d, tot2[c2] + dist2[c2]);
int s = level_lookup(row2, dist2[c2], tot2[c2], cum, &lo, &hi, &total);
dec_update(&d, lo, hi, total);
if (s != ESC) b = s;
}
if (b < 0 && tot1[p1] > 0) {
cum = dec_cum(&d, tot1[p1] + dist1[p1]);
int s = level_lookup(cnt1[p1], dist1[p1], tot1[p1], cum, &lo, &hi, &total);
dec_update(&d, lo, hi, total);
if (s != ESC) b = s;
}
if (b < 0 && tot0 > 0) {
cum = dec_cum(&d, tot0 + dist0);
int s = level_lookup(cnt0, dist0, tot0, cum, &lo, &hi, &total);
dec_update(&d, lo, hi, total);
if (s != ESC) b = s;
}
if (b < 0) {
cum = dec_cum(&d, 256);
b = (int)cum;
dec_update(&d, cum, cum + 1, 256);
}
out[i] = (uint8_t)b;
model_update(b, p2, p1);
p2 = p1; p1 = b;
}
spit(outpath, out, orig);
return 0;
}
int main(int argc, char **argv) {
if (argc != 4 || (argv[1][0] != 'c' && argv[1][0] != 'd')) {
fprintf(stderr, "usage: %s c|d in out\n", argv[0]);
return 1;
}
return argv[1][0] == 'c' ? encode(argv[2], argv[3])
: decode(argv[2], argv[3]);
}
-221
View File
@@ -1,221 +0,0 @@
/* rans.c - rANS entropy coder (see rans.h). Standard rANS:
* encode backwards, x in [2^23, 2^32); decode forwards from the
* 4-byte final state stored at the end of the stream. */
#include "rans.h"
#include <stdlib.h>
#include <string.h>
void rans_freq(const uint8_t *in, size_t n, uint16_t *freq) {
uint32_t cnt[256] = {0};
for (size_t i = 0; i < n; i++) cnt[in[i]]++;
uint32_t total = 0;
for (int s = 0; s < 256; s++) {
/* scale counts to PROB_SCALE, present symbols keep >= 1 */
uint32_t f = n ? (uint32_t)(((uint64_t)cnt[s] * RANS_PROB_SCALE) / n) : 0;
if (cnt[s] && f == 0) f = 1;
freq[s] = (uint16_t)f;
total += f;
}
/* Fix the sum to exactly PROB_SCALE by adjusting the largest. */
int mx = 0;
for (int s = 1; s < 256; s++) if (freq[s] > freq[mx]) mx = s;
if (total < RANS_PROB_SCALE) freq[mx] += (uint16_t)(RANS_PROB_SCALE - total);
else if (total > RANS_PROB_SCALE) {
uint32_t over = total - RANS_PROB_SCALE;
/* take from the largest symbol, never below 1 if present */
uint32_t give = freq[mx] - (cnt[mx] ? 1u : 0u);
if (give > over) give = over;
freq[mx] -= (uint16_t)give;
/* if still over (pathological), trim the next largest */
for (int s = 0; s < 256 && total - give > RANS_PROB_SCALE; s++) {
if (s == mx || !cnt[s]) continue;
uint32_t g = freq[s] - 1;
uint32_t need = total - give - RANS_PROB_SCALE;
if (g > need) g = need;
freq[s] -= (uint16_t)g; give += g;
}
}
}
size_t rans_encode_raw(const uint8_t *in, size_t n, const uint16_t *freq,
uint8_t *out) {
uint32_t cum[256];
uint32_t c = 0;
for (int s = 0; s < 256; s++) { cum[s] = c; c += freq[s]; }
uint32_t x = RANS_L;
/* Encode backwards; emit bytes into a temp tail, then reverse.
* Simpler: write backwards from the end of a scratch area. We
* write into out[0..] backwards via a local reverse pass: emit
* into out in reverse order by filling from the end. Caller
* guarantees out holds n + 64 bytes, so use the tail. */
uint8_t *p = out + 2 * n + 64; /* one past the end of scratch */
/* reserve 4 bytes at the very start of the emitted stream for the
* final state; emit stream bytes before them. Work backwards: */
uint8_t *w = p;
for (size_t i = n; i-- > 0;) {
uint8_t s = in[i];
uint32_t f = freq[s];
/* xmax = (L>>12)*f<<8: keeps post-update state in [L, 2^31) so the
* decoder renormalisation consumes exactly the bytes emitted here. */
uint32_t xmax = ((RANS_L >> RANS_PROB_BITS) * f) << 8;
while (x >= xmax) { *--w = (uint8_t)(x & 0xff); x >>= 8; }
x = (((x / f) << RANS_PROB_BITS) | ((x % f) + cum[s]));
}
/* w..p holds the emitted bytes in order; final state x follows. */
size_t nbytes = (size_t)(p - w);
memmove(out + 4, w, nbytes);
out[0] = (uint8_t)(x & 0xff);
out[1] = (uint8_t)((x >> 8) & 0xff);
out[2] = (uint8_t)((x >> 16) & 0xff);
out[3] = (uint8_t)((x >> 24) & 0xff);
return nbytes + 4;
}
int rans_decode_raw(const uint8_t *in, size_t in_len, const uint16_t *freq,
uint8_t *out, size_t out_len) {
if (in_len < 4) return -1;
uint16_t cum[256];
uint8_t dsym[RANS_PROB_SCALE];
uint32_t c = 0;
for (int s = 0; s < 256; s++) {
cum[s] = (uint16_t)c;
for (uint32_t k = 0; k < freq[s]; k++) dsym[c + k] = (uint8_t)s;
c += freq[s];
}
if (c != RANS_PROB_SCALE) return -1;
uint32_t x = (uint32_t)in[0] | ((uint32_t)in[1] << 8) |
((uint32_t)in[2] << 16) | ((uint32_t)in[3] << 24);
size_t p = 4;
for (size_t i = 0; i < out_len; i++) {
uint32_t slot = x & (RANS_PROB_SCALE - 1);
uint8_t s = dsym[slot];
out[i] = s;
uint32_t f = freq[s];
x = f * (x >> RANS_PROB_BITS) + (slot - cum[s]);
while (x < RANS_L) {
if (p >= in_len) return -1;
x = (x << 8) | in[p++];
}
}
return 0;
}
int rans_encode(const uint8_t *in, size_t n, uint8_t **out, size_t *out_len) {
uint16_t freq[256];
rans_freq(in, n, freq);
uint8_t *buf = malloc(520 + 2 * n + 64);
if (!buf) return -1;
memcpy(buf, "RANS", 4);
buf[4] = (uint8_t)(n & 0xff);
buf[5] = (uint8_t)((n >> 8) & 0xff);
buf[6] = (uint8_t)((n >> 16) & 0xff);
buf[7] = (uint8_t)((n >> 24) & 0xff);
for (int s = 0; s < 256; s++) {
buf[8 + 2 * s] = (uint8_t)(freq[s] & 0xff);
buf[8 + 2 * s + 1] = (uint8_t)((freq[s] >> 8) & 0xff);
}
size_t m = rans_encode_raw(in, n, freq, buf + 520);
*out = buf;
*out_len = 520 + m;
return 0;
}
int rans_decode(const uint8_t *in, size_t n, uint8_t **out, size_t *out_len) {
if (n < 520 || memcmp(in, "RANS", 4) != 0) return -1;
uint32_t orig = (uint32_t)in[4] | ((uint32_t)in[5] << 8) |
((uint32_t)in[6] << 16) | ((uint32_t)in[7] << 24);
uint16_t freq[256];
for (int s = 0; s < 256; s++)
freq[s] = (uint16_t)(in[8 + 2 * s] | (in[8 + 2 * s + 1] << 8));
uint8_t *buf = malloc(orig ? orig : 1);
if (!buf) return -1;
if (rans_decode_raw(in + 520, n - 520, freq, buf, orig) != 0) {
free(buf);
return -1;
}
*out = buf;
*out_len = orig;
return 0;
}
/* ---- general-alphabet layer (uint16_t symbols) ---- */
void rans_freq_n(const uint16_t *in, size_t n, int nsym, uint16_t *freq) {
uint32_t cnt[1024] = {0};
for (size_t i = 0; i < n; i++) cnt[in[i]]++;
uint32_t total = 0;
for (int s = 0; s < nsym; s++) {
uint32_t f = n ? (uint32_t)(((uint64_t)cnt[s] * RANS_PROB_SCALE) / n) : 0;
if (cnt[s] && f == 0) f = 1;
freq[s] = (uint16_t)f;
total += f;
}
int mx = 0;
for (int s = 1; s < nsym; s++) if (freq[s] > freq[mx]) mx = s;
if (total < RANS_PROB_SCALE) freq[mx] += (uint16_t)(RANS_PROB_SCALE - total);
else if (total > RANS_PROB_SCALE) {
uint32_t over = total - RANS_PROB_SCALE;
uint32_t give = freq[mx] - (cnt[mx] ? 1u : 0u);
if (give > over) give = over;
freq[mx] -= (uint16_t)give;
for (int s = 0; s < nsym && total - give > RANS_PROB_SCALE; s++) {
if (s == mx || !cnt[s]) continue;
uint32_t g = freq[s] - 1;
uint32_t need = total - give - RANS_PROB_SCALE;
if (g > need) g = need;
freq[s] -= (uint16_t)g; give += g;
}
}
}
size_t rans_encode_raw_n(const uint16_t *in, size_t n, const uint16_t *freq,
int nsym, uint8_t *out) {
uint32_t cum[1024];
uint32_t c = 0;
for (int s = 0; s < nsym; s++) { cum[s] = c; c += freq[s]; }
uint32_t x = RANS_L;
uint8_t *p = out + 2 * n + 64;
uint8_t *w = p;
for (size_t i = n; i-- > 0;) {
uint16_t s = in[i];
uint32_t f = freq[s];
uint32_t xmax = ((RANS_L >> RANS_PROB_BITS) * f) << 8;
while (x >= xmax) { *--w = (uint8_t)(x & 0xff); x >>= 8; }
x = (((x / f) << RANS_PROB_BITS) | ((x % f) + cum[s]));
}
size_t nbytes = (size_t)(p - w);
memmove(out + 4, w, nbytes);
out[0] = (uint8_t)(x & 0xff);
out[1] = (uint8_t)((x >> 8) & 0xff);
out[2] = (uint8_t)((x >> 16) & 0xff);
out[3] = (uint8_t)((x >> 24) & 0xff);
return nbytes + 4;
}
int rans_decode_raw_n(const uint8_t *in, size_t in_len, const uint16_t *freq,
int nsym, uint16_t *out, size_t out_len) {
if (in_len < 4) return -1;
uint16_t cum[1024];
uint16_t dsym[RANS_PROB_SCALE];
uint32_t c = 0;
for (int s = 0; s < nsym; s++) {
cum[s] = (uint16_t)c;
for (uint32_t k = 0; k < freq[s]; k++) dsym[c + k] = (uint16_t)s;
c += freq[s];
}
if (c != RANS_PROB_SCALE) return -1;
uint32_t x = (uint32_t)in[0] | ((uint32_t)in[1] << 8) |
((uint32_t)in[2] << 16) | ((uint32_t)in[3] << 24);
size_t p = 4;
for (size_t i = 0; i < out_len; i++) {
uint32_t slot = x & (RANS_PROB_SCALE - 1);
uint16_t s = dsym[slot];
out[i] = s;
uint32_t f = freq[s];
x = f * (x >> RANS_PROB_BITS) + (slot - cum[s]);
while (x < RANS_L) {
if (p >= in_len) return -1;
x = (x << 8) | in[p++];
}
}
return 0;
}
-44
View File
@@ -1,44 +0,0 @@
/* rans.h - rANS entropy coder shared by the lzply experiments.
* 12-bit probabilities (scale 4096), 23-bit renormalisation window.
* Two layers:
* - stream layer: rans_freq / rans_encode_raw / rans_decode_raw work
* on a raw byte stream with a caller-supplied freq table (for
* multi-stream coders, e.g. LZ token streams).
* - file layer: rans_encode / rans_decode wrap one stream with a
* header (magic "RANS", u32 orig_len, 256 x u16 freq table).
*/
#ifndef EXP_RANS_H
#define EXP_RANS_H
#include <stddef.h>
#include <stdint.h>
#define RANS_PROB_BITS 12
#define RANS_PROB_SCALE (1u << RANS_PROB_BITS)
#define RANS_L (1u << 23)
/* Count + normalise frequencies of `in` to sum RANS_PROB_SCALE.
* Symbols present get >= 1. */
void rans_freq(const uint8_t *in, size_t n, uint16_t *freq /*[256]*/);
/* Encode `in` with `freq`; `out` must hold 2*n + 64 bytes. Returns
* bytes written. */
size_t rans_encode_raw(const uint8_t *in, size_t n, const uint16_t *freq,
uint8_t *out);
/* Decode `in_len` bytes into `out` (out_len bytes). Returns 0 ok, -1 bad. */
int rans_decode_raw(const uint8_t *in, size_t in_len, const uint16_t *freq,
uint8_t *out, size_t out_len);
/* Whole-file wrap: mallocs *out. Returns 0 ok, -1 bad. */
int rans_encode(const uint8_t *in, size_t n, uint8_t **out, size_t *out_len);
int rans_decode(const uint8_t *in, size_t n, uint8_t **out, size_t *out_len);
#endif
/* General-alphabet layer (uint16_t symbols, nsym <= 1024): for token
* streams such as literal/length (286 symbols) and distance (21). */
void rans_freq_n(const uint16_t *in, size_t n, int nsym, uint16_t *freq);
size_t rans_encode_raw_n(const uint16_t *in, size_t n, const uint16_t *freq,
int nsym, uint8_t *out /* 2*n+64 */);
int rans_decode_raw_n(const uint8_t *in, size_t in_len, const uint16_t *freq,
int nsym, uint16_t *out, size_t out_len);
-46
View File
@@ -1,46 +0,0 @@
/* rans_tool.c - standalone rANS order-0 compressor: `rans_tool c in out`,
* `rans_tool d in out`. Used for the ANS-family measurements. */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "rans.h"
static uint8_t *slurp(const char *path, size_t *n) {
FILE *f = fopen(path, "rb");
if (!f) { perror(path); exit(2); }
fseek(f, 0, SEEK_END);
long sz = ftell(f);
fseek(f, 0, SEEK_SET);
uint8_t *b = malloc(sz ? (size_t)sz : 1);
if (!b) exit(2);
if (sz && fread(b, 1, (size_t)sz, f) != (size_t)sz) exit(2);
fclose(f);
*n = (size_t)sz;
return b;
}
static void spit(const char *path, const uint8_t *b, size_t n) {
FILE *f = fopen(path, "wb");
if (!f) { perror(path); exit(2); }
if (n && fwrite(b, 1, n, f) != n) exit(2);
fclose(f);
}
int main(int argc, char **argv) {
if (argc != 4 || (argv[1][0] != 'c' && argv[1][0] != 'd')) {
fprintf(stderr, "usage: %s c|d in out\n", argv[0]);
return 1;
}
size_t n;
uint8_t *in = slurp(argv[2], &n);
uint8_t *out = NULL;
size_t on = 0;
int rc = argv[1][0] == 'c' ? rans_encode(in, n, &out, &on)
: rans_decode(in, n, &out, &on);
if (rc != 0) {
fprintf(stderr, "%s: %s failed (bad input?)\n", argv[0], argv[1]);
return 3;
}
spit(argv[3], out, on);
return 0;
}
View File
Whitespace-only changes.
-6
View File
@@ -1,6 +0,0 @@
tool,corpus,orig,comp,ratio_pct,enc_s,dec_s,enc_MBs,dec_MBs,status
bzip2,text,8388608,776306,9.25,2.969,1.346,2.8,6.2,OK
bzip2,code,8388608,1053123,12.55,2.754,0.937,3.0,8.9,OK
bzip2,bin,8388608,3373815,40.22,1.866,1.575,4.5,5.3,OK
bzip2,mixed,8388608,1974225,23.53,2.081,0.875,4.0,9.6,OK
bzip2,rand,4194304,4213434,100.46,1.336,0.958,3.1,4.4,OK
1 tool corpus orig comp ratio_pct enc_s dec_s enc_MBs dec_MBs status
2 bzip2 text 8388608 776306 9.25 2.969 1.346 2.8 6.2 OK
3 bzip2 code 8388608 1053123 12.55 2.754 0.937 3.0 8.9 OK
4 bzip2 bin 8388608 3373815 40.22 1.866 1.575 4.5 5.3 OK
5 bzip2 mixed 8388608 1974225 23.53 2.081 0.875 4.0 9.6 OK
6 bzip2 rand 4194304 4213434 100.46 1.336 0.958 3.1 4.4 OK
-6
View File
@@ -1,6 +0,0 @@
tool,corpus,orig,comp,ratio_pct,enc_s,dec_s,enc_MBs,dec_MBs,status
dict-lzip6,text,8388608,299963,3.58,2.541,0.166,3.3,50.4,OK
dict-lzip6,code,8388608,770519,9.19,4.144,0.218,2.0,38.5,OK
dict-lzip6,bin,8388608,2793130,33.30,9.522,0.467,0.9,18.0,OK
dict-lzip6,mixed,8388608,1480819,17.65,5.358,0.317,1.6,26.5,OK
dict-lzip6,rand,4194304,4266698,101.73,2.794,0.475,1.5,8.8,OK
1 tool corpus orig comp ratio_pct enc_s dec_s enc_MBs dec_MBs status
2 dict-lzip6 text 8388608 299963 3.58 2.541 0.166 3.3 50.4 OK
3 dict-lzip6 code 8388608 770519 9.19 4.144 0.218 2.0 38.5 OK
4 dict-lzip6 bin 8388608 2793130 33.30 9.522 0.467 0.9 18.0 OK
5 dict-lzip6 mixed 8388608 1480819 17.65 5.358 0.317 1.6 26.5 OK
6 dict-lzip6 rand 4194304 4266698 101.73 2.794 0.475 1.5 8.8 OK
-6
View File
@@ -1,6 +0,0 @@
tool,corpus,orig,comp,ratio_pct,enc_s,dec_s,enc_MBs,dec_MBs,status
gzip9,text,8388608,1969901,23.48,0.830,0.117,10.1,71.6,OK
gzip9,code,8388608,1376091,16.40,0.980,0.066,8.6,127.7,OK
gzip9,bin,8388608,3702420,44.14,2.700,0.115,3.1,72.6,OK
gzip9,mixed,8388608,2521765,30.06,1.180,0.117,7.1,71.5,OK
gzip9,rand,4194304,4194967,100.02,0.428,0.059,9.8,71.3,OK
1 tool corpus orig comp ratio_pct enc_s dec_s enc_MBs dec_MBs status
2 gzip9 text 8388608 1969901 23.48 0.830 0.117 10.1 71.6 OK
3 gzip9 code 8388608 1376091 16.40 0.980 0.066 8.6 127.7 OK
4 gzip9 bin 8388608 3702420 44.14 2.700 0.115 3.1 72.6 OK
5 gzip9 mixed 8388608 2521765 30.06 1.180 0.117 7.1 71.5 OK
6 gzip9 rand 4194304 4194967 100.02 0.428 0.059 9.8 71.3 OK
-6
View File
@@ -1,6 +0,0 @@
tool,corpus,orig,comp,ratio_pct,enc_s,dec_s,enc_MBs,dec_MBs,status
lzip1,text,8388608,521474,6.22,0.923,0.117,9.1,71.8,OK
lzip1,code,8388608,1268850,15.13,1.127,0.216,7.4,38.8,OK
lzip1,bin,8388608,3173235,37.83,3.144,0.468,2.7,17.9,OK
lzip1,mixed,8388608,1809972,21.58,1.789,0.271,4.7,31.0,OK
lzip1,rand,4194304,4251394,101.36,3.104,0.474,1.4,8.9,OK
1 tool corpus orig comp ratio_pct enc_s dec_s enc_MBs dec_MBs status
2 lzip1 text 8388608 521474 6.22 0.923 0.117 9.1 71.8 OK
3 lzip1 code 8388608 1268850 15.13 1.127 0.216 7.4 38.8 OK
4 lzip1 bin 8388608 3173235 37.83 3.144 0.468 2.7 17.9 OK
5 lzip1 mixed 8388608 1809972 21.58 1.789 0.271 4.7 31.0 OK
6 lzip1 rand 4194304 4251394 101.36 3.104 0.474 1.4 8.9 OK
-6
View File
@@ -1,6 +0,0 @@
tool,corpus,orig,comp,ratio_pct,enc_s,dec_s,enc_MBs,dec_MBs,status
lzip6,text,8388608,298558,3.56,3.655,0.117,2.3,71.4,OK
lzip6,code,8388608,787213,9.38,5.138,0.168,1.6,50.0,OK
lzip6,bin,8388608,2735269,32.61,9.676,0.416,0.9,20.2,OK
lzip6,mixed,8388608,1460156,17.41,5.519,0.267,1.5,31.4,OK
lzip6,rand,4194304,4251435,101.36,3.173,0.531,1.3,7.9,OK
1 tool corpus orig comp ratio_pct enc_s dec_s enc_MBs dec_MBs status
2 lzip6 text 8388608 298558 3.56 3.655 0.117 2.3 71.4 OK
3 lzip6 code 8388608 787213 9.38 5.138 0.168 1.6 50.0 OK
4 lzip6 bin 8388608 2735269 32.61 9.676 0.416 0.9 20.2 OK
5 lzip6 mixed 8388608 1460156 17.41 5.519 0.267 1.5 31.4 OK
6 lzip6 rand 4194304 4251435 101.36 3.173 0.531 1.3 7.9 OK
-6
View File
@@ -1,6 +0,0 @@
tool,corpus,orig,comp,ratio_pct,enc_s,dec_s,enc_MBs,dec_MBs,status
lzip9,text,8388608,288746,3.44,6.658,0.119,1.3,70.3,OK
lzip9,code,8388608,758969,9.05,9.062,0.168,0.9,50.0,OK
lzip9,bin,8388608,2729180,32.53,10.747,0.479,0.8,17.5,OK
lzip9,mixed,8388608,1440405,17.17,8.603,0.272,1.0,30.8,OK
lzip9,rand,4194304,4251435,101.36,3.071,0.467,1.4,9.0,OK
1 tool corpus orig comp ratio_pct enc_s dec_s enc_MBs dec_MBs status
2 lzip9 text 8388608 288746 3.44 6.658 0.119 1.3 70.3 OK
3 lzip9 code 8388608 758969 9.05 9.062 0.168 0.9 50.0 OK
4 lzip9 bin 8388608 2729180 32.53 10.747 0.479 0.8 17.5 OK
5 lzip9 mixed 8388608 1440405 17.17 8.603 0.272 1.0 30.8 OK
6 lzip9 rand 4194304 4251435 101.36 3.071 0.467 1.4 9.0 OK
-6
View File
@@ -1,6 +0,0 @@
tool,corpus,orig,comp,ratio_pct,enc_s,dec_s,enc_MBs,dec_MBs,status
lzrans-lazy,text,8388608,525357,6.26,1.888,0.119,4.4,70.6,OK
lzrans-lazy,code,8388608,1134159,13.52,3.264,0.116,2.6,72.5,OK
lzrans-lazy,bin,8388608,3510054,41.84,9.644,0.320,0.9,26.2,OK
lzrans-lazy,mixed,8388608,1942374,23.15,3.963,0.165,2.1,50.7,OK
lzrans-lazy,rand,4194304,4214292,100.48,9.295,0.115,0.5,36.3,OK
1 tool corpus orig comp ratio_pct enc_s dec_s enc_MBs dec_MBs status
2 lzrans-lazy text 8388608 525357 6.26 1.888 0.119 4.4 70.6 OK
3 lzrans-lazy code 8388608 1134159 13.52 3.264 0.116 2.6 72.5 OK
4 lzrans-lazy bin 8388608 3510054 41.84 9.644 0.320 0.9 26.2 OK
5 lzrans-lazy mixed 8388608 1942374 23.15 3.963 0.165 2.1 50.7 OK
6 lzrans-lazy rand 4194304 4214292 100.48 9.295 0.115 0.5 36.3 OK
-3
View File
@@ -1,3 +0,0 @@
tool,corpus,orig,comp,ratio_pct,enc_s,dec_s,enc_MBs,dec_MBs,status
lzrans-opt,text,8388608,519352,6.19,18.714,0.132,0.4,63.5,OK
lzrans-opt,code,8388608,1094779,13.05,8.628,0.115,1.0,72.9,OK
1 tool corpus orig comp ratio_pct enc_s dec_s enc_MBs dec_MBs status
2 lzrans-opt text 8388608 519352 6.19 18.714 0.132 0.4 63.5 OK
3 lzrans-opt code 8388608 1094779 13.05 8.628 0.115 1.0 72.9 OK
-4
View File
@@ -1,4 +0,0 @@
tool,corpus,orig,comp,ratio_pct,enc_s,dec_s,enc_MBs,dec_MBs,status
ppm,text,8388608,2754814,32.84,1.327,2.176,6.3,3.9,OK
ppm,code,8388608,2585570,30.82,1.324,2.040,6.3,4.1,OK
ppm,mixed,8388608,3286801,39.18,1.732,2.635,4.8,3.2,OK
1 tool corpus orig comp ratio_pct enc_s dec_s enc_MBs dec_MBs status
2 ppm text 8388608 2754814 32.84 1.327 2.176 6.3 3.9 OK
3 ppm code 8388608 2585570 30.82 1.324 2.040 6.3 4.1 OK
4 ppm mixed 8388608 3286801 39.18 1.732 2.635 4.8 3.2 OK
-6
View File
@@ -1,6 +0,0 @@
tool,corpus,orig,comp,ratio_pct,enc_s,dec_s,enc_MBs,dec_MBs,status
rans0,text,8388608,5401895,64.40,0.221,0.170,38.0,49.3,OK
rans0,code,8388608,5672388,67.62,0.277,0.171,30.3,49.1,OK
rans0,bin,8388608,6470778,77.14,0.217,0.179,38.6,46.9,OK
rans0,mixed,8388608,6552704,78.11,0.218,0.174,38.4,48.1,OK
rans0,rand,4194304,4213441,100.46,0.115,0.068,36.4,61.6,OK
1 tool corpus orig comp ratio_pct enc_s dec_s enc_MBs dec_MBs status
2 rans0 text 8388608 5401895 64.40 0.221 0.170 38.0 49.3 OK
3 rans0 code 8388608 5672388 67.62 0.277 0.171 30.3 49.1 OK
4 rans0 bin 8388608 6470778 77.14 0.217 0.179 38.6 46.9 OK
5 rans0 mixed 8388608 6552704 78.11 0.218 0.174 38.4 48.1 OK
6 rans0 rand 4194304 4213441 100.46 0.115 0.068 36.4 61.6 OK
-6
View File
@@ -1,6 +0,0 @@
tool,corpus,orig,comp,ratio_pct,enc_s,dec_s,enc_MBs,dec_MBs,status
xz6,text,8388608,294056,3.51,4.257,0.076,2.0,110.1,OK
xz6,code,8388608,771984,9.20,7.147,0.200,1.2,42.0,OK
xz6,bin,8388608,2733616,32.59,12.330,0.367,0.7,22.8,OK
xz6,mixed,8388608,1450908,17.30,7.553,0.271,1.1,31.0,OK
xz6,rand,4194304,4194584,100.01,3.323,0.085,1.3,49.1,OK
1 tool corpus orig comp ratio_pct enc_s dec_s enc_MBs dec_MBs status
2 xz6 text 8388608 294056 3.51 4.257 0.076 2.0 110.1 OK
3 xz6 code 8388608 771984 9.20 7.147 0.200 1.2 42.0 OK
4 xz6 bin 8388608 2733616 32.59 12.330 0.367 0.7 22.8 OK
5 xz6 mixed 8388608 1450908 17.30 7.553 0.271 1.1 31.0 OK
6 xz6 rand 4194304 4194584 100.01 3.323 0.085 1.3 49.1 OK
-6
View File
@@ -1,6 +0,0 @@
tool,corpus,orig,comp,ratio_pct,enc_s,dec_s,enc_MBs,dec_MBs,status
zstd19,text,8388608,304391,3.63,3.549,0.055,2.4,151.8,OK
zstd19,code,8388608,795239,9.48,11.348,0.071,0.7,117.7,OK
zstd19,bin,8388608,2919792,34.81,14.260,0.169,0.6,49.5,OK
zstd19,mixed,8388608,1535960,18.31,8.021,0.066,1.0,126.9,OK
zstd19,rand,4194304,4194413,100.00,3.020,0.037,1.4,112.0,OK
1 tool corpus orig comp ratio_pct enc_s dec_s enc_MBs dec_MBs status
2 zstd19 text 8388608 304391 3.63 3.549 0.055 2.4 151.8 OK
3 zstd19 code 8388608 795239 9.48 11.348 0.071 0.7 117.7 OK
4 zstd19 bin 8388608 2919792 34.81 14.260 0.169 0.6 49.5 OK
5 zstd19 mixed 8388608 1535960 18.31 8.021 0.066 1.0 126.9 OK
6 zstd19 rand 4194304 4194413 100.00 3.020 0.037 1.4 112.0 OK