Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
z_algorithm_example.cc File Reference

Illustrative example for Z-algorithm pattern matching. More...

#include <iostream>
#include <string>
#include <format>
#include <String_Search.H>
Include dependency graph for z_algorithm_example.cc:

Go to the source code of this file.

Functions

template<typename Range >
void print_range (std::string_view label, const Range &r)
 Print a label followed by the elements of a range to standard output.
 
int main ()
 Example program demonstrating computation of the Z-array and pattern matches using the Z-algorithm.
 

Detailed Description

Illustrative example for Z-algorithm pattern matching.

Definition in file z_algorithm_example.cc.

Function Documentation

◆ main()

int main ( )

Example program demonstrating computation of the Z-array and pattern matches using the Z-algorithm.

Computes the Z-array for a sample text and finds all match positions of a sample pattern, then prints the text, pattern, Z-array, and match positions to standard output.

Returns
int Exit code: 0 on success.

Definition at line 72 of file z_algorithm_example.cc.

References Aleph::divide_and_conquer_partition_dp(), print_range(), Aleph::z_algorithm(), and Aleph::z_search().

◆ print_range()

template<typename Range >
void print_range ( std::string_view  label,
const Range &  r 
)

Print a label followed by the elements of a range to standard output.

Each element is formatted with std::format using the {} format specifier, separated by spaces, and the output is terminated with a newline.

Template Parameters
RangeType of the range; must be iterable.
Parameters
labelPrefix text printed before the range elements.
rThe range whose elements will be printed; element type must be formattable with std::format.
Examples
z_algorithm_example.cc.

Definition at line 56 of file z_algorithm_example.cc.

References r.

Referenced by main().