Class FastTripleStore

java.lang.Object
org.apache.jena.mem.store.fast.FastTripleStore
All Implemented Interfaces:
org.apache.jena.atlas.lib.Copyable<TripleStore>, TripleStore

public class FastTripleStore extends Object implements TripleStore
A triple store that uses hash tables to map from nodes to triple bunches.

Inner structure: - three FastHashMap, one for each node (subject, predicate, object) in the triple - each map maps from a node to a FastTripleBunch - for up to 16 triples with the same subject, the bunch is an FastArrayBunch, otherwise it is a FastHashedTripleBunch - for up to 32 triples with the same predicate and object, the bunch is an FastArrayBunch, otherwise it is a FastHashedTripleBunch

Other optimizations: - each triple is added to three FastTripleBunches. To avoid the overhead of calculating the hash code three times, the hash code is calculated once and passed to the FastTripleBunches. - the different sizes for the FastArrayBunches are chosen: - to avoid the memory-overhead of FastHashedTripleBunch for a small number of triples - the subject bunch is smaller than the predicate and object bunches, because the subject is typically used for #contains operations, which are faster for FastHashedTripleBunches. - the predicate and object bunches are the same size, because they are typically used for #find operations, which typically do not answer #contains operations. Making them much larger might slow down #remove operations on the graph. - "ANY_PRE_OBJ" matches primarily use the object bunch unless the size of the bunch is larger than 400 triples. In that case, there is a secondary lookup in the predicate bunch. Then the smaller bunch is used for the lookup. Especially for RDF graphs there are some very common object nodes like "true"/"false" or "0"/"1". In that case, a secondary lookup in the predicate bunch might be faster than a primary lookup in the object bunch. - FastTripleStore#contains uses FastTripleBunch.anyMatchRandomOrder(java.util.function.Predicate<org.apache.jena.graph.Triple>) for "ANY_PRE_OBJ" lookups. This is only faster than JenaMapSetCommon.anyMatch(java.util.function.Predicate<E>) if there are many matches and the set is ordered in an unfavorable way. "ANY_PRE_OBJ" matches usually fall into this category. This optimization was only needed because the FastTripleBunches does not use the random order of the triples in #anyMatch but the ordered dense array of triples, which is faster if there are only a few matches. - for the FastArrayBunches, the equals method of the triple is not called. Instead, only the two nodes that are not part of the key of the containing map are compared.

  • Constructor Details

    • FastTripleStore

      public FastTripleStore()
      Creates a new, empty fast triple store.
  • Method Details

    • add

      public void add(Triple triple)
      Description copied from interface: TripleStore
      Add a triple to the store. Does nothing if the triple is already present.
      Specified by:
      add in interface TripleStore
      Parameters:
      triple - the triple to add
    • remove

      public void remove(Triple triple)
      Description copied from interface: TripleStore
      Remove a triple from the store. Does nothing if the triple is not present.
      Specified by:
      remove in interface TripleStore
      Parameters:
      triple - the triple to remove
    • clear

      public void clear()
      Description copied from interface: TripleStore
      Remove all triples from the store. After this call, TripleStore.isEmpty() returns true and any associated indices are emptied.
      Specified by:
      clear in interface TripleStore
    • countTriples

      public int countTriples()
      Description copied from interface: TripleStore
      Returns the number of triples in the store.
      Specified by:
      countTriples in interface TripleStore
      Returns:
      the number of triples
    • isEmpty

      public boolean isEmpty()
      Description copied from interface: TripleStore
      Returns true if the store contains no triples.
      Specified by:
      isEmpty in interface TripleStore
      Returns:
      true if empty
    • contains

      public boolean contains(Triple tripleMatch)
      Description copied from interface: TripleStore
      Returns true if the store contains any triple matching the given pattern. The pattern may contain wildcards (e.g. Node.ANY).
      Specified by:
      contains in interface TripleStore
      Parameters:
      tripleMatch - the triple pattern to match
      Returns:
      true if at least one matching triple exists
    • stream

      public Stream<Triple> stream()
      Description copied from interface: TripleStore
      Returns a Stream of all triples in the store. The returned stream supports BaseStream.parallel().
      Specified by:
      stream in interface TripleStore
      Returns:
      a stream over every triple in this store
    • stream

      public Stream<Triple> stream(Triple tripleMatch)
      Description copied from interface: TripleStore
      Returns a Stream of every triple in the store matching the given pattern. The returned stream supports BaseStream.parallel().
      Specified by:
      stream in interface TripleStore
      Parameters:
      tripleMatch - the triple pattern to match (may contain wildcards)
      Returns:
      a stream over the matching triples
    • find

      public ExtendedIterator<Triple> find(Triple tripleMatch)
      Description copied from interface: TripleStore
      Returns an ExtendedIterator over every triple in the store matching the given pattern.
      Specified by:
      find in interface TripleStore
      Parameters:
      tripleMatch - the triple pattern to match (may contain wildcards)
      Returns:
      an iterator over the matching triples
    • copy

      public FastTripleStore copy()
      Description copied from interface: TripleStore
      Returns an independent copy of this store. Since Nodes and Triples are immutable, the copy may share node and triple instances with the original; only the container/index data structures are duplicated so that mutations in either store do not affect the other.
      Specified by:
      copy in interface org.apache.jena.atlas.lib.Copyable<TripleStore>
      Specified by:
      copy in interface TripleStore
      Returns:
      an independent copy of this store