prefix-hash-tree 0.0.4 → 0.0.5

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.d.ts CHANGED
@@ -24,6 +24,6 @@ declare module 'prefix-hash-tree' {
24
24
 
25
25
  searchExact(key: Buffer): Promise<any>
26
26
 
27
- prefixQuery(prefix: Buffer): Promise<[string, any][]>
27
+ prefixQuery(prefix: Buffer): Promise<[string, any][] | null>
28
28
  }
29
29
  }
package/index.js CHANGED
@@ -31,7 +31,7 @@ class PrefixHashTree {
31
31
  }
32
32
 
33
33
  async _dhtLookup(nodeLabel) {
34
- return await this.getFunc(this._labelHash(nodeLabel))
34
+ return this.getFunc(this._labelHash(nodeLabel))
35
35
  }
36
36
 
37
37
  async _linearSearch(nodeLabel) {
@@ -73,7 +73,7 @@ class PrefixHashTree {
73
73
  return result
74
74
  }
75
75
 
76
- return await this._linearSearch(nodeLabel)
76
+ return this._linearSearch(nodeLabel)
77
77
  }
78
78
 
79
79
  unhashedKeyFrom(string) {
@@ -158,7 +158,8 @@ class PrefixHashTree {
158
158
  await this.putFunc(this._labelHash(label(parent)), parent)
159
159
 
160
160
  const next =
161
- PrefixHashTree._lcp([lcp, label(child0)]) > PrefixHashTree._lcp([lcp, label(child1)])
161
+ PrefixHashTree._lcp([lcp, label(child0)]).length >
162
+ PrefixHashTree._lcp([lcp, label(child1)]).length
162
163
  ? child0
163
164
  : child1
164
165
 
@@ -168,7 +169,7 @@ class PrefixHashTree {
168
169
 
169
170
  async searchLeaf(key) {
170
171
  const keyLabel = PrefixHashTree._bufferToBase2String(key)
171
- return await this._fullSearch(keyLabel)
172
+ return this._fullSearch(keyLabel)
172
173
  }
173
174
 
174
175
  async searchExact(key) {
@@ -196,7 +197,7 @@ class PrefixHashTree {
196
197
  return null
197
198
  }
198
199
 
199
- return await this._doPrefixQuery({ phtNode: startNode, prefix: prefix })
200
+ return this._doPrefixQuery({ phtNode: startNode, prefix })
200
201
  }
201
202
 
202
203
  async _doPrefixQuery({ phtNode, prefix } = {}) {
@@ -207,7 +208,6 @@ class PrefixHashTree {
207
208
 
208
209
  const subtree0 = `${label(phtNode)}0`
209
210
  const subtree1 = `${label(phtNode)}1`
210
- const prefixLabel = PrefixHashTree._bufferToBase2String(prefix)
211
211
 
212
212
  const results = await Promise.all([
213
213
  (async () => {
@@ -226,9 +226,7 @@ class PrefixHashTree {
226
226
  }
227
227
 
228
228
  static _bufferToBase2String(buf) {
229
- return Array.from(buf)
230
- .map((byte) => byte.toString(2).padStart(8, '0'))
231
- .join('')
229
+ return Array.from(buf, (byte) => byte.toString(2).padStart(8, '0')).join('')
232
230
  }
233
231
 
234
232
  static _lcp(strings = []) {
package/lib/pht-node.d.ts CHANGED
@@ -22,7 +22,7 @@ declare module 'prefix-hash-tree' {
22
22
 
23
23
  export function size(node: PHTNode): number
24
24
 
25
- export function setPointers(node: PHTNode, left: string, right: string): void
25
+ export function setPointers(node: PHTNode, left: string | null, right: string | null): void
26
26
 
27
27
  export function pointerLeft(node: PHTNode): string | null
28
28
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "prefix-hash-tree",
3
- "version": "0.0.4",
3
+ "version": "0.0.5",
4
4
  "description": "An extensible prefix hash tree for indexing over distributed hash tables",
5
5
  "main": "index.js",
6
6
  "exports": {