git ssb

0+

wanderer🌟 / js-dfinity-radix-tree



Commit e2cd325fdcc6c86a830407f0c4c8638f3a5ad25a

fix typos

Norton Wang committed on 3/3/2018, 8:59:20 PM
Parent: 3228beb1ebc4a9921b555fd514ede84f91ce5bf9

Files changed

README.mdchanged
docs/index.mdchanged
docs/spec.mdchanged
index.jschanged
.gitignoreadded
README.mdView
@@ -1,17 +1,17 @@
11 [![NPM Package](https://img.shields.io/npm/v/dfinity-radix-tree.svg?style=flat-square)](https://www.npmjs.org/package/dfinity-radix-tree)
22 [![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)
44
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)
66
77 # Synopsis
88
99 :evergreen_tree: This implements a binary merkle radix tree. The point of using a binary radix
1010 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
1414 top of [ipld-graph-builder](https://github.com/ipld/js-ipld-graph-builder)
1515 and the resulting state and proofs are generated using it.
1616
1717 ## Install
@@ -51,20 +51,20 @@
5151 ```
5252 ## API
5353 ['./docs/'](./docs/index.md)
5454
55-## Spefication
55+## Specification
5656 ['./docs/spec.md'](./docs/spec.md)
5757
5858 ## Benchmarks
5959 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.
6161
6262 ['./benchmarks/benchmarks.md'](./benchmark/results.md)
6363
6464 ## License
6565
66-[**(C) 2017 DFINITY STIFTUNG**](http://dfinity.network)
66+[**(C) 2018 DFINITY STIFTUNG**](http://dfinity.network)
6767
6868 All code and designs are open sourced under GPL V3.
6969
7070 ![image](https://user-images.githubusercontent.com/6457089/32753794-10f4cbc2-c883-11e7-8dcf-ff8088b38f9f.png)
docs/index.mdView
@@ -13,21 +13,21 @@
1313 - [getMerkleLink](#getmerklelink)
1414
1515 ## constructor
1616
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")
1818
1919 **Parameters**
2020
2121 - `opts`
2222 - `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
2525 - `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.
2626
2727 ## get
2828
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")
3030
3131 gets a value given a key
3232
3333 **Parameters**
@@ -37,9 +37,9 @@
3737 Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)**
3838
3939 ## set
4040
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")
4242
4343 stores a value at a given key
4444
4545 **Parameters**
@@ -50,9 +50,9 @@
5050 Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)**
5151
5252 ## delete
5353
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")
5555
5656 deletes a value at a given key
5757
5858 **Parameters**
@@ -62,39 +62,39 @@
6262 Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)**
6363
6464 ## done
6565
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")
6767
6868 returns a promise that resolve when the tree is done with all of its writes
6969
7070 Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)**
7171
7272 ## flush
7373
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")
7575
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
7777
7878 Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)**
7979
8080 ## emptyTreeState
8181
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")
8383
8484 returns the state of an empty tree
8585
8686 ## ArrayConstructor
8787
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")
8989
90-returns an Uint1Array constructir which is used to repersent keys
90+returns an Uint1Array constructor which is used to represent keys
9191
9292 Returns **[object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)**
9393
9494 ## getMerkleLink
9595
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")
9797
9898 returns a merkle link for some given data
9999
100100 **Parameters**
docs/spec.mdView
@@ -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)
33
44 ## 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:
66 "extension", "left branch", "right branch" and "value".
77
88 ```
99 node : = TYPE | EXTENSION | LBRANCH | RBRANCH | VALUE
1010 ```
1111
1212 ### 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
1414
1515 ```
1616 Type := 0 | 0 | 0 | 0 | HasEXTENSION | HasLBRANCH | HasRBRANCH | HasVALUE
1717 ```
1818
1919 For example a node that contained a left branch and a value would have a prefix byte of 00000101 or 0x07
2020
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>`
2222
2323
2424 ### Branches
2525
@@ -42,10 +42,10 @@
4242 ```
4343 extension := Length | ExtensionValue
4444
4545 ```
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.
4848
4949 For example if the binary keys [0, 0, 1, 1] and
5050 [0, 0, 1, 0] have a shared path of [0, 0, 1]. The extension node would therefor be
5151
index.jsView
@@ -9,10 +9,10 @@
99 module.exports = class RadixTree {
1010 /**
1111 * @param opts
1212 * @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
1515 * @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.
1616 */
1717 constructor (opts) {
1818 this.root = opts.root || {
@@ -47,9 +47,9 @@
4747 let subKey = key.subarray(index)
4848
4949 const {extensionIndex, extensionLen, extension} = findMatchBits(subKey, root)
5050 index += extensionIndex
51- // check if we compelete travered the extension
51+ // check if we complete traversed the extension
5252 if (extensionIndex !== extensionLen) {
5353 return {index, root, extension, extensionIndex}
5454 }
5555 }
@@ -57,9 +57,9 @@
5757 let keySegment = key[index]
5858 if (keySegment !== undefined) {
5959 const branch = treeNode.getBranch(root)
6060 await this.graph.get(branch, keySegment, true)
61- // preseves the '/'
61+ // preserves the '/'
6262 const nextRoot = branch[keySegment]
6363 if (!nextRoot) {
6464 return {root, index}
6565 } else {
@@ -212,9 +212,9 @@
212212 return this._setting
213213 }
214214
215215 /**
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
217217 * @returns {Promise}
218218 */
219219 async flush () {
220220 await this.done()
@@ -249,9 +249,9 @@
249249 return [null, null, null]
250250 }
251251
252252 /**
253- * returns an Uint1Array constructir which is used to repersent keys
253+ * returns an Uint1Array constructor which is used to represent keys
254254 * @returns {object}
255255 */
256256 static get ArrayConstructor () {
257257 return Uint1Array
.gitignoreView
@@ -1,0 +1,2 @@
1+node_modules
2+testdb

Built with git-ssb-web