subjects property

Set<RdfSubject> get subjects

Get all unique subjects in this graph

Returns a set containing all subject resources that appear as the subject component of any triple in this graph. The result is computed efficiently using the internal index if available and indexing is enabled.

Performance: If indexing is enabled, the first call to this method may trigger lazy creation of the internal index. Subsequent calls will use the cached index for O(1) performance.

Returns: An unmodifiable set of all subjects in the graph. The set may be empty if the graph contains no triples.

Example:

// Find all resources that are subjects of statements
final allSubjects = graph.subjects;
print('Graph contains information about ${allSubjects.length} resources');

Implementation

Set<RdfSubject> get subjects => switch (_effectiveIndex) {
      null => _triples.map((triple) => triple.subject).toSet(),
      final index => index.keys.toSet(),
    };