bbse

Crates.iobbse
lib.rsbbse
version2.1.0
created_at2025-05-16 19:54:46.89373+00
updated_at2025-05-23 04:03:58.794283+00
descriptionBackward Binary Search Encoding โ€” minimal and deterministic scheme for sorted domains
homepage
repositoryhttps://github.com/shurankain/bbse
max_upload_size
id1676987
size15,932
Oleksandr Husiev (shurankain)

documentation

README

bbse โ€” Backward Binary Search Encoding

Crates.io

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_std compatible with alloc

๐Ÿš€ Quick Example

use bbse::{encode, decode};

let bits = encode(0, 256, 128); // Path to 128 in [0, 256)
let value = decode(0, 256, &bits);
assert_eq!(value, 128);

๐ŸŽฏ Stack-based Encoding

Each encoded value is just a binary search path โ€” ideal for use as a stack of values:

use bbse::{encode, BBSEStack};

let mut stack = BBSEStack::new();
for value in [0, 1, 2, 3, 4, 5, 6, 7] {
    stack.push(encode(0, 8, value));
}

let decoded = stack.decode_all(0, 8);
assert_eq!(decoded, vec![0, 1, 2, 3, 4, 5, 6, 7]);

๐Ÿ›  Custom Midpoint (Optional)

use bbse::{encode_from, decode};

let bits = encode_from(0, 16, 3, 4);  // Use midpoint = 4 instead of center
let value = decode(0, 16, &bits);
assert_eq!(value, 3);

๐ŸŽจ 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.

[dependencies]
bbse = "2.1.0"

For embedded or no_std use:

[dependencies.bbse]
version = "2.1.0"
default-features = false

โš™๏ธ Features

  • std (default): Enables printing and full integration with standard I/O
  • no_std: Disables std, uses alloc only โ€” 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

Commit count: 26

cargo fmt