fast_array_intersect
Advanced tools
Comparing version 1.0.1 to 1.0.2
@@ -46,4 +46,10 @@ "use strict"; | ||
// Output only the elements that have been seen as many times as there are arrays | ||
return arrays[0].filter(e => set.get(hash(e)) === arrays.length); | ||
return arrays[0].filter(e => { | ||
const hashed = hash(e); | ||
const count = set.get(hashed); | ||
if (count !== undefined) | ||
set.set(hashed, 0); | ||
return count === arrays.length; | ||
}); | ||
} | ||
exports.default = intersect; |
{ | ||
"name": "fast_array_intersect", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "Fast intersection of multiple arrays", | ||
@@ -20,2 +20,10 @@ "main": "lib/index.js", | ||
], | ||
"keywords": [ | ||
"list", | ||
"intersection", | ||
"set", | ||
"intersecting", | ||
"array", | ||
"product" | ||
], | ||
"devDependencies": { | ||
@@ -22,0 +30,0 @@ "array-intersection-x": "^3.1.2", |
@@ -10,2 +10,3 @@ # fast_array_intersect | ||
 | ||
 | ||
@@ -67,46 +68,46 @@ ## How to use | ||
```diff | ||
``` | ||
2 arrays of 10 elements, with an intersection of size 5... | ||
+ fast_array_intersect x 1,184,797 ops/sec ±0.37% (95 runs sampled) | ||
intersect x 366,556 ops/sec ±0.42% (96 runs sampled) | ||
intersection-of x 301,857 ops/sec ±0.32% (92 runs sampled) | ||
array-intersection-x x 28,634 ops/sec ±0.37% (92 runs sampled) | ||
+ Fastest is fast_array_intersect | ||
fast_array_intersect x 1,064,622 ops/sec ±0.55% (92 runs sampled) | ||
intersect x 360,324 ops/sec ±0.46% (95 runs sampled) | ||
intersection-of x 303,913 ops/sec ±0.35% (97 runs sampled) | ||
array-intersection-x x 28,616 ops/sec ±0.20% (94 runs sampled) | ||
Fastest is fast_array_intersect | ||
2 arrays of 100 elements, with an intersection of size 10... | ||
+ fast_array_intersect x 129,016 ops/sec ±0.34% (96 runs sampled) | ||
intersect x 27,995 ops/sec ±0.29% (97 runs sampled) | ||
intersection-of x 29,102 ops/sec ±0.33% (92 runs sampled) | ||
array-intersection-x x 3,582 ops/sec ±0.19% (96 runs sampled) | ||
+ Fastest is fast_array_intersect | ||
fast_array_intersect x 104,023 ops/sec ±0.30% (92 runs sampled) | ||
intersect x 28,178 ops/sec ±0.38% (96 runs sampled) | ||
intersection-of x 30,345 ops/sec ±0.21% (94 runs sampled) | ||
array-intersection-x x 3,667 ops/sec ±0.32% (97 runs sampled) | ||
Fastest is fast_array_intersect | ||
10 arrays of 100 elements, with an intersection of size 99... | ||
+ fast_array_intersect x 42,378 ops/sec ±0.26% (96 runs sampled) | ||
intersect x 24,630 ops/sec ±0.32% (96 runs sampled) | ||
intersection-of x 39,934 ops/sec ±0.28% (95 runs sampled) | ||
array-intersection-x x 2,525 ops/sec ±0.22% (96 runs sampled) | ||
+ Fastest is fast_array_intersect | ||
fast_array_intersect x 41,212 ops/sec ±0.39% (92 runs sampled) | ||
intersect x 24,863 ops/sec ±0.36% (93 runs sampled) | ||
intersection-of x 40,573 ops/sec ±0.17% (96 runs sampled) | ||
array-intersection-x x 2,504 ops/sec ±0.14% (98 runs sampled) | ||
Fastest is fast_array_intersect | ||
10 arrays of 100 elements, with an intersection of size 0... | ||
+ fast_array_intersect x 152,349 ops/sec ±0.41% (97 runs sampled) | ||
intersect x 8,502 ops/sec ±0.40% (98 runs sampled) | ||
intersection-of x 6,429 ops/sec ±0.15% (97 runs sampled) | ||
array-intersection-x x 3,614 ops/sec ±0.35% (96 runs sampled) | ||
+ Fastest is fast_array_intersect | ||
fast_array_intersect x 156,244 ops/sec ±0.38% (95 runs sampled) | ||
intersect x 9,125 ops/sec ±0.29% (95 runs sampled) | ||
intersection-of x 6,426 ops/sec ±0.24% (97 runs sampled) | ||
array-intersection-x x 3,695 ops/sec ±0.31% (96 runs sampled) | ||
Fastest is fast_array_intersect | ||
1000 arrays of 10 elements, with an intersection of size 3... | ||
+ fast_array_intersect x 3,804 ops/sec ±0.34% (95 runs sampled) | ||
intersect x 416 ops/sec ±0.77% (87 runs sampled) | ||
intersection-of x 812 ops/sec ±0.23% (94 runs sampled) | ||
array-intersection-x x 2,701 ops/sec ±0.29% (95 runs sampled) | ||
+ Fastest is fast_array_intersect | ||
fast_array_intersect x 4,260 ops/sec ±0.29% (96 runs sampled) | ||
intersect x 438 ops/sec ±0.81% (92 runs sampled) | ||
intersection-of x 835 ops/sec ±0.17% (94 runs sampled) | ||
array-intersection-x x 2,672 ops/sec ±0.60% (95 runs sampled) | ||
Fastest is fast_array_intersect | ||
10 arrays of 1000 elements, with an intersection of size 500... | ||
+ fast_array_intersect x 2,787 ops/sec ±0.29% (96 runs sampled) | ||
intersect x 826 ops/sec ±0.71% (94 runs sampled) | ||
intersection-of x 1,164 ops/sec ±0.17% (95 runs sampled) | ||
array-intersection-x x 232 ops/sec ±0.27% (90 runs sampled) | ||
+ Fastest is fast_array_intersect | ||
fast_array_intersect x 2,701 ops/sec ±0.13% (97 runs sampled) | ||
intersect x 842 ops/sec ±0.63% (94 runs sampled) | ||
intersection-of x 1,193 ops/sec ±0.17% (96 runs sampled) | ||
array-intersection-x x 234 ops/sec ±0.33% (91 runs sampled) | ||
Fastest is fast_array_intersect | ||
``` | ||
For more details about the benchmark, see [`benchmark.js`](./benchmark.js). |
9005
66
112