Skip to main content

hexane/
lib.rs

1//! Hexane is a columnar compression library implementing the encoding described in the
2//! [Automerge Binary Format](https://automerge.org/automerge-binary-format-spec/).
3//!
4//! Data is stored in [`ColumnData<C>`] where the cursor type `C` selects the encoding
5//! (`RLE<T>`, delta, boolean, or raw). Values are batched into [`Slab`]s — `Arc`-wrapped byte
6//! buffers — held in a [`SpanTree`] B-tree for O(log n) positional seek, insert, and splice.
7//!
8//! # Cursor Types
9//!
10//! | Type            | Item    | Encoding                        |
11//! |-----------------|---------|---------------------------------|
12//! | [`UIntCursor`]  | `u64`   | RLE + unsigned LEB128           |
13//! | [`IntCursor`]   | `i64`   | RLE + signed LEB128             |
14//! | [`StrCursor`]   | `str`   | RLE + length-prefixed UTF-8     |
15//! | [`ByteCursor`]  | `[u8]`  | RLE + length-prefixed bytes     |
16//! | [`BooleanCursor`]| `bool` | Boolean run-length encoding     |
17//! | [`DeltaCursor`] | `i64`   | Delta-encoded integers          |
18//! | [`RawCursor`]   | `[u8]`  | Uncompressed raw bytes          |
19//!
20//! # Quick Example
21//!
22//! ```rust
23//! use hexane::{ColumnData, UIntCursor};
24//!
25//! let mut col: ColumnData<UIntCursor> = ColumnData::new();
26//! col.splice(0, 0, [1u64, 2, 3, 4, 5]);
27//! assert_eq!(col.to_vec(), vec![Some(1), Some(2), Some(3), Some(4), Some(5)]);
28//!
29//! let bytes = col.save();
30//! let col2: ColumnData<UIntCursor> = ColumnData::load(&bytes).unwrap();
31//! assert_eq!(col.to_vec(), col2.to_vec());
32//! ```
33//!
34//! See the [README](https://github.com/automerge/automerge/tree/main/rust/hexane) for
35//! comprehensive usage documentation.
36
37#[doc(hidden)]
38#[macro_export]
39macro_rules! log {
40     ( $( $t:tt )* ) => {
41          {
42            use $crate::__log;
43            __log!( $( $t )* );
44          }
45     }
46 }
47
48#[cfg(all(feature = "wasm", target_family = "wasm"))]
49#[doc(hidden)]
50#[macro_export]
51macro_rules! __log {
52     ( $( $t:tt )* ) => {
53         web_sys::console::log_1(&format!( $( $t )* ).into());
54     }
55 }
56
57#[cfg(not(all(feature = "wasm", target_family = "wasm")))]
58#[doc(hidden)]
59#[macro_export]
60macro_rules! __log {
61     ( $( $t:tt )* ) => {
62         println!( $( $t )* );
63     }
64 }
65
66pub(crate) mod aggregate;
67pub(crate) mod boolean;
68pub(crate) mod columndata;
69pub(crate) mod cursor;
70pub(crate) mod delta;
71pub(crate) mod encoder;
72pub(crate) mod leb128;
73pub(crate) mod pack;
74pub(crate) mod raw;
75pub(crate) mod rle;
76pub(crate) mod slab;
77
78#[cfg(test)]
79pub mod test;
80
81pub use aggregate::{Acc, Agg};
82pub use boolean::BooleanCursor;
83pub use columndata::{
84    ColAccIter, ColGroupItem, ColGroupIter, ColumnData, ColumnDataIter, ColumnDataIterState,
85};
86pub use cursor::{ColumnCursor, CursorIter, HasAcc, HasMinMax, HasPos, Run, RunIter, SpliceDel};
87pub use delta::DeltaCursor;
88pub use encoder::{Encoder, EncoderState};
89pub use leb128::{lebsize, ulebsize};
90pub use pack::{MaybePackable, PackError, Packable};
91pub use raw::{RawCursor, RawReader, ReadRawError};
92pub use rle::{ByteCursor, IntCursor, RleCursor, StrCursor, UIntCursor};
93pub use slab::{tree, Slab, SlabTree, SlabWeight, SlabWriter, SpanTree, SpanWeight, WriteOp};
94
95pub(crate) use std::borrow::Cow;