git ssb

0+

wanderer🌟 / js-dfinity-radix-tree



Commit 3e5f1310aaf2b3f3e5ce84ef70c9d91a24657bde

Update spec.md

Mahnush Movahedi authored on 12/21/2017, 8:16:30 PM
GitHub committed on 12/21/2017, 8:16:30 PM
Parent: 89398824f10c7485f1839296a5d994e9b852aef9

Files changed

docs/spec.mdchanged
docs/spec.mdView
@@ -1,30 +1,29 @@
1-This is a simple Merkle Binary [Radix Tree](https://ipfs.io/ipns/QmdJiuMWp2FxyaerfLrtdLF6Nr1EWpL7dPAxA9oKSPYYgV/wiki/Radix_tree.html).
1 +This documnet provides the structure of the Dfinities Radix Tree which is type of the Merkle tree.(https://ipfs.io/ipns/QmdJiuMWp2FxyaerfLrtdLF6Nr1EWpL7dPAxA9oKSPYYgV/wiki/Radix_tree.html).
2 +The radix tree data structure consists of nodes.
23
3-
44 ## Node
5-Each node contains at the most four elements
5 +Each node has a type and contains at the most four elements
66 "extension", "left branch", "right branch" and "value".
77
88 ```
9-node : = EXTENSION | LBRANCH | RBRANCH | VALUE
9 +node : = TYPE | EXTENSION | LBRANCH | RBRANCH | VALUE
1010 ```
1111
12-A prefix byte is used a bit field to signify which elements a node contains.
13-The bit field is defined a the following. The first nibble is reserved for
14-merkle proofs.
12 +###Type
13 +Contains a byte that the last 4 bits are used to signify which elements a node contains.
14 +The bit field is defined a the following. The first 4 bits are paded to zero while in storage. These bits are reserved as insicators of type when sending the nodes to other clients which we will describe later.
1515
1616 ```
17-PREFIX := reserved | reserved | reserved | reserved | EXTENSION | LBRANCH | RBRANCH | VALUE
17 +Type := 0 | 0 | 0 | 0 | HasEXTENSION | HasLBRANCH | HasRBRANCH | HasVALUE
1818 ```
1919
20-For example a node that contained a left branch and a value would have a prefix byte
21-of 00000101 or 0x07
20 +For example a node that contained a left branch and a value would have a prefix byte of 00000101 or 0x07
2221
2322 The full encoded node would then look something like. `0x07<20_bytes_for_lbranch><remaing_bytes_for_value>`
2423
2524
26-## Branches
25 +### Branches
2726
2827 The branch elements point to the next node in the tree using a merkle link.
2928 A merkle link is defined by the first 20 bytes of the result SHA2-256 of an encoded node.
3029
@@ -37,13 +36,13 @@
3736 link := SHA2(encoded_node)[0..20]
3837 ```
3938
4039
41-## Extensions
42-Extensions encode shared paths. Extensions are defined as
40 +### Extensions
41 +For optimization, we use the Extension element that encodes shared paths in the tree. Extensions are defined as
4342
4443 ```
45-extension := length | extension
44 +extension := Length | ExtensionValue
4645
4746 ```
4847 Where the length is the number of bits that extension repesents. This varuint32
4948 encoded with leb128. And the extension is bit array padded with 0's to the nearst byte.
@@ -55,14 +54,14 @@
5554
5655 where 3 is the the shared path length and the `0x04` is the shared path encoded
5756 as a little endian byte array.
5857
59-# Examples
58 +## Examples
6059
61-An empty tree is hash a merkle link of sha256(0x00) or `6e340b9cffb37a989ca544e6bb780a2c78901d3f`
60 +An empty tree has a merkle root which is a hash of sha256(0x00) or `6e340b9cffb37a989ca544e6bb780a2c78901d3f`.
6261
6362
64-A tree with a single key 'binary' and value of 'tree' is encoded as
63 +A tree with a single node with key 'binary' and value of 'tree' is encoded as
6564
6665 ```
6766 0x093062696e61727974726565
6867
@@ -71,9 +70,9 @@
7170 0x62696e617279 the key 'binary'
7271 0x4726565 the value 'tree'
7372 ```
7473
75-If an other key "bin" with the value "number" is add the tree will have two nodes
74 +If we add another key-value with the key "bin" and the value "number" to the tree, the tree will have two nodes
7675
7776 The root node will be
7877
7978 ```

Built with git-ssb-web