prefix-hash-tree 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +8 -8
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -35,7 +35,7 @@ class PrefixHashTree {
|
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
async _linearSearch(nodeLabel) {
|
|
38
|
-
for (let i = 0; i
|
|
38
|
+
for (let i = 0; i <= nodeLabel.length; i += 1) {
|
|
39
39
|
const { phtNode, metadata } = await this._dhtLookup(nodeLabel.substring(0, i))
|
|
40
40
|
|
|
41
41
|
if (phtNode !== null && isLeaf(phtNode)) {
|
|
@@ -47,19 +47,19 @@ class PrefixHashTree {
|
|
|
47
47
|
}
|
|
48
48
|
|
|
49
49
|
async _binarySearch(nodeLabel) {
|
|
50
|
-
let
|
|
51
|
-
let
|
|
50
|
+
let lo = 0
|
|
51
|
+
let hi = nodeLabel.length
|
|
52
52
|
|
|
53
|
-
while (
|
|
54
|
-
const
|
|
55
|
-
const { phtNode, metadata } = await this._dhtLookup(nodeLabel.substring(0,
|
|
53
|
+
while (lo <= hi) {
|
|
54
|
+
const mid = Math.floor((lo + hi) / 2)
|
|
55
|
+
const { phtNode, metadata } = await this._dhtLookup(nodeLabel.substring(0, mid))
|
|
56
56
|
|
|
57
57
|
if (phtNode !== null && isLeaf(phtNode)) {
|
|
58
58
|
return { phtNode, metadata }
|
|
59
59
|
} else if (phtNode !== null) {
|
|
60
|
-
|
|
60
|
+
lo = mid + 1
|
|
61
61
|
} else {
|
|
62
|
-
|
|
62
|
+
hi = mid - 1
|
|
63
63
|
}
|
|
64
64
|
}
|
|
65
65
|
|