prefix-hash-tree 0.0.6 → 0.0.7

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 CHANGED
@@ -137,8 +137,7 @@ class PrefixHashTree {
137
137
 
138
138
  const parent = createPHTNode({
139
139
  label: label(leaf),
140
- child0: label(child0),
141
- child1: label(child1)
140
+ isLeaf: false
142
141
  })
143
142
 
144
143
  if (depth === lcp.length) {
package/lib/pht-node.d.ts CHANGED
@@ -1,8 +1,7 @@
1
1
  declare module 'prefix-hash-tree' {
2
2
  export interface PHTNode {
3
3
  label: string
4
- child0: string | null
5
- child1: string | null
4
+ isLeaf: boolean
6
5
  lPtr: string | null
7
6
  rPtr: string | null
8
7
  keys: Record<string, any>
package/lib/pht-node.js CHANGED
@@ -1,8 +1,7 @@
1
- function createPHTNode({ label, child0, child1, lPtr, rPtr, keys } = {}) {
1
+ function createPHTNode({ label, isLeaf, lPtr, rPtr, keys } = {}) {
2
2
  return {
3
3
  label: label || '',
4
- child0: child0 || null,
5
- child1: child1 || null,
4
+ isLeaf: isLeaf !== undefined ? isLeaf : true,
6
5
  lPtr: lPtr || null,
7
6
  rPtr: rPtr || null,
8
7
  keys: keys || {}
@@ -12,7 +11,7 @@ function createPHTNode({ label, child0, child1, lPtr, rPtr, keys } = {}) {
12
11
  function isNode(obj) {
13
12
  if (typeof obj !== 'object' || obj === null) return false
14
13
 
15
- const validKeys = new Set(['label', 'child0', 'child1', 'lPtr', 'rPtr', 'keys'])
14
+ const validKeys = new Set(['label', 'isLeaf', 'lPtr', 'rPtr', 'keys'])
16
15
 
17
16
  const keys = Object.keys(obj)
18
17
 
@@ -21,8 +20,7 @@ function isNode(obj) {
21
20
 
22
21
  return (
23
22
  isBinaryString(obj.label) &&
24
- isBinaryStringOrNull(obj.child0) &&
25
- isBinaryStringOrNull(obj.child1) &&
23
+ typeof obj.isLeaf === 'boolean' &&
26
24
  isBinaryStringOrNull(obj.lPtr) &&
27
25
  isBinaryStringOrNull(obj.rPtr) &&
28
26
  typeof obj.keys === 'object' &&
@@ -46,7 +44,7 @@ function isBinaryStringOrNull(v) {
46
44
  }
47
45
 
48
46
  function isLeaf(node) {
49
- return node.child0 === null && node.child1 === null
47
+ return node.isLeaf
50
48
  }
51
49
 
52
50
  function get(node, key) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "prefix-hash-tree",
3
- "version": "0.0.6",
3
+ "version": "0.0.7",
4
4
  "description": "An extensible prefix hash tree for indexing over distributed hash tables",
5
5
  "main": "index.js",
6
6
  "exports": {