fast-ternary-string-set
Advanced tools
Comparing version 2.1.0 to 2.1.1
@@ -401,7 +401,19 @@ /** | ||
* any existing elements are retained as a prefix of every string. | ||
* @param visitFn The non-null function to invoke for each string; returning | ||
* `false` will stop and return without visiting more strings. | ||
* @param visitFn The non-null function to invoke for each string. | ||
*/ | ||
private _visitCodePoints; | ||
/** | ||
* This behaves identically to `_visitCodePoints`, except that the | ||
* `visitFn` is expected to return a boolean value that indicates | ||
* whether or not the search (string visiting) should stop. | ||
* | ||
* @param node The starting node index (0 for tree root). | ||
* @param prefix The non-null array that will hold string code points; | ||
* any existing elements are retained as a prefix of every string. | ||
* @param visitFn The non-null function to invoke for each string; returning | ||
* `true` stops and returns without visiting more strings. | ||
* @returns A boolean indicating if the search was stopped by the callback. | ||
*/ | ||
private _searchCodePoints; | ||
/** | ||
* Tests whether a string specified as an array of numeric code points is in the set. | ||
@@ -408,0 +420,0 @@ * Returns a numeric result `n` as follows: |
@@ -527,7 +527,8 @@ "use strict"; | ||
let subset = true; | ||
this._visitCodePoints(0, [], (s) => { | ||
this._searchCodePoints(0, [], (s) => { | ||
if (rhs._hasCodePoints(0, s, 0) < 0) { | ||
subset = false; | ||
return false; | ||
return true; | ||
} | ||
return false; | ||
}); | ||
@@ -678,6 +679,4 @@ return subset; | ||
prefix.push(tree[node] & CP_MASK); | ||
if (tree[node] & EOS) { | ||
if (visitFn(prefix, node) === false) | ||
return; | ||
} | ||
if (tree[node] & EOS) | ||
visitFn(prefix, node); | ||
this._visitCodePoints(tree[node + 2], prefix, visitFn); | ||
@@ -687,2 +686,22 @@ prefix.pop(); | ||
} | ||
_searchCodePoints(node, prefix, visitFn) { | ||
const tree = this._tree; | ||
if (node >= tree.length) | ||
return false; | ||
if (this._searchCodePoints(tree[node + 1], prefix, visitFn)) | ||
return true; | ||
prefix.push(tree[node] & CP_MASK); | ||
if (tree[node] & EOS) { | ||
if (visitFn(prefix, node) === true) { | ||
prefix.pop(); | ||
return true; | ||
} | ||
} | ||
if (this._searchCodePoints(tree[node + 2], prefix, visitFn)) | ||
return true; | ||
prefix.pop(); | ||
if (this._searchCodePoints(tree[node + 3], prefix, visitFn)) | ||
return true; | ||
return false; | ||
} | ||
_hasCodePoints(node, s, i) { | ||
@@ -689,0 +708,0 @@ const tree = this._tree; |
{ | ||
"name": "fast-ternary-string-set", | ||
"version": "2.1.0", | ||
"version": "2.1.1", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
80459
1542