Plebeia.SegmentSourceA module encapsulating the concept of a path through the Patricia tree. A path is a sequence of n full segments. The n-1 first segments end in a bud and the nth ends in a leaf. Internal segments are bit of paths encoded in the internal nodes of the Patricia tree while tip segments represent the bits of path encoded close to the leaf.
2 Side
Human readable string representation of a side list, e.g. "LLLRLLRL"
2 Segment
Maximum length of sides which fits with one cell with an index: 215
Maximum length of sides for a segment: 1815
Cuts a path into a head and tail if not empty. Also known as "snoc".
Normal compare does not work. Note: this may call to_sides internally and therefore is not very light operaiton.
Factors a common prefix between two segments.
common_prefix t1 t2 = (prefix, t1', t2') then, t1 = append prefix t1' and t2 = append prefix t2'
Fast build of a segment from a raw encoding data: the length and a string of LR bits postfixed by 0
,7
. No sanity check.
Parse the string representation of a segment, e.g. "LLRLLRL"
Human readable string representation of segments: "LLRLRLL/RRRLL/.."
3 Serialization
3 Data encoding
For encoding to JSON or binary using data-encoding.
Binary encoding:
<1B> <------- len bytes --------> +----+------------------------------+ |len |<- serialized segment sides ->| +----+------------------------------+
* The first byte is the length of the serialized segment sides part (1 .. 255) * The rest is the string of the serialized segment sides, which is the stream of segment bits (Left: 0, Right: 1) postfixed 10n (0 <= n <= 7) to make the stream fit in a string.
Example:
data | binary ---------------------- empty segment | 0180 LRLRLRLRL | 025540 LRLRLRLR | 025580 RRRRRRRRRRRRRRRRRRRR | 03fffff8
2 Segs: append friendly segment list