git ssb

0+

wanderer🌟 / js-dfinity-radix-tree



Commit 6fd6059129f2f7a3affd4fdc4f14a1a513f78811

remove node value

Signed-off-by: wanderer <mjbecze@gmail.com>
wanderer committed on 12/2/2017, 6:32:33 AM
Parent: 74c27efe6161579d1e5e9e771cfd23eae53b9124

Files changed

index.jschanged
tests/index.jschanged
index.jsView
@@ -30,9 +30,11 @@
3030 * @param {*} key
3131 * @return {Promise} resolve to the new instance of RadixTree
3232 */
3333 async getSubTree (key, decode) {
34- const {root} = await this.get(key, decode)
34 + key = this.formatKey(key)
35 + await this.done()
36 + const {root} = await this._get(key, decode)
3537 return new RadixTree({dag: this.dag, root: root, appendKeyToRoot: true})
3638 }
3739
3840 /**
@@ -44,9 +46,10 @@
4446 */
4547 async get (key, decode) {
4648 key = this.formatKey(key)
4749 await this.done()
48- return this._get(key)
50 + const result = await this._get(key)
51 + return result.value
4952 }
5053
5154 async _get (key) {
5255 let index = 0
tests/index.jsView
@@ -14,24 +14,24 @@
1414 })
1515
1616 tree.set('test', Buffer.from('cat'))
1717 let val = await tree.get('test')
18- t.equals(val.value.toString(), 'cat')
18 + t.equals(val.toString(), 'cat')
1919 tree.set('te', Buffer.from('blop'))
2020 val = await tree.get('test')
21- t.equals(val.value.toString(), 'cat')
21 + t.equals(val.toString(), 'cat')
2222
2323 val = await tree.get('te')
24- t.equals(val.value.toString(), 'blop')
24 + t.equals(val.toString(), 'blop')
2525
2626 tree.set('rad', Buffer.from('cat2'))
2727
2828 val = await tree.get('rad')
29- t.equals(val.value.toString(), 'cat2')
29 + t.equals(val.toString(), 'cat2')
3030
3131 tree.set('test', Buffer.from('cat111'))
3232 val = await tree.get('test')
33- t.equals(val.value.toString(), 'cat111')
33 + t.equals(val.toString(), 'cat111')
3434
3535 const stateRoot = await tree.flush()
3636
3737 // try reteriving node from ipfs
@@ -40,15 +40,15 @@
4040 root: stateRoot
4141 })
4242
4343 val = await tree.get('te')
44- t.equals(val.value.toString(), 'blop')
44 + t.equals(val.toString(), 'blop')
4545
4646 val = await tree.get('rad')
47- t.equals(val.value.toString(), 'cat2')
47 + t.equals(val.toString(), 'cat2')
4848
4949 val = await tree.get('test')
50- t.equals(val.value.toString(), 'cat111')
50 + t.equals(val.toString(), 'cat111')
5151 // console.log(JSON.stringify(tree.root, null, 2))
5252 t.end()
5353 })
5454
@@ -67,15 +67,15 @@
6767 tree.set(key2, Buffer.from('cat'))
6868 tree.set(key3, Buffer.from('cat3'))
6969
7070 let val = await tree.get(key0)
71- t.equals(val.value.toString(), 'cat')
71 + t.equals(val.toString(), 'cat')
7272 val = await tree.get(key1)
73- t.equals(val.value.toString(), 'cat2')
73 + t.equals(val.toString(), 'cat2')
7474 val = await tree.get(key2)
75- t.equals(val.value.toString(), 'cat')
75 + t.equals(val.toString(), 'cat')
7676 val = await tree.get(key3)
77- t.equals(val.value.toString(), 'cat3')
77 + t.equals(val.toString(), 'cat3')
7878
7979 t.end()
8080 })
8181
@@ -101,12 +101,12 @@
101101
102102 const subTree = await tree.getSubTree(key)
103103
104104 let val = await subTree.get(subKey1)
105- t.equals(val.value.toString(), 'cat')
105 + t.equals(val.toString(), 'cat')
106106
107107 val = await subTree.get(subKey2)
108- t.equals(val.value.toString(), 'dog')
108 + t.equals(val.toString(), 'dog')
109109
110110 t.end()
111111 })
112112
@@ -126,9 +126,9 @@
126126 tree.set('te', Buffer.from('cat2'))
127127 tree.set('ter', Buffer.from('cat3'))
128128 await tree.delete('te')
129129 let val = await tree.get('test')
130- t.equals(val.value.toString(), 'cat')
130 + t.equals(val.toString(), 'cat')
131131
132132 // tests delete end branchs
133133 tree.set('te', 'cat2')
134134 tree.delete('ter')
@@ -144,9 +144,9 @@
144144 })
145145 const saved = Buffer.alloc(33).fill(1)
146146 tree.set('test', saved)
147147 const value = await tree.get('test')
148- t.equals(value.value.toString(), saved.toString())
148 + t.equals(value.toString(), saved.toString())
149149 t.end()
150150 })
151151
152152 tape('errors', async t => {
@@ -179,9 +179,9 @@
179179
180180 for (let i = 0; i < entries; i++) {
181181 const key = crypto.createHash('sha256').update(i.toString()).digest().slice(0, 20)
182182 const value = await tree.get(key)
183- t.equals(value.value[0], i)
183 + t.equals(value[0], i)
184184 }
185185
186186 await tree.flush()
187187 for (let i = 0; i < entries; i++) {

Built with git-ssb-web