Commit a3aed82a78f2d18269efbd86f8784e8989e5d4da
Update spec.md
wanderer authored on 3/1/2018, 2:13:26 AMGitHub committed on 3/1/2018, 2:13:26 AM
Parent: 343203ced157299bd2c071287e5c9945a760fe45
Files changed
docs/spec.md | changed |
docs/spec.md | |||
---|---|---|---|
@@ -1,6 +1,6 @@ | |||
1 | 1 … | This documnet provides the structure of the [Dfinity's Radix Tree.](https://ipfs.io/ipns/QmdJiuMWp2FxyaerfLrtdLF6Nr1EWpL7dPAxA9oKSPYYgV/wiki/Radix_tree.html) | |
2 | -The radix tree data structure stores the key-values; the tree is an instances of nodes that contains the value and the key is the path to the node in the tree. | ||
2 … | +The radix tree data structure stores the key-values; the tree is an instances of nodes that contains the value and the key is the path to the node in the tree. All values are encoded with [CBOR](http://cbor.io) | ||
3 | 3 … | ||
4 | 4 … | ## Node | |
5 | 5 … | Each node has a type and contains at most four elements: | |
6 | 6 … | "extension", "left branch", "right branch" and "value". | |
@@ -52,44 +52,4 @@ | |||
52 | 52 … | `0x03, 0x04` | |
53 | 53 … | ||
54 | 54 … | where 3 is the the shared path length and the `0x04` is the shared path encoded | |
55 | 55 … | as a little endian byte array. | |
56 | - | ||
57 | -## Examples | ||
58 | - | ||
59 | -An empty tree has a merkle root which is a hash of sha256(0x00) or `6e340b9cffb37a989ca544e6bb780a2c78901d3f`. | ||
60 | - | ||
61 | - | ||
62 | -A tree with a single node with key 'binary' and value of 'tree' is encoded as | ||
63 | - | ||
64 | -``` | ||
65 | -0x093062696e61727974726565 | ||
66 | - | ||
67 | -0x09 this node has an extention and value | ||
68 | -0x30 the extention has a length of 48 bits or 6 bytes | ||
69 | -0x62696e617279 the key 'binary' | ||
70 | -0x4726565 the value 'tree' | ||
71 | -``` | ||
72 | - | ||
73 | -If we add another key-value with the key "bin" and the value "number" to the tree, the tree will have two nodes | ||
74 | - | ||
75 | -The root node will be | ||
76 | - | ||
77 | -``` | ||
78 | -0x0b1862696eaf39aa98eb0350611f230cbeb2e68dbe95ab5ecc6e756d626572 | ||
79 | - | ||
80 | -0xb this node has an extention, a right branch and a value | ||
81 | -0x18 this the extention has a length of 24 bits | ||
82 | -0x62696e the value extention "bin" | ||
83 | -0xaf39aa98eb0350611f230cbeb2e68dbe95ab5ecc a merkle link to another node | ||
84 | -0x6e756d626572 the value "number" | ||
85 | - | ||
86 | -the link 0xaf39aa98eb0350611f230cbeb2e68dbe95ab5ecc points to the node | ||
87 | - | ||
88 | -0x091730b93c74726565 | ||
89 | - | ||
90 | -0x09 this node has an extention and value | ||
91 | -0x17 this the extention has a length of 23 bits | ||
92 | -0x30b93c the extention 'ary' = 0x617279 that is shift left one bit. 'a' is 0x61 which | ||
93 | -is read 100001100 (little endian) The was first bit is was used to choose the branch (right) | ||
94 | -turns into 0x30 (110000) | ||
95 | -``` |
Built with git-ssb-web