Larch B-tree forests are stored on the disk as follows:
The following values are stored in the metadata file:
Leaf nodes are encoded as follows:
Index nodes are encoded as follows:
All integers are in big-endian order.
All root nodes are index nodes, so decoding can start knowing that the first node is an index node.
Each node is stored in a file under the nodes subdirectory, using multiple levels of directories to avoid having too many files in the same directory. The basename of the file is the node identifier in hexadecimal.
The directory levels are user adjustable, see the IdPath class for details.
Each node has a reference count. When the count drops to zero, the node file gets removed. Reference counts are stored in files under the refcounts subdirectory. Each file there contains up to 32768 reference counts, as a 16-bit unsigned big-endian integer. Thus, the reference count for node i is file named refcount-N where N is i modulo 32768.
A refcount file that is full of zeroes is removed. When looking up refcounts, if the file does not exist, the count is assumed to be zero. This avoids having to store refcounts for deleted nodes indefinitely.