Commit e2cd325fdcc6c86a830407f0c4c8638f3a5ad25a
fix typos
Norton Wang committed on 3/3/2018, 8:59:20 PMParent: 3228beb1ebc4a9921b555fd514ede84f91ce5bf9
Files changed
README.md | changed |
docs/index.md | changed |
docs/spec.md | changed |
index.js | changed |
.gitignore | added |
README.md | ||
---|---|---|
@@ -1,17 +1,17 @@ | ||
1 | 1 | [![NPM Package](https://img.shields.io/npm/v/dfinity-radix-tree.svg?style=flat-square)](https://www.npmjs.org/package/dfinity-radix-tree) |
2 | 2 | [![Build Status](https://img.shields.io/travis/dfinity/js-dfinity-radix-tree.svg?branch=master&style=flat-square)](https://travis-ci.org/dfinity/js-dfinity-radix-tree) |
3 | -[![Coverage Status](https://img.shields.io/coveralls/dfinity/js-dfinity-radix-tree.svg?style=flat-square)](https://coveralls.io/dfinity/js-dfinity-radix-tree) | |
3 | +[![Coverage Status](https://img.shields.io/coveralls/dfinity/js-dfinity-radix-tree.svg?style=flat-square)](https://coveralls.io/dfinity/js-dfinity-radix-tree) | |
4 | 4 | |
5 | -[![js-standard-style](https://cdn.rawgit.com/feross/standard/master/badge.svg)](https://github.com/feross/standard) | |
5 | +[![js-standard-style](https://cdn.rawgit.com/feross/standard/master/badge.svg)](https://github.com/feross/standard) | |
6 | 6 | |
7 | 7 | # Synopsis |
8 | 8 | |
9 | 9 | :evergreen_tree: This implements a binary merkle radix tree. The point of using a binary radix |
10 | 10 | tree is that it generates smaller proof size then trees with larger radixes. |
11 | -This tree is well suited for storing large dictonaries of fairly random keys. | |
12 | -And is optimized for storing keys of the same length. If the keys are not | |
13 | -random better performance can be achived by hashing them first. It builds on | |
11 | +This tree is well suited for storing large dictionaries of fairly random keys. | |
12 | +And is optimized for storing keys of the same length. If the keys are not | |
13 | +random better performance can be archived by hashing them first. It builds on | |
14 | 14 | top of [ipld-graph-builder](https://github.com/ipld/js-ipld-graph-builder) |
15 | 15 | and the resulting state and proofs are generated using it. |
16 | 16 | |
17 | 17 | ## Install |
@@ -51,20 +51,20 @@ | ||
51 | 51 | ``` |
52 | 52 | ## API |
53 | 53 | ['./docs/'](./docs/index.md) |
54 | 54 | |
55 | -## Spefication | |
55 | +## Specification | |
56 | 56 | ['./docs/spec.md'](./docs/spec.md) |
57 | 57 | |
58 | 58 | ## Benchmarks |
59 | 59 | The result of the benchmarks show that the binary radix tree produces proofs on |
60 | -average %67 small then the Ethereum Trie with 100000 keys stored. | |
60 | +average 67% small then the Ethereum Trie with 100000 keys stored. | |
61 | 61 | |
62 | 62 | ['./benchmarks/benchmarks.md'](./benchmark/results.md) |
63 | 63 | |
64 | 64 | ## License |
65 | 65 | |
66 | -[**(C) 2017 DFINITY STIFTUNG**](http://dfinity.network) | |
66 | +[**(C) 2018 DFINITY STIFTUNG**](http://dfinity.network) | |
67 | 67 | |
68 | 68 | All code and designs are open sourced under GPL V3. |
69 | 69 | |
70 | 70 | ![image](https://user-images.githubusercontent.com/6457089/32753794-10f4cbc2-c883-11e7-8dcf-ff8088b38f9f.png) |
docs/index.md | ||
---|---|---|
@@ -13,21 +13,21 @@ | ||
13 | 13 | - [getMerkleLink](#getmerklelink) |
14 | 14 | |
15 | 15 | ## constructor |
16 | 16 | |
17 | -[index.js:17-25](https://github.com/dfinity/js-dfinity-radix-tree/blob/d8e138d6c098bb9fe80d40c19b9987c94516c5d0/index.js#L17-L25 "Source code on GitHub") | |
17 | +[index.js:17-25](https://github.com/dfinity/js-dfinity-radix-tree/blob/3228beb1ebc4a9921b555fd514ede84f91ce5bf9/index.js#L17-L25 "Source code on GitHub") | |
18 | 18 | |
19 | 19 | **Parameters** |
20 | 20 | |
21 | 21 | - `opts` |
22 | 22 | - `opts.root` {object} a merkle root to a radix tree. If none, RadixTree will create an new root. |
23 | - - `opts.db` {object} a level db instance alternitly `opts.graph` can be used | |
24 | - - `opts.graph` {object} an instance of [ipld-graph-builder](https://github.com/ipld/js-ipld-graph-builder) alternitvly `opts.dag` can be used | |
23 | + - `opts.db` {object} a level db instance; alternatively, `opts.graph` can be used | |
24 | + - `opts.graph` {object} an instance of [ipld-graph-builder](https://github.com/ipld/js-ipld-graph-builder); alternatively, `opts.dag` can be used | |
25 | 25 | - `opts.dag` {object} an instance if [ipfs.dag](https://github.com/ipfs/js-ipfs#dag). If there is no `opts.graph` this will be used to create a new graph instance. |
26 | 26 | |
27 | 27 | ## get |
28 | 28 | |
29 | -[index.js:32-36](https://github.com/dfinity/js-dfinity-radix-tree/blob/d8e138d6c098bb9fe80d40c19b9987c94516c5d0/index.js#L32-L36 "Source code on GitHub") | |
29 | +[index.js:32-36](https://github.com/dfinity/js-dfinity-radix-tree/blob/3228beb1ebc4a9921b555fd514ede84f91ce5bf9/index.js#L32-L36 "Source code on GitHub") | |
30 | 30 | |
31 | 31 | gets a value given a key |
32 | 32 | |
33 | 33 | **Parameters** |
@@ -37,9 +37,9 @@ | ||
37 | 37 | Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)** |
38 | 38 | |
39 | 39 | ## set |
40 | 40 | |
41 | -[index.js:86-89](https://github.com/dfinity/js-dfinity-radix-tree/blob/d8e138d6c098bb9fe80d40c19b9987c94516c5d0/index.js#L86-L89 "Source code on GitHub") | |
41 | +[index.js:87-90](https://github.com/dfinity/js-dfinity-radix-tree/blob/3228beb1ebc4a9921b555fd514ede84f91ce5bf9/index.js#L87-L90 "Source code on GitHub") | |
42 | 42 | |
43 | 43 | stores a value at a given key |
44 | 44 | |
45 | 45 | **Parameters** |
@@ -50,9 +50,9 @@ | ||
50 | 50 | Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)** |
51 | 51 | |
52 | 52 | ## delete |
53 | 53 | |
54 | -[index.js:134-137](https://github.com/dfinity/js-dfinity-radix-tree/blob/d8e138d6c098bb9fe80d40c19b9987c94516c5d0/index.js#L134-L137 "Source code on GitHub") | |
54 | +[index.js:135-138](https://github.com/dfinity/js-dfinity-radix-tree/blob/3228beb1ebc4a9921b555fd514ede84f91ce5bf9/index.js#L135-L138 "Source code on GitHub") | |
55 | 55 | |
56 | 56 | deletes a value at a given key |
57 | 57 | |
58 | 58 | **Parameters** |
@@ -62,39 +62,39 @@ | ||
62 | 62 | Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)** |
63 | 63 | |
64 | 64 | ## done |
65 | 65 | |
66 | -[index.js:196-202](https://github.com/dfinity/js-dfinity-radix-tree/blob/d8e138d6c098bb9fe80d40c19b9987c94516c5d0/index.js#L196-L202 "Source code on GitHub") | |
66 | +[index.js:197-203](https://github.com/dfinity/js-dfinity-radix-tree/blob/3228beb1ebc4a9921b555fd514ede84f91ce5bf9/index.js#L197-L203 "Source code on GitHub") | |
67 | 67 | |
68 | 68 | returns a promise that resolve when the tree is done with all of its writes |
69 | 69 | |
70 | 70 | Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)** |
71 | 71 | |
72 | 72 | ## flush |
73 | 73 | |
74 | -[index.js:218-221](https://github.com/dfinity/js-dfinity-radix-tree/blob/d8e138d6c098bb9fe80d40c19b9987c94516c5d0/index.js#L218-L221 "Source code on GitHub") | |
74 | +[index.js:219-222](https://github.com/dfinity/js-dfinity-radix-tree/blob/3228beb1ebc4a9921b555fd514ede84f91ce5bf9/index.js#L219-L222 "Source code on GitHub") | |
75 | 75 | |
76 | -creates a merkle root for the current tree and stores the data perstantly | |
76 | +creates a merkle root for the current tree and stores the data persistently | |
77 | 77 | |
78 | 78 | Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)** |
79 | 79 | |
80 | 80 | ## emptyTreeState |
81 | 81 | |
82 | -[index.js:247-249](https://github.com/dfinity/js-dfinity-radix-tree/blob/d8e138d6c098bb9fe80d40c19b9987c94516c5d0/index.js#L247-L249 "Source code on GitHub") | |
82 | +[index.js:248-250](https://github.com/dfinity/js-dfinity-radix-tree/blob/3228beb1ebc4a9921b555fd514ede84f91ce5bf9/index.js#L248-L250 "Source code on GitHub") | |
83 | 83 | |
84 | 84 | returns the state of an empty tree |
85 | 85 | |
86 | 86 | ## ArrayConstructor |
87 | 87 | |
88 | -[index.js:255-257](https://github.com/dfinity/js-dfinity-radix-tree/blob/d8e138d6c098bb9fe80d40c19b9987c94516c5d0/index.js#L255-L257 "Source code on GitHub") | |
88 | +[index.js:256-258](https://github.com/dfinity/js-dfinity-radix-tree/blob/3228beb1ebc4a9921b555fd514ede84f91ce5bf9/index.js#L256-L258 "Source code on GitHub") | |
89 | 89 | |
90 | -returns an Uint1Array constructir which is used to repersent keys | |
90 | +returns an Uint1Array constructor which is used to represent keys | |
91 | 91 | |
92 | 92 | Returns **[object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** |
93 | 93 | |
94 | 94 | ## getMerkleLink |
95 | 95 | |
96 | -[index.js:264-266](https://github.com/dfinity/js-dfinity-radix-tree/blob/d8e138d6c098bb9fe80d40c19b9987c94516c5d0/index.js#L264-L266 "Source code on GitHub") | |
96 | +[index.js:265-267](https://github.com/dfinity/js-dfinity-radix-tree/blob/3228beb1ebc4a9921b555fd514ede84f91ce5bf9/index.js#L265-L267 "Source code on GitHub") | |
97 | 97 | |
98 | 98 | returns a merkle link for some given data |
99 | 99 | |
100 | 100 | **Parameters** |
docs/spec.md | ||
---|---|---|
@@ -1,25 +1,25 @@ | ||
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. All values are encoded with [CBOR](http://cbor.io) | |
1 | +This document provides the structure of the [Dfinity 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 instance 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 | -Each node has a type and contains at most four elements: | |
5 | +Each node has a type and contains at most four elements: | |
6 | 6 | "extension", "left branch", "right branch" and "value". |
7 | 7 | |
8 | 8 | ``` |
9 | 9 | node : = TYPE | EXTENSION | LBRANCH | RBRANCH | VALUE |
10 | 10 | ``` |
11 | 11 | |
12 | 12 | ### Type |
13 | -The type field contains a byte. The first 4 bits are paded to zero while the Node is stored in the tree. These bits are reserved as insicators of type when sending the nodes to other clients which we will describe later. The last 4 bits are used to signify which elements a node contains. The bit field is defined a the following | |
13 | +The type field contains a byte. The first 4 bits are padded to zero while the Node is stored in the tree. These bits are reserved as indicators of type when sending the nodes to other clients which we will describe later. The last 4 bits are used to signify which elements a node contains. The bit field is defined a the following | |
14 | 14 | |
15 | 15 | ``` |
16 | 16 | Type := 0 | 0 | 0 | 0 | HasEXTENSION | HasLBRANCH | HasRBRANCH | HasVALUE |
17 | 17 | ``` |
18 | 18 | |
19 | 19 | For example a node that contained a left branch and a value would have a prefix byte of 00000101 or 0x07 |
20 | 20 | |
21 | -The full encoded node would then look something like. `0x07<20_bytes_for_lbranch><remaing_bytes_for_value>` | |
21 | +The full encoded node would then look something like. `0x07<20_bytes_for_lbranch><remaing_bytes_for_value>` | |
22 | 22 | |
23 | 23 | |
24 | 24 | ### Branches |
25 | 25 | |
@@ -42,10 +42,10 @@ | ||
42 | 42 | ``` |
43 | 43 | extension := Length | ExtensionValue |
44 | 44 | |
45 | 45 | ``` |
46 | -Where the length is the number of bits that extension repesents. This varuint32 | |
47 | -encoded with leb128. And the extension is bit array padded with 0's to the nearst byte. | |
46 | +Where the length is the number of bits that extension represents. This varuint32 | |
47 | +encoded with leb128. And the extension is bit array padded with 0's to the nearest byte. | |
48 | 48 | |
49 | 49 | For example if the binary keys [0, 0, 1, 1] and |
50 | 50 | [0, 0, 1, 0] have a shared path of [0, 0, 1]. The extension node would therefor be |
51 | 51 |
index.js | ||
---|---|---|
@@ -9,10 +9,10 @@ | ||
9 | 9 | module.exports = class RadixTree { |
10 | 10 | /** |
11 | 11 | * @param opts |
12 | 12 | * @param opts.root {object} a merkle root to a radix tree. If none, RadixTree will create an new root. |
13 | - * @param opts.db {object} a level db instance alternitly `opts.graph` can be used | |
14 | - * @param opts.graph {object} an instance of [ipld-graph-builder](https://github.com/ipld/js-ipld-graph-builder) alternitvly `opts.dag` can be used | |
13 | + * @param opts.db {object} a level db instance; alternatively, `opts.graph` can be used | |
14 | + * @param opts.graph {object} an instance of [ipld-graph-builder](https://github.com/ipld/js-ipld-graph-builder); alternatively, `opts.dag` can be used | |
15 | 15 | * @param opts.dag {object} an instance if [ipfs.dag](https://github.com/ipfs/js-ipfs#dag). If there is no `opts.graph` this will be used to create a new graph instance. |
16 | 16 | */ |
17 | 17 | constructor (opts) { |
18 | 18 | this.root = opts.root || { |
@@ -47,9 +47,9 @@ | ||
47 | 47 | let subKey = key.subarray(index) |
48 | 48 | |
49 | 49 | const {extensionIndex, extensionLen, extension} = findMatchBits(subKey, root) |
50 | 50 | index += extensionIndex |
51 | - // check if we compelete travered the extension | |
51 | + // check if we complete traversed the extension | |
52 | 52 | if (extensionIndex !== extensionLen) { |
53 | 53 | return {index, root, extension, extensionIndex} |
54 | 54 | } |
55 | 55 | } |
@@ -57,9 +57,9 @@ | ||
57 | 57 | let keySegment = key[index] |
58 | 58 | if (keySegment !== undefined) { |
59 | 59 | const branch = treeNode.getBranch(root) |
60 | 60 | await this.graph.get(branch, keySegment, true) |
61 | - // preseves the '/' | |
61 | + // preserves the '/' | |
62 | 62 | const nextRoot = branch[keySegment] |
63 | 63 | if (!nextRoot) { |
64 | 64 | return {root, index} |
65 | 65 | } else { |
@@ -212,9 +212,9 @@ | ||
212 | 212 | return this._setting |
213 | 213 | } |
214 | 214 | |
215 | 215 | /** |
216 | - * creates a merkle root for the current tree and stores the data perstantly | |
216 | + * creates a merkle root for the current tree and stores the data persistently | |
217 | 217 | * @returns {Promise} |
218 | 218 | */ |
219 | 219 | async flush () { |
220 | 220 | await this.done() |
@@ -249,9 +249,9 @@ | ||
249 | 249 | return [null, null, null] |
250 | 250 | } |
251 | 251 | |
252 | 252 | /** |
253 | - * returns an Uint1Array constructir which is used to repersent keys | |
253 | + * returns an Uint1Array constructor which is used to represent keys | |
254 | 254 | * @returns {object} |
255 | 255 | */ |
256 | 256 | static get ArrayConstructor () { |
257 | 257 | return Uint1Array |
Built with git-ssb-web