Skip to content

Commit

Permalink
Improve the db2 seekers in operators.js
Browse files Browse the repository at this point in the history
  • Loading branch information
staltz authored Oct 23, 2023
1 parent 165967e commit 8df71a5
Showing 1 changed file with 19 additions and 21 deletions.
40 changes: 19 additions & 21 deletions lib/operators.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,15 @@ module.exports = {
}
const B_TANGLE = B_TANGLE_MAP.get(tangle)

function seekTangleRoot(buffer, start, p) {
if (p < 0) return -1
p = seekKey2(buffer, 0, B_VALUE, 0)
if (p < 0) return -1
p = seekKey2(buffer, p, B_CONTENT, 0)
if (p < 0) return -1
p = seekKey2(buffer, p, B_TANGLES, 0)
if (p < 0) return -1
p = seekKey2(buffer, p, B_TANGLE, 0)
if (p < 0) return -1
return seekKey2(buffer, p, B_ROOT, 0)
function seekTangleRoot(buffer, start, pValue) {
if (pValue < 0) return -1
const pValueContent = seekKey2(buffer, pValue, B_CONTENT, 0)
if (pValueContent < 0) return -1
const pValueContentTangles = seekKey2(buffer, pValueContent, B_TANGLES, 0)
if (pValueContentTangles < 0) return -1
const pValueContentTanglesTangle = seekKey2(buffer, pValueContentTangles, B_TANGLE, 0)
if (pValueContentTanglesTangle < 0) return -1
return seekKey2(buffer, pValueContentTanglesTangle, B_ROOT, 0)
}

return equal(seekTangleRoot, value, {
Expand All @@ -47,18 +45,18 @@ module.exports = {
},
}

function seekFirstRecp(buffer, start, p) {
if (p < 0) return -1
p = seekKey2(buffer, p, B_CONTENT, 0)
if (p < 0) return -1
p = seekKey2(buffer, p, B_RECPS, 0)
if (p < 0) return -1
function seekFirstRecp(buffer, start, pValue) {
if (pValue < 0) return -1
const pValueContent = seekKey2(buffer, pValue, B_CONTENT, 0)
if (pValueContent < 0) return -1
const pValueContentRecps = seekKey2(buffer, pValueContent, B_RECPS, 0)
if (pValueContentRecps < 0) return -1

let pValueFirstRecp
const error = iterate(buffer, p, (_, pointer) => {
pValueFirstRecp = pointer
let pValueContentRecps0
const error = iterate(buffer, pValueContentRecps, (_, pointer) => {
pValueContentRecps0 = pointer
return true
})
if (error === -1) return -1
return pValueFirstRecp
return pValueContentRecps0
}

0 comments on commit 8df71a5

Please sign in to comment.