itacart.serialization.data_tree_blob
DataTreeBlob: values on a tree of cells, read and updated in place.
A TreeBlob holds a set of cells and answers where. A DataTreeBlob holds a tree of cells and, at every node of it, the values of a fixed set of variables, so it answers what is there: at a cell and at every one of its ancestors, in one walk down the tree, on the bytes, without decoding the rest. The two formats live side by side. The TreeBlob is the canonical, content-addressed form of a region; this one is the fast, hierarchical form of data about cells, and it has no canonical form to hash.
The tree is lexical, like the ancestry of the index. Its nodes are the cells written into it and every prefix of their spellings. Away from the domain border that is the physical tree. On the border, the surplus children of a cell are spelled under the next column’s prefix, which names no cell, so they hang under that prefix and not under their physical parent; inside a polar cap the same happens at intermediate levels. Such a prefix is a node of the blob, because the walk needs it, and it holds the aggregate of what hangs under it. No function here emits it, and a path through it skips it. The aggregate of a border cell therefore covers its own stem only, a share of the cell that depends on how deep the data goes.
Variables. A blob carries up to 255 fixed-width columns, declared with
DataVariable. A pyramid variable is observed at the leaves and
held at every internal node as an operator over the daughters – their
sum, mean, maximum, minimum or mode – computed exactly and rounded once to
the variable’s type. A level variable is observed wherever the caller
gives it a value, at a parent and at its daughter alike, and is never
aggregated. A mean or a mode is weighted by an integer sum declared before
it, normally the count of the cells where the value was observed, so a
node’s mean is over what was observed rather than over what could have
been.
Absence. Each variable declares what a missing value means: zero, or unknown. An unknown value is a cleared bit in a validity bitmap beside the values, so the type keeps its whole domain. Operators skip the unknown daughters, and a node none of whose daughters is known is unknown itself. Operators run over the daughters the tree holds: a daughter it does not hold is not a zero.
Blocks. The blob declares an observation resolution, the finest of its
data. A leaf above it stands for every cell beneath it: reading inside it
returns its values, with a sum divided evenly over the cells. Such a leaf
must be a cell that does not absorb the border, so that the cells beneath
it are exactly the product of the refinement ratios.
encode_data_tree(..., prune=True) makes blocks out of complete
families of leaves that agree on every variable, and out of nothing else.
Widths. An unsigned sum declared with leaf_max is written at each
level in the narrowest unsigned type its structure can fill, so a count
costs one byte at the leaves and two or four higher up, and an update in
place can never overflow it.
Reading. Every read works on the bytes. The frame of a bytes blob,
which cannot change, is parsed on the first read and kept for the next
ones – the last sixteen blobs read are kept – while a bytearray is
parsed on every call, because it can change between them. A read handed a
compositional index, or several integers, answers for all of them on one
parse.
The wire format is specified on the DataTreeBlob encoding page of the documentation.
Module constants
the |
|
Version written in the high nibble of the second byte. |
|
the writer pruned complete families into blocks. |
|
The fixed-width types, in the order of their codes on the wire. |
Functions
What a DataTreeBlob declares, read from its frame. |
|
Every cell of a DataTreeBlob with its values, every invariant checked. |
|
Encode values on cells as a DataTreeBlob. |
|
The values of a cell, read in place. |
|
A cell's ancestors that the blob holds, with their values, read in place. |
|
The sub-tree of a node, with the path that reaches it, as a new blob. |
|
Write values at one node in place, and refresh the aggregates above it. |
Classes
One column of a DataTreeBlob. |