Commit f45337de9e0a6483fad38e4162908b16c457c0b2
added docs
wanderer committed on 8/4/2017, 9:53:25 PMParent: bef8976f2a564cf623b6149280f7efe17f4a2886
Files changed
package.json | changed |
docs/index.md | added |
docs/spec.md | added |
package.json | ||
---|---|---|
@@ -6,15 +6,21 @@ | ||
6 | 6 … | "scripts": { |
7 | 7 … | "coverage": "node ./node_modules/istanbul/lib/cli.js cover ./tests/index.js", |
8 | 8 … | "coveralls": "npm run coverage && coveralls <coverage/lcov.info", |
9 | 9 … | "lint": "standard", |
10 | - "test": "node ./tests/index.js" | |
10 … | + "test": "node ./tests/index.js", | |
11 … | + "build:docs": "documentation build ./index.js --github --sort-order source -f md > ./docs/index.md" | |
11 | 12 … | }, |
12 | 13 … | "author": "mjbecze <mjbecze@gmail.com>", |
13 | 14 … | "license": "MPL-2.0", |
14 | - "keywords": ["merkle", "tree", "ipfs"], | |
15 … | + "keywords": [ | |
16 … | + "merkle", | |
17 … | + "tree", | |
18 … | + "ipfs" | |
19 … | + ], | |
15 | 20 … | "devDependencies": { |
16 | 21 … | "coveralls": "^2.13.1", |
22 … | + "documentation": "^5.1.1", | |
17 | 23 … | "ipfs": "^0.25.0", |
18 | 24 … | "istanbul": "^1.1.0-alpha.1", |
19 | 25 … | "standard": "^10.0.0", |
20 | 26 … | "tape": "^4.6.3" |
docs/index.md | ||
---|---|---|
@@ -1,0 +1,87 @@ | ||
1 … | +<!-- Generated by documentation.js. Update this documentation by updating the source code. --> | |
2 … | + | |
3 … | +### Table of Contents | |
4 … | + | |
5 … | +- [constructor](#constructor) | |
6 … | +- [get](#get) | |
7 … | +- [set](#set) | |
8 … | +- [delete](#delete) | |
9 … | +- [flush](#flush) | |
10 … | +- [ArrayConstructor](#arrayconstructor) | |
11 … | +- [toTypedArray](#totypedarray) | |
12 … | + | |
13 … | +## constructor | |
14 … | + | |
15 … | +[index.js:19-22](https://github.com/wanderer/merkle-radix-tree/blob/bef8976f2a564cf623b6149280f7efe17f4a2886/index.js#L19-L22 "Source code on GitHub") | |
16 … | + | |
17 … | +**Parameters** | |
18 … | + | |
19 … | +- `opts` | |
20 … | + - `opts.root` {object} a merkle root to a radix tree. If none, RadixTree will create an new root. | |
21 … | + - `opts.graph` {object} an instance of [ipld-graph-builder](https://github.com/ipld/js-ipld-graph-builder) alternitvly `opts.dag` can be used | |
22 … | + - `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. | |
23 … | + | |
24 … | +## get | |
25 … | + | |
26 … | +[index.js:111-115](https://github.com/wanderer/merkle-radix-tree/blob/bef8976f2a564cf623b6149280f7efe17f4a2886/index.js#L111-L115 "Source code on GitHub") | |
27 … | + | |
28 … | +gets a value given a key | |
29 … | + | |
30 … | +**Parameters** | |
31 … | + | |
32 … | +- `key` **any** | |
33 … | + | |
34 … | +Returns **[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)** | |
35 … | + | |
36 … | +## set | |
37 … | + | |
38 … | +[index.js:122-165](https://github.com/wanderer/merkle-radix-tree/blob/bef8976f2a564cf623b6149280f7efe17f4a2886/index.js#L122-L165 "Source code on GitHub") | |
39 … | + | |
40 … | +stores a value at a given key | |
41 … | + | |
42 … | +**Parameters** | |
43 … | + | |
44 … | +- `key` **any** | |
45 … | +- `value` | |
46 … | + | |
47 … | +Returns **[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)** | |
48 … | + | |
49 … | +## delete | |
50 … | + | |
51 … | +[index.js:172-223](https://github.com/wanderer/merkle-radix-tree/blob/bef8976f2a564cf623b6149280f7efe17f4a2886/index.js#L172-L223 "Source code on GitHub") | |
52 … | + | |
53 … | +deletes a value at a given key | |
54 … | + | |
55 … | +**Parameters** | |
56 … | + | |
57 … | +- `key` **any** | |
58 … | + | |
59 … | +Returns **[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)** | |
60 … | + | |
61 … | +## flush | |
62 … | + | |
63 … | +[index.js:229-231](https://github.com/wanderer/merkle-radix-tree/blob/bef8976f2a564cf623b6149280f7efe17f4a2886/index.js#L229-L231 "Source code on GitHub") | |
64 … | + | |
65 … | +creates a merkle root for the current tree and stores the data perstantly | |
66 … | + | |
67 … | +Returns **[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)** | |
68 … | + | |
69 … | +## ArrayConstructor | |
70 … | + | |
71 … | +[index.js:28-30](https://github.com/wanderer/merkle-radix-tree/blob/bef8976f2a564cf623b6149280f7efe17f4a2886/index.js#L28-L30 "Source code on GitHub") | |
72 … | + | |
73 … | +returns an Uint1Array constructir which is used to repersent keys | |
74 … | + | |
75 … | +Returns **[object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** | |
76 … | + | |
77 … | +## toTypedArray | |
78 … | + | |
79 … | +[index.js:37-39](https://github.com/wanderer/merkle-radix-tree/blob/bef8976f2a564cf623b6149280f7efe17f4a2886/index.js#L37-L39 "Source code on GitHub") | |
80 … | + | |
81 … | +converts a TypedArray or Buffer to an Uint1Array | |
82 … | + | |
83 … | +**Parameters** | |
84 … | + | |
85 … | +- `array` **[TypedArray](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray)** the array to convert | |
86 … | + | |
87 … | +Returns **[TypedArray](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray)** |
docs/spec.md | ||
---|---|---|
@@ -1,0 +1,55 @@ | ||
1 … | +This is a simple Binary [Radix Tree](https://ipfs.io/ipns/QmdJiuMWp2FxyaerfLrtdLF6Nr1EWpL7dPAxA9oKSPYYgV/wiki/Radix_tree.html). | |
2 … | +The default encodeing used is [cbor](http://cbor.io/) and the default hashing | |
3 … | +algorithim used is sha2-256. | |
4 … | + | |
5 … | + | |
6 … | +## Node | |
7 … | +Each node is an variable length array containing at the most four elements | |
8 … | +"left branch", "right branch" "extension", "value" | |
9 … | + | |
10 … | +``` | |
11 … | +node : = [LBRANCH, RBRANCH, EXTENSION, VALUE] | |
12 … | +``` | |
13 … | + | |
14 … | +If no value exists at a given node the array is truncated to | |
15 … | + | |
16 … | +``` | |
17 … | +node : = [LBRANCH, RBRANCH, EXTENSION] | |
18 … | +``` | |
19 … | + | |
20 … | +If no value and no extension exists at a given node the array is truncated to | |
21 … | + | |
22 … | +``` | |
23 … | +node : = [LBRANCH, RBRANCH] | |
24 … | +``` | |
25 … | + | |
26 … | +All empty values in the array are encoded as "undefined" | |
27 … | + | |
28 … | +## Branches | |
29 … | +Branch are merkle link defined in the [IPLD format](https://github.com/ipld/specs/tree/master/ipld#what-is-a-merkle-link) | |
30 … | +Each link points to the next node in the tree. | |
31 … | +``` | |
32 … | +branch : = {'/': <merkle link>} | |
33 … | +``` | |
34 … | +Where the link is a [CID](https://github.com/ipld/cid) is encoded as a byte string. | |
35 … | +Using CIDs allow for the flexablity to update the hashing algorithim and encoding | |
36 … | +at a later date while being backwards compatiable. | |
37 … | + | |
38 … | +## Extensions | |
39 … | +Extensions encode shared paths. Extensions are defined as | |
40 … | +``` | |
41 … | +extension := [length, extension] | |
42 … | + | |
43 … | +``` | |
44 … | +Where the length is an interger and the extension is a byte string padded with | |
45 … | +0's | |
46 … | + | |
47 … | +For example if the binary keys [0, 0, 1, 1] and | |
48 … | +[0, 0, 1, 0] have a shared path of [0, 0]. If they where the only two values in | |
49 … | +the tree the root node would have an extension of [0, 0] | |
50 … | + | |
51 … | +``` | |
52 … | +root := [undefined, <link>, [2, 0x00]] | |
53 … | +``` | |
54 … | + | |
55 … | + |
Built with git-ssb-web