bbse — Backward Binary Search Encoding
bbse encodes integer values as the path that binary search would take to find them in a known range.
The result is a prefix-free, compact, reversible, and range-aware representation —
ideal for low-footprint use cases like compression, embedded indexing, and color deltas.
✨ Highlights
- 🧠 Path-based encoding using binary search logic
- ✅ Prefix-free, minimal-length representation
- 🪆 Stack-compatible — values can be stored without headers or offsets
- 🧮 Customizable midpoint for biased distributions
- 🚫 No statistical model or table required
- 🧵
no_stdcompatible withalloc
🚀 Quick Example
use ;
let bits = encode; // Path to 128 in [0, 256)
let value = decode;
assert_eq!;
🎯 Stack-based Encoding
Each encoded value is just a binary search path — ideal for use as a stack of values:
use ;
let mut stack = new;
for value in
let decoded = stack.decode_all;
assert_eq!;
🛠 Custom Midpoint (Optional)
use ;
let bits = encode_from; // Use midpoint = 4 instead of center
let value = decode;
assert_eq!;
🎨 Origin: Efficient Color Deltas
This project originated while designing a custom image codec for RGB delta compression. By encoding deltas using binary search paths instead of entropy coding, we achieved:
- Predictable bit lengths
- Simple bitstream merging
- Ultra-lightweight decoding with no tables or models
📦 Installation
MSRV (Minimum Supported Rust Version) This crate requires Rust 1.78.0 or later.
[]
= "2.1.0"
For embedded or no_std use:
[]
= "2.1.0"
= false
⚙️ Features
std(default): Enables printing and full integration with standard I/Ono_std: Disablesstd, usesalloconly — ideal for embedded targets
BBSE is simple, elegant, and inspired by the structure of the data itself — not statistics. No entropy. No overhead. Just binary logic.
📄 License
MIT