references encoding - SkycoinWikis/CXO GitHub Wiki
HOME » CX » CXO » REFERENCES ENCODING
Reference Encoding
There are Ref
, Refs
and Dynamic
references. Where
Ref
points to single obejctRefs
is like slice of objectsDynamic
is likeinterface{}
, e.g. schema of the reference described by the reference, not tag
Basis of every reference is SHA256 hash of encoded value.
Ref
The Ref
is structure that contains SHA256 hash. Encoded value represents the hash only, and can be decoded to the hash, or encoded from the hash.
Refs
The Refs
represented as Merkle-tree with some degree. E.g. every node of the tree contains 'degree' child nodes. By default the degree is 16 and can be configured. The Refs
itself is SHA256 hash that points to some encoded value (see image below). If the hash is blank (zero bytes only), then the Refs
represents empty slice.
If the Depth
is 0, then the encoded Refs
point directly to elements, otherwise it points to encoded Refs nodes.
The Length
is amount of non-zero elements in subtree. Thus, a node can contains empty (zero) elements that doesn't count. This way, we can delete an element without tree reconstructing. If tree is full, and we need to insert another element, then we need to increase the depth of the tree (actually, depth is height of the tree). The Depth is depth - 1
. Max number of elements that tree can contain is power(Degree, Depth+1)
. If many elements removed, then we can reduce the depth, removing empty (zero) elements
So, encoding:
Refs
- SHA256 hash- encoded Refs
Depth uint32 Degree uint32 Length uint32 Nested []cipher.SHA256
- encoded Refs node
Length uint32 Nested []cipher.SHA256
Dynamic
A Dynamic
contains reference to object and reference to schema of the object. Schema is first. Both are SHA256 hash.
Schema SHA256
Object SHA256