Module

pooka/bytes_tree

src/pooka/bytes_tree.pooka

Keep 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.

Pooka
assert bytes_tree.to_bit_array(bytes_tree.from_bit_array(<<1, 2>>)) == <<1, 2>>

API reference

class

BytesTree

src/pooka/bytes_tree.pooka:22
class BytesTree

An immutable tree. Only the private leaf and branch classes construct its values.

function

new

src/pooka/bytes_tree.pooka:31
new() -> BytesTree

Start without any chunks.

function

from_bit_array

src/pooka/bytes_tree.pooka:36
from_bit_array(value: BitArray) -> BytesTree
INFERREDfn(BitArray) -> pooka/bytes_tree.BytesTree

Keep a chunk without copying its contents.

function

append

src/pooka/bytes_tree.pooka:45
append(tree: BytesTree, value: BitArray) -> BytesTree

Attach one chunk in constant time.

Pooka
assert bytes_tree.to_bit_array(bytes_tree.append(bytes_tree.new(), <<1, 2>>)) == <<1, 2>>
function

append_tree

src/pooka/bytes_tree.pooka:50
append_tree(left: BytesTree, right: BytesTree) -> BytesTree

Attach another tree without walking either side.

function

prepend

src/pooka/bytes_tree.pooka:55
prepend(tree: BytesTree, value: BitArray) -> BytesTree

Place one chunk before the earlier tree.

function

concat

src/pooka/bytes_tree.pooka:60
concat(trees: List(BytesTree)) -> BytesTree

Join trees in input order without rendering their chunks.

function

from_bit_arrays

src/pooka/bytes_tree.pooka:65
from_bit_arrays(values: List(BitArray)) -> BytesTree
INFERREDfn(List(BitArray)) -> pooka/bytes_tree.BytesTree

Keep each supplied chunk as a leaf.

function

to_bit_array

src/pooka/bytes_tree.pooka:70
to_bit_array(tree: BytesTree) -> BitArray
INFERREDfn(pooka/bytes_tree.BytesTree) -> BitArray

Render once, preserving every chunk's order.

function

byte_size

src/pooka/bytes_tree.pooka:75
byte_size(tree: BytesTree) -> Int
INFERREDfn(pooka/bytes_tree.BytesTree) -> Int

Byte-oriented size rounds a partial final byte up after rendering.

function

bit_size

src/pooka/bytes_tree.pooka:80
bit_size(tree: BytesTree) -> Int
INFERREDfn(pooka/bytes_tree.BytesTree) -> Int

Count every bit without rendering the tree.

function

is_empty

src/pooka/bytes_tree.pooka:87
is_empty(tree: BytesTree) -> Bool
INFERREDfn(pooka/bytes_tree.BytesTree) -> Bool

Ask whether rendering would produce an empty value.