Comparing version 1.20.3 to 1.20.4
@@ -18,2 +18,7 @@ "use strict"; | ||
const ITERATOR = Symbol('iter'); | ||
function merge(target, source, depth = 4) { | ||
if (depth === 0) return Object.assign(target, source); | ||
for (const key in source) target[key] = merge(target[key] || Object.create(null), source[key], depth - 1); | ||
return target; | ||
} | ||
@@ -129,3 +134,3 @@ // ## Constructor | ||
// Setting the key to _any_ value signals the presence of the quad | ||
const existed = (key2 in index2); | ||
const existed = key2 in index2; | ||
if (!existed) index2[key2] = null; | ||
@@ -751,3 +756,8 @@ return !existed; | ||
addAll(quads) { | ||
if (Array.isArray(quads)) this.addQuads(quads);else { | ||
if (Array.isArray(quads)) this.addQuads(quads);else if (quads instanceof N3Store && quads._entityIndex === this._entityIndex) { | ||
if (quads._size !== 0) { | ||
this._graphs = merge(this._graphs, quads._graphs); | ||
this._size = null; // Invalidate the cached size | ||
} | ||
} else { | ||
for (const quad of quads) this.add(quad); | ||
@@ -765,2 +775,3 @@ } | ||
contains(other) { | ||
if (other === this) return true; | ||
if (!(other instanceof N3Store) || this._entityIndex !== other._entityIndex) return other.every(quad => this.has(quad)); | ||
@@ -804,2 +815,5 @@ const g1 = this._graphs, | ||
difference(other) { | ||
if (other === this) return new N3Store({ | ||
entityIndex: this._entityIndex | ||
}); | ||
return this.filter(quad => !other.has(quad)); | ||
@@ -834,2 +848,9 @@ } | ||
intersection(other) { | ||
if (other === this) { | ||
const store = new N3Store({ | ||
entityIndex: this._entityIndex | ||
}); | ||
store._graphs = merge(Object.create(null), this._graphs); | ||
store._size = this._size; | ||
} | ||
return this.filter(quad => other.has(quad)); | ||
@@ -907,3 +928,4 @@ } | ||
}); | ||
store.addAll(this); | ||
store._graphs = merge(Object.create(null), this._graphs); | ||
store._size = this._size; | ||
store.addAll(quads); | ||
@@ -910,0 +932,0 @@ return store; |
{ | ||
"name": "n3", | ||
"version": "1.20.3", | ||
"version": "1.20.4", | ||
"description": "Lightning fast, asynchronous, streaming Turtle / N3 / RDF library.", | ||
@@ -39,6 +39,5 @@ "author": "Ruben Verborgh <ruben.verborgh@gmail.com>", | ||
"browserify": "^17.0.0", | ||
"colors": "^1.1.2", | ||
"deep-taxonomy-benchmark": "^1.2.0", | ||
"docco": "^0.9.1", | ||
"eslint": "^5.14.1", | ||
"eslint": "^8.57.0", | ||
"eslint-plugin-import": "^2.29.1", | ||
@@ -45,0 +44,0 @@ "jest": "^29.7.0", |
# Lightning fast, asynchronous, streaming RDF for JavaScript | ||
[![Build Status](https://github.com/rdfjs/N3.js/workflows/CI/badge.svg)](https://github.com/rdfjs/N3.js/actions) | ||
[![Build Status](https://github.com/rdfjs/n3.js/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/rdfjs/N3.js/actions) | ||
[![Coverage Status](https://coveralls.io/repos/github/rdfjs/N3.js/badge.svg)](https://coveralls.io/github/rdfjs/N3.js) | ||
@@ -4,0 +4,0 @@ [![npm version](https://badge.fury.io/js/n3.svg)](https://www.npmjs.com/package/n3) |
@@ -232,3 +232,3 @@ // N3.js implementations of the RDF/JS core data types | ||
termFromId(id[2], factory, true), | ||
id[3] && termFromId(id[3], factory, true) | ||
id[3] && termFromId(id[3], factory, true), | ||
); | ||
@@ -235,0 +235,0 @@ } |
@@ -10,2 +10,12 @@ // **N3Store** objects store N3 quads by graph in memory. | ||
function merge(target, source, depth = 4) { | ||
if (depth === 0) | ||
return Object.assign(target, source); | ||
for (const key in source) | ||
target[key] = merge(target[key] || Object.create(null), source[key], depth - 1); | ||
return target; | ||
} | ||
// ## Constructor | ||
@@ -35,3 +45,3 @@ export class N3EntityIndex { | ||
this._termFromId(entities[terms[3]]), | ||
terms[4] && this._termFromId(entities[terms[4]]) | ||
terms[4] && this._termFromId(entities[terms[4]]), | ||
); | ||
@@ -797,2 +807,8 @@ return q; | ||
this.addQuads(quads); | ||
else if (quads instanceof N3Store && quads._entityIndex === this._entityIndex) { | ||
if (quads._size !== 0) { | ||
this._graphs = merge(this._graphs, quads._graphs); | ||
this._size = null; // Invalidate the cached size | ||
} | ||
} | ||
else { | ||
@@ -805,3 +821,2 @@ for (const quad of quads) | ||
/** | ||
@@ -814,2 +829,5 @@ * Returns `true` if the current dataset is a superset of the given dataset; in other words, returns `true` if | ||
contains(other) { | ||
if (other === this) | ||
return true; | ||
if (!(other instanceof N3Store) || this._entityIndex !== other._entityIndex) | ||
@@ -856,2 +874,5 @@ return other.every(quad => this.has(quad)); | ||
difference(other) { | ||
if (other === this) | ||
return new N3Store({ entityIndex: this._entityIndex }); | ||
return this.filter(quad => !other.has(quad)); | ||
@@ -886,2 +907,7 @@ } | ||
intersection(other) { | ||
if (other === this) { | ||
const store = new N3Store({ entityIndex: this._entityIndex }); | ||
store._graphs = merge(Object.create(null), this._graphs); | ||
store._size = this._size; | ||
} | ||
return this.filter(quad => other.has(quad)); | ||
@@ -957,3 +983,5 @@ } | ||
const store = new N3Store({ entityIndex: this._entityIndex }); | ||
store.addAll(this); | ||
store._graphs = merge(Object.create(null), this._graphs); | ||
store._size = this._size; | ||
store.addAll(quads); | ||
@@ -960,0 +988,0 @@ return store; |
@@ -25,3 +25,3 @@ // **N3StreamParser** parses a text stream into a quad stream. | ||
// Emit prefixes through the `prefix` event | ||
(prefix, uri) => { this.emit('prefix', prefix, uri); } | ||
(prefix, uri) => { this.emit('prefix', prefix, uri); }, | ||
); | ||
@@ -28,0 +28,0 @@ |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
578439
17
8296