git ssb

0+

wanderer🌟 / js-dfinity-radix-tree



Commit 0ab6c08c96392d6f3a76fbaf0a826b48445e56b8

return tree node when setting value

Signed-off-by: wanderer <mjbecze@gmail.com>
wanderer committed on 3/5/2018, 11:25:29 PM
Parent: 3228beb1ebc4a9921b555fd514ede84f91ce5bf9

Files changed

index.jschanged
index.jsView
@@ -79,9 +79,9 @@
7979 return {value, root, node, parent, index}
8080 }
8181
8282 /**
83- * stores a value at a given key
83 + * stores a value at a given key returning the tree node that the value was saved in
8484 * @param {*} key
8585 * @return {Promise}
8686 */
8787 set (key, value) {
@@ -91,13 +91,15 @@
9191
9292 async _set (key, value) {
9393 if (treeNode.isEmpty(this.root)) {
9494 this.root['/'] = createNode(key, [null, null], value)['/']
95 + return this.root['/']
9596 } else {
96- let {root, extensionIndex, extension, index, value: rValue} = await this._get(key)
97 + let {node, root, extensionIndex, extension, index, value: rValue} = await this._get(key)
9798
9899 if (rValue) {
99100 treeNode.setValue(root, value)
101 + return node
100102 } else {
101103 if (extensionIndex !== undefined) {
102104 // split the extension node in two
103105 const extensionKey = extension[extensionIndex]
@@ -119,17 +121,19 @@
119121 const newNode = createNode(extension, [null, null], value)
120122 const rootBranch = treeNode.getBranch(root)
121123 rootBranch[keySegment] = newNode
122124 treeNode.setBranch(root, rootBranch)
125 + return newNode['/']
123126 } else {
124127 treeNode.setValue(root, value)
128 + return root['/']
125129 }
126130 }
127131 }
128132 }
129133
130134 /**
131- * deletes a value at a given key
135 + *smContainer.js deletes a value at a given key
132136 * @param {*} key
133137 * @return {Promise}
134138 */
135139 delete (key) {

Built with git-ssb-web