BoolCodec: draft
Sep 2, 2026Storage of booleans is in most systems grossly inefficient, it isn't uncommon for a program to take a full `u64` towards storing one boolean, if not a UTF-8 string. The inefficiency compounds as one moves from singular booleans to a sequence of booleans.
BoolCodec is a quick attempt to design & implement a Pareto-optimal boolean codec. The initial specification is as follows:
BoolCodec operates on the byte level. The first bit is a flag (1 => ON 0 => OFF).
If ON, succeeding three bits are a n=3 boolean pattern (1 => TRUE 0 => FALSE). The next four bits are a replication coefficient, i.e. how many times a pattern is repeated.
Else, the succeeding 7 bits merely express 7 booleans.
Therefore, a byte may represent [7, 3 * (2^4-1)] booleans. or on avg (statistically flawed) 26 booleans.
Rust implementation is here.