Class RoaringTripleStore

java.lang.Object
org.apache.jena.mem2.store.roaring.RoaringTripleStore
All Implemented Interfaces:
org.apache.jena.atlas.lib.Copyable<TripleStore>, TripleStore

public class RoaringTripleStore extends Object implements TripleStore
A triple store that is ideal for handling extremely large graphs.

Internal structure: - One indexed hash set (same as GraphMem2Fast uses) that holds all triples - Three hash maps indexed by subjects, predicates, and objects with RoaringBitmaps as values - The bitmaps contain the indices of the triples in the central hash set

The bitmaps are used to quickly find triples that match a given pattern. The bitmaps operations like FastAggregation.naive_and(RoaringBitmap...) and RoaringBitmap.intersects(RoaringBitmap, RoaringBitmap) are used to find matches for the pattern S_O, SP_, and _PO pretty fast, even in large graphs.

Additional optimizations: - because we know that if a triple exists in one of the maps, it also exists in the other two, we can use the JenaMapSetCommon.removeUnchecked(java.lang.Object) method to avoid unnecessary checks.

  • Constructor Details

    • RoaringTripleStore

      public RoaringTripleStore()
  • Method Details

    • add

      public void add(Triple triple)
      Description copied from interface: TripleStore
      Add a triple to the map.
      Specified by:
      add in interface TripleStore
      Parameters:
      triple - to add
    • remove

      public void remove(Triple triple)
      Description copied from interface: TripleStore
      Remove a triple from the map.
      Specified by:
      remove in interface TripleStore
      Parameters:
      triple - to remove
    • clear

      public void clear()
      Description copied from interface: TripleStore
      Remove all triples from the map.
      Specified by:
      clear in interface TripleStore
    • countTriples

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

      public boolean isEmpty()
      Description copied from interface: TripleStore
      Return true if the map is empty.
      Specified by:
      isEmpty in interface TripleStore
    • contains

      public boolean contains(Triple tripleMatch)
      Description copied from interface: TripleStore
      Answer true if the graph contains any triple matching t.
      Specified by:
      contains in interface TripleStore
      Parameters:
      tripleMatch - triple match pattern, which may be contained
    • stream

      public Stream<Triple> stream()
      Description copied from interface: TripleStore
      Returns a Stream of all triples in the graph. Note: BaseStream.parallel() is supported.
      Specified by:
      stream in interface TripleStore
      Returns:
      a stream of triples in this graph.
    • stream

      public Stream<Triple> stream(Triple tripleMatch)
      Description copied from interface: TripleStore
      Returns a Stream of Triples matching the given pattern. Note: BaseStream.parallel() is supported.
      Specified by:
      stream in interface TripleStore
      Parameters:
      tripleMatch - triple match pattern
      Returns:
      a stream of triples in this graph matching the pattern.
    • find

      public ExtendedIterator<Triple> find(Triple tripleMatch)
      Description copied from interface: TripleStore
      Returns an ExtendedIterator of all triples in the graph matching the given triple match.
      Specified by:
      find in interface TripleStore
    • copy

      public RoaringTripleStore copy()
      Description copied from interface: TripleStore
      Return a new triple store that is a copy of this one. Since Nodes and Triples are immutable and shared, the copy can share the same Nodes and Triples.
      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