Module
pooka/bytes_tree
src/pooka/bytes_tree.pookaKeep the pieces until somebody asks for the whole parcel. Appending makes a branch in constant time. Rendering walks an explicit work list, preserving chunk order without recursive calls down a deep left spine. Partial final bytes are preserved; this tree accepts arbitrary bitstrings.
assert bytes_tree.to_bit_array(bytes_tree.from_bit_array(<<1, 2>>)) == <<1, 2>>
API reference
class BytesTree
An immutable tree. Only the private leaf and branch classes construct its values.
new() -> BytesTree
fn() -> pooka/bytes_tree.BytesTreeStart without any chunks.
from_bit_array(value: BitArray) -> BytesTree
fn(BitArray) -> pooka/bytes_tree.BytesTreeKeep a chunk without copying its contents.
append(tree: BytesTree, value: BitArray) -> BytesTree
fn(pooka/bytes_tree.BytesTree, BitArray) -> pooka/bytes_tree.BytesTreeAttach one chunk in constant time.
assert bytes_tree.to_bit_array(bytes_tree.append(bytes_tree.new(), <<1, 2>>)) == <<1, 2>>
append_tree(left: BytesTree, right: BytesTree) -> BytesTree
Attach another tree without walking either side.
prepend(tree: BytesTree, value: BitArray) -> BytesTree
fn(pooka/bytes_tree.BytesTree, BitArray) -> pooka/bytes_tree.BytesTreePlace one chunk before the earlier tree.
concat(trees: List(BytesTree)) -> BytesTree
fn(List(pooka/bytes_tree.BytesTree)) -> pooka/bytes_tree.BytesTreeJoin trees in input order without rendering their chunks.
from_bit_arrays(values: List(BitArray)) -> BytesTree
fn(List(BitArray)) -> pooka/bytes_tree.BytesTreeKeep each supplied chunk as a leaf.
to_bit_array(tree: BytesTree) -> BitArray
fn(pooka/bytes_tree.BytesTree) -> BitArrayRender once, preserving every chunk's order.
byte_size(tree: BytesTree) -> Int
fn(pooka/bytes_tree.BytesTree) -> IntByte-oriented size rounds a partial final byte up after rendering.
bit_size(tree: BytesTree) -> Int
fn(pooka/bytes_tree.BytesTree) -> IntCount every bit without rendering the tree.
is_empty(tree: BytesTree) -> Bool
fn(pooka/bytes_tree.BytesTree) -> BoolAsk whether rendering would produce an empty value.