withOptions method

RdfGraph withOptions({
  1. bool? enableIndexing,
})

Creates a new graph with modified configuration options

This method allows you to create a copy of the graph with different configuration settings while preserving all the triples. This provides a way to adjust graph behavior without recreating the entire dataset.

If the specified options are the same as the current graph's settings, returns the same instance for efficiency.

Parameters:

  • enableIndexing Whether to enable lazy internal indexing for query optimization. When enabled, an internal index is created lazily on first query to improve performance for subsequent pattern matching operations. The index is only built when actually needed, so enabling this option has no immediate memory cost. If null, uses the current setting.

Returns: A graph instance with the specified configuration options. May return the same instance if no changes are needed.

Example:

// Enable indexing for better query performance
final optimizedGraph = graph.withOptions(enableIndexing: true);

// Disable indexing to reduce memory usage
final lightweightGraph = graph.withOptions(enableIndexing: false);

Implementation

RdfGraph withOptions({bool? enableIndexing}) {
  final effectiveIndexing = enableIndexing ?? indexingEnabled;
  if (effectiveIndexing == indexingEnabled) {
    return this;
  }
  return RdfGraph(triples: _triples, enableIndexing: effectiveIndexing);
}