Class RoaringTripleStore

java.lang.Object
org.apache.jena.mem.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. With the new indexing strategies, it also works well for very small graphs, where pattern matching is not needed.

This store supports different indexing strategies to balance RAM usage and performance for various operations. See IndexingStrategy for details on the available strategies.

Internal structure:

  • One indexed hash set (same as GraphMem2Fast uses) that holds all triples
  • The index consists of 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 bitmap 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.

  • Constructor Details

    • RoaringTripleStore

      public RoaringTripleStore()
      Create a new RoaringTripleStore with the default indexing strategy (EAGER).

      The default strategy is EAGER, because of backwards compatibility. This is not necessarily the best strategy for all use cases, but it reflects the behavior before introducing the indexing strategies.

    • RoaringTripleStore

      public RoaringTripleStore(IndexingStrategy indexingStrategy)
      Create a new RoaringTripleStore with the given indexing strategy.
      Parameters:
      indexingStrategy - the indexing strategy to use
  • Method Details

    • isIndexInitialized

      public boolean isIndexInitialized()
      Check if the index of this store is initialized. This will return true if the current strategy is EagerStoreStrategy, which means that the index has been initialized and all triples are indexed.
      Returns:
      true if the index is initialized, false otherwise
    • getIndexingStrategy

      public IndexingStrategy getIndexingStrategy()
      Get the indexing strategy of this store.
      Returns:
      the indexing strategy
    • clearIndex

      public void clearIndex()
      Clear the index of this store. This will remove all triples from the index and reset the current strategy to the initial one.
    • initializeIndex

      public void initializeIndex()
      Initialize the index for this store.
    • initializeIndexParallel

      public void initializeIndexParallel()
      Initialize the index for this store in parallel. This will index all triples in parallel, which can be faster for large datasets.
    • 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 RoaringTripleStore 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