Class GraphMemIndexedSet

All Implemented Interfaces:
org.apache.jena.atlas.lib.Copyable<GraphMem>, Graph, GraphWithPerform

public class GraphMemIndexedSet extends GraphMem
In-memory GraphMem implementation that stores all triples in a single indexed set (IndexedSetTripleStore). This class is not thread-safe.

Different indexing strategies can be selected to balance memory usage and lookup performance. The triples themselves always live in a flat set; only the auxiliary subject/predicate/object indices are controlled by the strategy. See IndexingStrategy for the trade-offs of each variant.

While the index has not been built (e.g. with IndexingStrategy.LAZY, IndexingStrategy.LAZY_PARALLEL, IndexingStrategy.MANUAL or IndexingStrategy.MINIMAL) the memory footprint is very low and the following operations are particularly fast:

A typical bulk-load pattern is to start without an index, add all triples and then call initializeIndexParallel() to build the index in parallel.
  • Constructor Details

    • GraphMemIndexedSet

      public GraphMemIndexedSet()
      Creates a new graph using the IndexingStrategy.EAGER default indexing strategy.
    • GraphMemIndexedSet

      public GraphMemIndexedSet(IndexingStrategy indexingStrategy)
      Creates a new graph that uses the given indexing strategy.
      Parameters:
      indexingStrategy - the indexing strategy to use; controls when the subject/predicate/object index is built and how pattern lookups are evaluated
  • Method Details

    • copy

      public GraphMemIndexedSet copy()
      Creates a copy of this graph. Since the triples and nodes are immutable, the copy contains the same triples and nodes as this graph. Modifications to the copy will not affect this graph.

      Returns an independent copy that preserves the indexing strategy and, if the source has its index built, copies the index data structures directly to avoid rebuilding them.

      Specified by:
      copy in interface org.apache.jena.atlas.lib.Copyable<GraphMem>
      Overrides:
      copy in class GraphMem
      Returns:
      independent copy of the current graph
    • getIndexingStrategy

      public IndexingStrategy getIndexingStrategy()
      Returns the indexing strategy this graph was created with. The strategy is fixed for the lifetime of the graph; clearing or initializing the index does not change it.
      Returns:
      the indexing strategy
    • resetIndexingStrategy

      public void resetIndexingStrategy()
      Drops the current subject/predicate/object index and reverts to the initial strategy. Subsequent pattern lookups will trigger (re)building the index according to the configured IndexingStrategy.
    • initializeIndex

      public void initializeIndex()
      Build (or rebuild) the index sequentially. After this call, pattern lookups will be served by the eager strategy regardless of the originally configured indexing strategy.
    • initializeIndexParallel

      public void initializeIndexParallel()
      Build (or rebuild) the index in parallel. This can be substantially faster than initializeIndex() for larger graphs. After this call, pattern lookups will be served by the eager strategy regardless of the originally configured indexing strategy.
    • isIndexInitialized

      public boolean isIndexInitialized()
      Reports whether the index is currently built and ready to serve pattern lookups directly. For graphs configured with a non-eager strategy this may flip from false to true as soon as the first lookup is performed (or when initializeIndex() is called explicitly).
      Returns:
      true iff the index is initialized