Comparing version 2.16.0 to 2.17.0
37
index.js
@@ -127,3 +127,3 @@ const codecs = require('codecs') | ||
async insertKey (key, child, node, encoding, cas) { | ||
async insertKey (key, value, child, node, encoding, cas) { | ||
let s = 0 | ||
@@ -138,3 +138,10 @@ let e = this.keys.length | ||
if (c === 0) { | ||
if (cas && !(await cas((await this.getKeyNode(mid)).final(encoding), node))) return true | ||
if (cas) { | ||
const prev = await this.getKeyNode(mid) | ||
if (!(await cas(prev.final(encoding), node))) return true | ||
} | ||
if (!this.block.tree.tree.alwaysDuplicate) { | ||
const prev = await this.getKeyNode(mid) | ||
if (sameValue(prev.value, value)) return true | ||
} | ||
this.changed = true | ||
@@ -327,2 +334,5 @@ this.keys[mid] = key | ||
// In a future version, this should be false by default | ||
this.alwaysDuplicate = opts.alwaysDuplicate !== false | ||
this._unprefixedKeyEncoding = this.keyEncoding | ||
@@ -821,4 +831,10 @@ this._sub = !!this.prefix | ||
if (c === 0) { | ||
if (cas && !(await cas((await node.getKeyNode(mid)).final(encoding), newNode))) return this._unlockMaybe() | ||
if (cas) { | ||
const prev = await node.getKeyNode(mid) | ||
if (!(await cas(prev.final(encoding), newNode))) return this._unlockMaybe() | ||
} | ||
if (!this.tree.alwaysDuplicate) { | ||
const prev = await node.getKeyNode(mid) | ||
if (sameValue(prev.value, value)) return this._unlockMaybe() | ||
} | ||
node.setKey(mid, target) | ||
@@ -836,3 +852,3 @@ return this._append(root, seq, key, value) | ||
let needsSplit = !(await node.insertKey(target, null, newNode, encoding, cas)) | ||
let needsSplit = !(await node.insertKey(target, value, null, newNode, encoding, cas)) | ||
if (!node.changed) return this._unlockMaybe() | ||
@@ -845,3 +861,3 @@ | ||
if (parent) { | ||
needsSplit = !(await parent.insertKey(median, right, null, encoding, null)) | ||
needsSplit = !(await parent.insertKey(median, value, right, null, encoding, null)) | ||
node = parent | ||
@@ -903,3 +919,6 @@ } else { | ||
if (c === 0) { | ||
if (cas && !(await cas((await node.getKeyNode(mid)).final(encoding), delNode))) return this._unlockMaybe() | ||
if (cas) { | ||
const prev = await node.getKeyNode(mid) | ||
if (!(await cas(prev.final(encoding), delNode))) return this._unlockMaybe() | ||
} | ||
if (node.children.length) await setKeyToNearestLeaf(node, mid, stack) | ||
@@ -1457,4 +1476,8 @@ else node.removeKey(mid) | ||
function sameValue (a, b) { | ||
return a === b || (a !== null && b !== null && b4a.equals(a, b)) | ||
} | ||
function noop () {} | ||
module.exports = Hyperbee |
{ | ||
"name": "hyperbee", | ||
"version": "2.16.0", | ||
"version": "2.17.0", | ||
"description": "An append-only B-tree running on a Hypercore.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
93988
2586