Template Numerical Library: Overview of Segment Traversal Functions

Template Numerical Library version\ main:c7077e4fd

Loading...
Searching...
No Matches
Overview of Segment Traversal Functions

This page provides an overview of all traversal functions available for segment operations, helping to understand the differences between variants and choose the right function for your needs.

# Function Categories

Traversal functions are organized along two main dimensions:

## Element-wise vs. Segment-wise Traversal

Category | Operates On | Lambda Parameter | Use Case
--- | --- | --- | ---
Element-wise (forElements, forAllElements) | Individual elements | Element indices | Operate on each element separately
Segment-wise (forSegments, forAllSegments) | Whole segments | SegmentView object | Operate on segments as units

When to use:

- Element-wise: When you need to process each element independently (e.g., apply transformation, update values)
- Segment-wise: When you need access to the entire segment structure or segment context (e.g., custom segment algorithms, segment-level operations)

## Scope and Conditional Variants

Similar to other segment operations, traversal functions come in different scopes and conditional variants.

Scope | Segments Processed | Parameters
--- | --- | ---
All | All segments | No range/array parameters
Range | Segments [begin, end) | begin and end indices
Array | Specific segments | Array of segment indices
If | Segment condition | Process segments based on segment-level properties

# Element-wise Traversal Functions

These functions iterate over individual elements within segments:

## Basic Element Traversal

Function | Segments Processed | Description
--- | --- | ---
forAllElements | All segments | Process all elements in all segments
forElements (range) | Segments [begin, end) | Process elements in segment range
forElements (array) | Segments in array | Process elements in specified segments
forAllElementsIf | All segments | Segment-level condition
forElementsIf | Segments [begin, end) | Segment-level condition

# Segment-wise Traversal Functions

These functions iterate over segments as whole units:

## Basic Segment Traversal

Function | Segments Processed | Description
--- | --- | ---
forAllSegments | All segments | Process all segments
forSegments (range) | Segments [begin, end) | Process segments in range
forSegments (array) | Segments in array | Process specified segments
forAllSegmentsIf | All segments | Segment-level condition
forSegmentsIf | Segments [begin, end) | Segment-level condition

# Common Parameters

All traversal functions share these common parameters:

- segments: The segments container to traverse
- f: Lambda function to apply (see Full Form (With All Parameters), Brief Form (Without Local Index), or Segment View Lambda)
- launchConfig: Configuration for parallel execution (optional)

Additional parameters for specific variants:

- Scope variants: begin, end (range) or segmentIndexes (array)
- If variants: condition lambda for filtering (see Condition Check)

# Related Pages

- Segment Traversal Lambda Function Reference - Detailed lambda function signatures
- TNL::Algorithms::Segments::SegmentView - Segment view documentation