From 404ae18545adbb66b7c73d14c884731f30167a14 Mon Sep 17 00:00:00 2001 From: RubenVerborgh Date: Thu, 12 May 2022 10:21:21 +0000 Subject: [PATCH] deploy: 51c86cdb74419ba08cb43bfd277f61cdb394250a --- docs/N3Store.html | 503 ++++++++++++++++++++++------------------------ 1 file changed, 243 insertions(+), 260 deletions(-) diff --git a/docs/N3Store.html b/docs/N3Store.html index 000e3256..cebfcf44 100644 --- a/docs/N3Store.html +++ b/docs/N3Store.html @@ -415,7 +415,10 @@

_findI
  *_findInIndex(index0, key0, key1, key2, name0, name1, name2, graphId) {
-    let tmp, index1, index2;
+ let tmp, index1, index2; + const entityKeys = this._entities; + const graph = termFromId(graphId, this._factory); + const parts = { subject: null, predicate: null, object: null }; @@ -426,41 +429,23 @@

_findI
§
-

Depending on the number of variables, keys or reverse index are faster

- - - -
    const varCount = !key0 + !key1 + !key2,
-        entityKeys = varCount > 1 ? Object.keys(this._ids) : this._entities;
-    const graph = termFromId(graphId, this._factory);
- - - - -
  • -
    - -
    - § -

    If a key is specified, use only that part of index 0.

        if (key0) (tmp = index0, index0 = {})[key0] = tmp[key0];
         for (const value0 in index0) {
    -      const entity0 = entityKeys[value0];
    -
    -      if (index1 = index0[value0]) {
    + if (index1 = index0[value0]) { + parts[name0] = termFromId(entityKeys[value0], this._factory);
  • -
  • +
  • - § + §

    If a key is specified, use only that part of index 1.

    @@ -468,18 +453,17 @@

    _findI
            if (key1) (tmp = index1, index1 = {})[key1] = tmp[key1];
             for (const value1 in index1) {
    -          const entity1 = entityKeys[value1];
    -
    -          if (index2 = index1[value1]) {
    + if (index2 = index1[value1]) { + parts[name1] = termFromId(entityKeys[value1], this._factory);

  • -
  • +
  • - § + §

    If a key is specified, use only that part of index 2, if it exists.

    @@ -490,20 +474,17 @@

    _findI

  • -
  • +
  • - § + §

    Create quads for all items found in index 2.

                for (let l = 0; l < values.length; l++) {
    -              const parts = { subject: null, predicate: null, object: null };
    -              parts[name0] = termFromId(entity0, this._factory);
    -              parts[name1] = termFromId(entity1, this._factory);
                   parts[name2] = termFromId(entityKeys[values[l]], this._factory);
                   yield this._factory.quad(parts.subject, parts.predicate, parts.object, graph);
                 }
    @@ -516,11 +497,11 @@ 

    _findI

  • -
  • +
  • - § + §

    _loop executes the callback on all keys of index 0

    @@ -534,11 +515,11 @@

    _loop e

  • -
  • +
  • - § + §

    _loopByKey0 executes the callback on all keys of a certain entry in index 0

    @@ -555,11 +536,11 @@

    +
  • - § + §

    _loopByKey1 executes the callback on given keys of all entries in index 0

    @@ -577,11 +558,11 @@

    +
  • - § + §

    _loopBy2Keys executes the callback on given keys of certain entries in index 2

    @@ -598,11 +579,11 @@

    +
  • - § + §

    _countInIndex counts matching quads in a three-layered index.

    The index base is index0 and the keys at each level are key0, key1, and key2. @@ -616,11 +597,11 @@

    _cou

  • -
  • +
  • - § + §

    If a key is specified, count only that part of index 0

    @@ -633,11 +614,11 @@

    _cou

  • -
  • +
  • - § + §

    If a key is specified, count only that part of index 1

    @@ -650,11 +631,11 @@

    _cou

  • -
  • +
  • - § + §

    If a key is specified, count the quad if it exists

    @@ -665,11 +646,11 @@

    _cou

  • -
  • +
  • - § + §

    Otherwise, count all quads

    @@ -686,11 +667,11 @@

    _cou

  • -
  • +
  • - § + §

    _getGraphs returns an array with the given graph,

    or all graphs if the argument is null or undefined.

    @@ -708,11 +689,11 @@

    _getGraphs -
  • +
  • - § + §

    _uniqueEntities returns a function that accepts an entity ID

    and passes the corresponding entity to callback if it hasn’t occurred before.

    @@ -732,11 +713,11 @@

    _uni

  • -
  • +
  • - § + §

    Public methods

    @@ -745,11 +726,11 @@

    Public methods

  • -
  • +
  • - § + §

    add adds the specified quad to the dataset.

    Returns the dataset instance it was called on. @@ -765,11 +746,11 @@

    add adds the sp

  • -
  • +
  • - § + §

    addQuad adds a new quad to the store.

    Returns if the quad index has changed, if the quad did not already exist.

    @@ -781,11 +762,11 @@

    addQuad adds a new qu

  • -
  • +
  • - § + §

    Shift arguments if a quad object is given instead of components

    @@ -798,11 +779,11 @@

    addQuad adds a new qu

  • -
  • +
  • - § + §

    Convert terms to internal string representation

    @@ -816,11 +797,11 @@

    addQuad adds a new qu

  • -
  • +
  • - § + §

    Find the graph that will contain the triple

    @@ -831,11 +812,11 @@

    addQuad adds a new qu

  • -
  • +
  • - § + §

    Create the graph if it doesn’t exist yet

    @@ -847,11 +828,11 @@

    addQuad adds a new qu

  • -
  • +
  • - § + §

    Freezing a graph helps subsequent add performance, and properties will never be modified anyway

    @@ -864,11 +845,11 @@

    addQuad adds a new qu

  • -
  • +
  • - § + §

    Since entities can often be long IRIs, we avoid storing them in every index. Instead, we have a separate index that maps entities to numbers, @@ -889,11 +870,11 @@

    addQuad adds a new qu

  • -
  • +
  • - § + §

    The cached quad count is now invalid

    @@ -906,11 +887,11 @@

    addQuad adds a new qu

  • -
  • +
  • - § + §

    addQuads adds multiple quads to the store

    @@ -924,11 +905,11 @@

    addQuads adds mu

  • -
  • +
  • - § + §

    delete removes the specified quad from the dataset.

    Returns the dataset instance it was called on.

    @@ -943,11 +924,11 @@

    delete

  • -
  • +
  • - § + §

    has determines whether a dataset includes a certain quad or quad pattern.

    @@ -962,11 +943,11 @@

    +
  • - § + §

    import adds a stream of quads to the store

    @@ -980,11 +961,11 @@

    import adds a s

  • -
  • +
  • - § + §

    removeQuad removes a quad from the store if it exists

    @@ -995,11 +976,11 @@

    removeQuad<

  • -
  • +
  • - § + §

    Shift arguments if a quad object is given instead of components

    @@ -1012,11 +993,11 @@

    removeQuad<

  • -
  • +
  • - § + §

    Convert terms to internal string representation

    @@ -1030,11 +1011,11 @@

    removeQuad<

  • -
  • +
  • - § + §

    Find internal identifiers for all components and verify the quad exists.

    @@ -1053,11 +1034,11 @@

    removeQuad<

  • -
  • +
  • - § + §

    Remove it from all indexes

    @@ -1071,11 +1052,11 @@

    removeQuad<

  • -
  • +
  • - § + §

    Remove the graph if it is empty

    @@ -1089,11 +1070,11 @@

    removeQuad<

  • -
  • +
  • - § + §

    removeQuads removes multiple quads from the store

    @@ -1107,11 +1088,11 @@

    removeQuads -
  • +
  • - § + §

    remove removes a stream of quads from the store

    @@ -1125,11 +1106,11 @@

    remove rem

  • -
  • +
  • - § + §

    removeMatches removes all matching quads from the store

    Setting any field to undefined or null indicates a wildcard.

    @@ -1151,11 +1132,11 @@

    removeMat

  • -
  • +
  • - § + §

    deleteGraph removes all triples with the given graph from the store

    @@ -1168,11 +1149,11 @@

    -
  • +
  • - § + §

    getQuads returns an array of quads matching a pattern.

    Setting any field to undefined or null indicates a wildcard.

    @@ -1186,11 +1167,11 @@

    getQuads -
  • +
  • - § + §

    readQuads returns an generator of quads matching a pattern.

    Setting any field to undefined or null indicates a wildcard.

    @@ -1202,11 +1183,11 @@

    readQu

  • -
  • +
  • - § + §

    Convert terms to internal string representation

    @@ -1223,11 +1204,11 @@

    readQu

  • -
  • +
  • - § + §

    Translate IRIs to internal index keys.

    @@ -1243,11 +1224,11 @@

    readQu

  • -
  • +
  • - § + §

    Only if the specified graph contains triples, there can be results

    @@ -1258,11 +1239,11 @@

    readQu

  • -
  • +
  • - § + §

    Choose the optimal index, based on what fields are present

    @@ -1274,87 +1255,87 @@

    readQu

  • -
  • +
  • - § + §

    If subject and object are given, the object index will be the fastest

                yield* this._findInIndex(content.objects, objectId, subjectId, predicateId,
    -                              'object', 'subject', 'predicate', graphId, null, true);
    +                              'object', 'subject', 'predicate', graphId);
               else
  • -
  • +
  • - § + §

    If only subject and possibly predicate are given, the subject index will be the fastest

                yield* this._findInIndex(content.subjects, subjectId, predicateId, null,
    -                              'subject', 'predicate', 'object', graphId, null, true);
    +                              'subject', 'predicate', 'object', graphId);
             }
             else if (predicateId)
  • -
  • +
  • - § + §

    If only predicate and possibly object are given, the predicate index will be the fastest

              yield* this._findInIndex(content.predicates, predicateId, objectId, null,
    -                            'predicate', 'object', 'subject', graphId, null, true);
    +                            'predicate', 'object', 'subject', graphId);
             else if (objectId)
  • -
  • +
  • - § + §

    If only object is given, the object index will be the fastest

              yield* this._findInIndex(content.objects, objectId, null, null,
    -                            'object', 'subject', 'predicate', graphId, null, true);
    +                            'object', 'subject', 'predicate', graphId);
             else
  • -
  • +
  • - § + §

    If nothing is given, iterate subjects and predicates first

              yield* this._findInIndex(content.subjects, null, null, null,
    -                            'subject', 'predicate', 'object', graphId, null, true);
    +                            'subject', 'predicate', 'object', graphId);
           }
         }
       }
    @@ -1362,11 +1343,11 @@

    readQu

  • -
  • +
  • - § + §

    match returns a new dataset that is comprised of all quads in the current instance matching the given arguments.

    The logic described in Quad Matching is applied for each quad in this dataset to check if it should be included in the output dataset. @@ -1384,11 +1365,11 @@

    +
  • - § + §

    countQuads returns the number of quads matching a pattern.

    Setting any field to undefined or null indicates a wildcard.

    @@ -1400,11 +1381,11 @@

    countQu

  • -
  • +
  • - § + §

    Convert terms to internal string representation

    @@ -1421,11 +1402,11 @@

    countQu

  • -
  • +
  • - § + §

    Translate IRIs to internal index keys.

    @@ -1441,11 +1422,11 @@

    countQu

  • -
  • +
  • - § + §

    Only if the specified graph contains triples, there can be results

    @@ -1456,11 +1437,11 @@

    countQu

  • -
  • +
  • - § + §

    Choose the optimal index, based on what fields are present

    @@ -1472,11 +1453,11 @@

    countQu

  • -
  • +
  • - § + §

    If subject and object are given, the object index will be the fastest

    @@ -1488,11 +1469,11 @@

    countQu

  • -
  • +
  • - § + §

    If only subject and possibly predicate are given, the subject index will be the fastest

    @@ -1505,11 +1486,11 @@

    countQu

  • -
  • +
  • - § + §

    If only predicate and possibly object are given, the predicate index will be the fastest

    @@ -1522,11 +1503,11 @@

    countQu

  • -
  • +
  • - § + §

    If only object is possibly given, the object index will be the fastest

    @@ -1542,11 +1523,11 @@

    countQu

  • -
  • +
  • - § + §

    forEach executes the callback on all quads.

    Setting any field to undefined or null indicates a wildcard.

    @@ -1563,11 +1544,11 @@

    forEach execute

  • -
  • +
  • - § + §

    every executes the callback on all quads,

    and returns true if it returns truthy for all them. @@ -1587,11 +1568,11 @@

    every executes th

  • -
  • +
  • - § + §

    some executes the callback on all quads,

    and returns true if it returns truthy for any of them. @@ -1609,11 +1590,11 @@

    some executes the

  • -
  • +
  • - § + §

    getSubjects returns all subjects that match the pattern.

    Setting any field to undefined or null indicates a wildcard.

    @@ -1629,11 +1610,11 @@

    getSubjec

  • -
  • +
  • - § + §

    forSubjects executes the callback on all subjects that match the pattern.

    Setting any field to undefined or null indicates a wildcard.

    @@ -1645,11 +1626,11 @@

    +
  • - § + §

    Convert terms to internal string representation

    @@ -1666,11 +1647,11 @@

    +
  • - § + §

    Translate IRIs to internal index keys.

    @@ -1685,11 +1666,11 @@

    +
  • - § + §

    Only if the specified graph contains triples, there can be results

    @@ -1700,11 +1681,11 @@

    +
  • - § + §

    Choose optimal index based on which fields are wildcards

    @@ -1716,11 +1697,11 @@

    +
  • - § + §

    If predicate and object are given, the POS index is best.

    @@ -1732,11 +1713,11 @@

    +
  • - § + §

    If only predicate is given, the SPO index is best.

    @@ -1749,11 +1730,11 @@

    +
  • - § + §

    If only object is given, the OSP index is best.

    @@ -1765,11 +1746,11 @@

    +
  • - § + §

    If no params given, iterate all the subjects

    @@ -1783,11 +1764,11 @@

    +
  • - § + §

    getPredicates returns all predicates that match the pattern.

    Setting any field to undefined or null indicates a wildcard.

    @@ -1803,11 +1784,11 @@

    getPr

  • -
  • +
  • - § + §

    forPredicates executes the callback on all predicates that match the pattern.

    Setting any field to undefined or null indicates a wildcard.

    @@ -1819,11 +1800,11 @@

    +
  • - § + §

    Convert terms to internal string representation

    @@ -1840,11 +1821,11 @@

    +
  • - § + §

    Translate IRIs to internal index keys.

    @@ -1859,11 +1840,11 @@

    +
  • - § + §

    Only if the specified graph contains triples, there can be results

    @@ -1874,11 +1855,11 @@

    +
  • - § + §

    Choose optimal index based on which fields are wildcards

    @@ -1890,11 +1871,11 @@

    +
  • - § + §

    If subject and object are given, the OSP index is best.

    @@ -1906,11 +1887,11 @@

    +
  • - § + §

    If only subject is given, the SPO index is best.

    @@ -1923,11 +1904,11 @@

    +
  • - § + §

    If only object is given, the POS index is best.

    @@ -1939,11 +1920,11 @@

    +
  • - § + §

    If no params given, iterate all the predicates.

    @@ -1957,11 +1938,11 @@

    +
  • - § + §

    getObjects returns all objects that match the pattern.

    Setting any field to undefined or null indicates a wildcard.

    @@ -1977,11 +1958,11 @@

    getObjects<

  • -
  • +
  • - § + §

    forObjects executes the callback on all objects that match the pattern.

    Setting any field to undefined or null indicates a wildcard.

    @@ -1993,11 +1974,11 @@

  • -
  • +
  • - § + §

    Convert terms to internal string representation

    @@ -2014,11 +1995,11 @@

  • -
  • +
  • - § + §

    Translate IRIs to internal index keys.

    @@ -2033,11 +2014,11 @@

  • -
  • +
  • - § + §

    Only if the specified graph contains triples, there can be results

    @@ -2048,11 +2029,11 @@

  • -
  • +
  • - § + §

    Choose optimal index based on which fields are wildcards

    @@ -2064,11 +2045,11 @@

  • -
  • +
  • - § + §

    If subject and predicate are given, the SPO index is best.

    @@ -2080,11 +2061,11 @@

  • -
  • +
  • - § + §

    If only subject is given, the OSP index is best.

    @@ -2097,11 +2078,11 @@

  • -
  • +
  • - § + §

    If only predicate is given, the POS index is best.

    @@ -2113,11 +2094,11 @@

  • -
  • +
  • - § + §

    If no params given, iterate all the objects.

    @@ -2131,11 +2112,11 @@

  • -
  • +
  • - § + §

    getGraphs returns all graphs that match the pattern.

    Setting any field to undefined or null indicates a wildcard.

    @@ -2151,11 +2132,11 @@

    getGraphs -
  • +
  • - § + §

    forGraphs executes the callback on all graphs that match the pattern.

    Setting any field to undefined or null indicates a wildcard.

    @@ -2174,11 +2155,11 @@

    -
  • +
  • - § + §

    createBlankNode creates a new blank node, returning its name

    @@ -2190,11 +2171,11 @@

    creat

  • -
  • +
  • - § + §

    Generate a name based on the suggested name

    @@ -2209,11 +2190,11 @@

    creat

  • -
  • +
  • - § + §

    Generate a generic blank node name

    @@ -2227,11 +2208,11 @@

    creat

  • -
  • +
  • - § + §

    Add the blank node to the entities, avoiding the generation of duplicates

    @@ -2245,11 +2226,11 @@

    creat

  • -
  • +
  • - § + §

    extractLists finds and removes all list triples

    and returns the items per list.

    @@ -2264,11 +2245,11 @@

    extractLists -
  • +
  • - § + §

    Traverse each list from its tail

    @@ -2286,11 +2267,11 @@

    extractLists -
  • +
  • - § + §

    Traverse the list from tail to end

    @@ -2305,11 +2286,11 @@

    extractLists -
  • +
  • - § + §

    Find the first and rest of this list node

    @@ -2325,11 +2306,11 @@

    extractLists -
  • +
  • - § + §

    one rdf:first

    @@ -2345,11 +2326,11 @@

    extractLists -
  • +
  • - § + §

    one rdf:rest

    @@ -2365,11 +2346,11 @@

    extractLists -
  • +
  • - § + §

    alien triple

    @@ -2386,11 +2367,11 @@

    extractLists -
  • +
  • - § + §

    { :s :p (1 2) } arrives here with no head { (1 2) :p :o } arrives here with head set to the list.

    @@ -2405,11 +2386,11 @@

    extractLists -
  • +
  • - § + §

    one rdf:rest

    @@ -2430,11 +2411,11 @@

    extractLists -
  • +
  • - § + §

    Store the list item and continue with parent

    @@ -2450,11 +2431,11 @@

    extractLists -
  • +
  • - § + §

    Don’t remove any quads if the list is malformed

    @@ -2466,11 +2447,11 @@

    extractLists -
  • +
  • - § + §

    Store the list under the value of its head

    @@ -2483,11 +2464,11 @@

    extractLists -
  • +
  • - § + §

    Remove list quads if requested

    @@ -2501,11 +2482,11 @@

    extractLists -
  • +
  • - § + §

    Store is an iterable.

    Can be used where iterables are expected: for…of loops, array spread operator, @@ -2521,11 +2502,11 @@

    Store is an iterable.

  • -
  • +
  • - § + §

    Determines whether the argument is a string

    @@ -2547,11 +2528,13 @@

    Store is an iterable.

    get filtered() { if (!this._filtered) { const { n3Store, graph, object, predicate, subject } = this; - const quads = n3Store.getQuads(subject, predicate, object, graph); - this._filtered = new N3Store(quads, { factory: n3Store._factory }); + const newStore = this._filtered = new N3Store({ factory: n3Store._factory }); + for (const quad of n3Store.readQuads(subject, predicate, object, graph)) + newStore.addQuad(quad); } return this._filtered; } + get size() { return this.filtered.size; }