n3 2.6.3 → 2.6.4

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/lib/N3Store.js CHANGED
@@ -331,28 +331,25 @@ class N3Store {
331
331
 
332
332
  // ### `_countInIndex` counts matching quads in a three-layered index.
333
333
  // The index base is `index0` and the keys at each level are `key0`, `key1`, and `key2`.
334
- // Any of these keys can be undefined, which is interpreted as a wildcard.
334
+ // A key and any keys after it can be null or undefined, which is interpreted as a wildcard.
335
335
  _countInIndex(index0, key0, key1, key2) {
336
336
  let count = 0,
337
- tmp,
338
337
  index1,
339
338
  index2;
340
339
 
341
- // If a key is specified, count only that part of index 0
342
- if (key0) (tmp = index0, index0 = {})[key0] = tmp[key0];
343
- for (const value0 in index0) {
344
- if (index1 = index0[value0]) {
345
- // If a key is specified, count only that part of index 1
346
- if (key1) (tmp = index1, index1 = {})[key1] = tmp[key1];
347
- for (const value1 in index1) {
348
- if (index2 = index1[value1]) {
349
- // If a key is specified, count the quad if it exists
350
- if (key2) key2 in index2 && count++;
351
- // Otherwise, count all quads
352
- else count += index2[SIZE];
353
- }
354
- }
340
+ // Bound outer keys can be looked up directly.
341
+ if (key0) {
342
+ if (!(index1 = index0[key0])) return 0;
343
+ if (key1) {
344
+ if (!(index2 = index1[key1])) return 0;
345
+ return key2 ? key2 in index2 ? 1 : 0 : index2[SIZE];
355
346
  }
347
+ for (const value1 in index1) count += index1[value1][SIZE];
348
+ return count;
349
+ }
350
+ for (const value0 in index0) {
351
+ index1 = index0[value0];
352
+ for (const value1 in index1) count += index1[value1][SIZE];
356
353
  }
357
354
  return count;
358
355
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "n3",
3
- "version": "2.6.3",
3
+ "version": "2.6.4",
4
4
  "description": "Lightning fast, asynchronous, streaming Turtle / N3 / RDF library.",
5
5
  "author": "Ruben Verborgh <ruben.verborgh@gmail.com>",
6
6
  "keywords": [
package/src/N3Store.js CHANGED
@@ -351,25 +351,29 @@ export default class N3Store {
351
351
 
352
352
  // ### `_countInIndex` counts matching quads in a three-layered index.
353
353
  // The index base is `index0` and the keys at each level are `key0`, `key1`, and `key2`.
354
- // Any of these keys can be undefined, which is interpreted as a wildcard.
354
+ // A key and any keys after it can be null or undefined, which is interpreted as a wildcard.
355
355
  _countInIndex(index0, key0, key1, key2) {
356
- let count = 0, tmp, index1, index2;
356
+ let count = 0, index1, index2;
357
+
358
+ // Bound outer keys can be looked up directly.
359
+ if (key0) {
360
+ if (!(index1 = index0[key0]))
361
+ return 0;
362
+ if (key1) {
363
+ if (!(index2 = index1[key1]))
364
+ return 0;
365
+ return key2 ? (key2 in index2 ? 1 : 0) : index2[SIZE];
366
+ }
367
+
368
+ for (const value1 in index1)
369
+ count += index1[value1][SIZE];
370
+ return count;
371
+ }
357
372
 
358
- // If a key is specified, count only that part of index 0
359
- if (key0) (tmp = index0, index0 = {})[key0] = tmp[key0];
360
373
  for (const value0 in index0) {
361
- if (index1 = index0[value0]) {
362
- // If a key is specified, count only that part of index 1
363
- if (key1) (tmp = index1, index1 = {})[key1] = tmp[key1];
364
- for (const value1 in index1) {
365
- if (index2 = index1[value1]) {
366
- // If a key is specified, count the quad if it exists
367
- if (key2) (key2 in index2) && count++;
368
- // Otherwise, count all quads
369
- else count += index2[SIZE];
370
- }
371
- }
372
- }
374
+ index1 = index0[value0];
375
+ for (const value1 in index1)
376
+ count += index1[value1][SIZE];
373
377
  }
374
378
  return count;
375
379
  }