ACAV 69797fb42a2b
Abstract Syntax Tree (AST) visualization tool for C, C++, and Objective-C
Loading...
Searching...
No Matches
acav::IntervalTree Class Reference

Static interval index for source-location queries. More...

#include <SourceLocationIndex.h>

Public Member Functions

 IntervalTree (const IntervalTree &)=delete
IntervalTree & operator= (const IntervalTree &)=delete
void insert (Interval interval)
 Add interval to collection (not sorted yet).
void finalize ()
 Sort intervals by start position (call once after all inserts).
std::vector< AstViewNode * > query (unsigned line, unsigned column) const
 Find all intervals containing a point.
AstViewNodequeryFirstContained (unsigned beginLine, unsigned beginColumn, unsigned endLine, unsigned endColumn) const
 Find first interval fully contained within a range.
std::size_t size () const
 Get total number of intervals.

Detailed Description

Static interval index for source-location queries.

Stores source ranges in a sorted vector for range-selection queries and builds a centered interval tree for point queries.

Complexity:

  • Insert: O(1) amortized (vector push_back)
  • Finalize: O(n log n) (one-time sort and interval-tree build)
  • Point query: O(log n + k) before result-depth ordering, where k is the number of matches

Definition at line 65 of file SourceLocationIndex.h.

Member Function Documentation

◆ finalize()

void acav::IntervalTree::finalize ( )

Sort intervals by start position (call once after all inserts).

Definition at line 96 of file SourceLocationIndex.cpp.

◆ insert()

void acav::IntervalTree::insert ( Interval interval)

Add interval to collection (not sorted yet).

Parameters
intervalThe source range and associated node

Definition at line 92 of file SourceLocationIndex.cpp.

◆ query()

std::vector< AstViewNode * > acav::IntervalTree::query ( unsigned line,
unsigned column ) const

Find all intervals containing a point.

Parameters
lineSource line number (1-based)
columnSource column number (1-based)
Returns
Vector of nodes sorted by depth (deepest first)

Definition at line 107 of file SourceLocationIndex.cpp.

◆ queryFirstContained()

AstViewNode * acav::IntervalTree::queryFirstContained ( unsigned beginLine,
unsigned beginColumn,
unsigned endLine,
unsigned endColumn ) const

Find first interval fully contained within a range.

Parameters
beginLineRange start line (1-based)
beginColumnRange start column (1-based)
endLineRange end line (1-based)
endColumnRange end column (1-based)
Returns
First node whose interval is inside the range, or nullptr

Definition at line 190 of file SourceLocationIndex.cpp.

◆ size()

std::size_t acav::IntervalTree::size ( ) const
inline

Get total number of intervals.

Definition at line 97 of file SourceLocationIndex.h.


The documentation for this class was generated from the following files: