Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
Iterator Filters

Filtering adaptors for Aleph iterators, including graph arc/node filters. More...

Files

file  filter_iterator.H
 Generic filter iterator wrapper for Aleph containers.
 

Detailed Description

Filtering adaptors for Aleph iterators, including graph arc/node filters.

This module documents iterator-level filtering in Aleph-w.

Aleph-w provides filtering in two complementary ways:

  1. Generic filtered iterators using filter_iterator.H (Aleph::Filter_Iterator)
  2. Graph-specific filtered iterators (nodes/arcs) in tpl_graph.H, built on top of Aleph::Filter_Iterator

1) Generic <tt>Filter_Iterator</tt>

Aleph::Filter_Iterator wraps an Aleph iterator and hides elements that do not satisfy a predicate.

Key points:

#include <tpl_dynDlist.H>
using namespace Aleph;
struct ShowEven {
bool operator()(int x) const { return x % 2 == 0; }
};
int main()
{
for (int i = 1; i <= 10; ++i)
xs.append(i);
for (; it.has_curr(); it.next())
{
auto x = it.get_curr();
(void) x;
}
}
int main()
Iterator dynamic list.
Dynamic doubly linked list with O(1) size and bidirectional access.
T & append(const T &item)
Append a copied item at the end of the list.
Generic filter iterator wrapper.
Generic filter iterator wrapper for Aleph containers.
Main namespace for Aleph-w library functions.
Definition ah-arena.H:89
bool operator()(int x) const
Dynamic doubly linked list implementation.

2) Graph arc/node filters (practical example)

Graph traversal in Aleph-w often exposes a filter hook via a functor parameter (commonly called Show_Arc or Show_Node). This is used throughout tpl_graph.H and shortest-path algorithms like Dijkstra.H.

Example: exclude "highways" from shortest-path

If your arc payload indicates whether an arc represents a highway, you can provide a Show_Arc filter so that Dijkstra ignores those arcs.

#include <tpl_graph.H>
#include <Dijkstra.H>
using namespace Aleph;
struct RoadInfo {
double distance;
bool is_highway;
};
struct RoadDistance {
double operator()(G::Arc * a) const noexcept { return a->get_info().distance; }
};
struct NoHighways {
bool operator()(G::Arc * a) const noexcept { return !a->get_info().is_highway; }
};
int main()
{
G g;
auto * s = g.insert_node(0);
auto * t = g.insert_node(1);
g.insert_arc(s, t, RoadInfo{10.0, true}); // highway
g.insert_arc(s, t, RoadInfo{12.0, false}); // regular road
Path<G> path(g);
auto d = dij(g, s, t, path);
(void) d;
}
Dijkstra's shortest path algorithm.
Spanning tree calculation of all shortest paths from a given node according to Dijkstra's algorithm.
Definition Dijkstra.H:101
Graph implemented with double-linked adjacency lists.
Definition tpl_graph.H:428
Path on a graph.
Definition tpl_graph.H:2669
DynList< T > maps(const C &c, Op op)
Classic map operation.
Arc of graph implemented with double-linked adjacency lists.
Definition tpl_graph.H:222
Distance accessor functor for Dijkstra algorithm.
double operator()(CityGraph::Arc *arc) const
Generic graph and digraph implementations.

Notes: