fast-ternary-string-set
Advanced tools
Comparing version 1.0.2 to 1.0.3
@@ -357,4 +357,4 @@ "use strict"; | ||
throw new TypeError("distance must be a number"); | ||
// only the string itself is within distance 0 | ||
if (distance < 1) { | ||
// only the string itself is within distance 0 or matches empty pattern | ||
if (distance < 1 || pattern.length === 0) { | ||
return this.has(pattern) ? [pattern] : []; | ||
@@ -361,0 +361,0 @@ } |
{ | ||
"name": "fast-ternary-string-set", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -14,6 +14,6 @@ # Fast ternary string set | ||
- The tree structure is encoded in a form that is friendly to common JS engine optimizations. | ||
- Elements are stored by Unicode code point; any valid Unicode string can be added to a`TernaryStringSet`. | ||
- Sets can be serialized to a compact binary format (an `ArrayBuffer`). | ||
- Written in TypeScript with full documentation, targeting modern JavaScript engines. | ||
- Backed by an extensive test suite. | ||
- Elements are stored by Unicode code point; any valid Unicode string can be added to a set. | ||
- Sets can be serialized to a compact binary format (as an `ArrayBuffer`). | ||
- Written in fully documented TypeScript, targeting modern JavaScript engines. | ||
- Backed by extensive test suites. | ||
- No other dependencies. | ||
@@ -52,8 +52,9 @@ | ||
set.add("dog").add("cat").add("eagle"); | ||
console.log(set.has("cat")); | ||
set.has("cat"); | ||
// => true | ||
set.delete("cat"); | ||
console.log(set.has("cat")); | ||
// => true since "cat" was in the set | ||
set.has("cat"); | ||
// => false | ||
console.log(set.has(123.456)); | ||
set.has(123.456); | ||
// => false (any non-string returns false) | ||
@@ -65,3 +66,6 @@ ``` | ||
```js | ||
const stringArray = ["aardvark", "beaver", "cat", "dog", "eagle", /* ..., */ "zebra"]; | ||
const stringArray = [ | ||
"aardvark", "beaver", "cat", | ||
"dog", "eagle", /* ..., */ "zebra" | ||
]; | ||
set.addAll(stringArray); | ||
@@ -73,5 +77,7 @@ ``` | ||
```js | ||
for(let el of set) { | ||
for (const el of set) { | ||
console.log(el); | ||
} | ||
// or equivalently: | ||
set.forEach((el) => console.log(el)); | ||
``` | ||
@@ -82,6 +88,30 @@ | ||
```js | ||
console.log(set.getArrangementsOf("taco")); | ||
// => ["act", "cat", "taco"] (for example) | ||
set.getArrangementsOf("taco"); | ||
// => ["act", "cat", "coat", "taco"] (for example) | ||
``` | ||
Find all elements within Hamming distance 1 of "cat": | ||
```js | ||
set.getWithinHammingDistanceOf("cat", 1); | ||
// => ["bat", "can", "cap", "cat", "cot", "sat"] (for example) | ||
``` | ||
Find all elements that match "b.t": | ||
```js | ||
set.getPartialMatchesOf("b.t"); | ||
// => ["bat", "bet", "bit", "bot", "but"] (for example) | ||
``` | ||
Serialize to or from a binary blob: | ||
```js | ||
// write a set to an ArrayBuffer | ||
const buff = set.toBuffer(); | ||
// create a new set from a previously saved ArrayBuffer | ||
const set = TernaryStringSet.fromBuffer(buff); | ||
``` | ||
## Differences from standard JS `Set` | ||
@@ -88,0 +118,0 @@ |
46851
156