Filtering adaptors for Aleph iterators, including graph arc/node filters.
More...
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:
- Generic filtered iterators using filter_iterator.H (Aleph::Filter_Iterator)
- 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:
- The predicate type is the template parameter
Show_Item.
- The wrapper preserves the usual Aleph iterator interface (
has_curr(), get_curr(), next() / next_ne(), etc.).
- You can attach context via
set_cookie() / get_cookie() if needed.
bool operator()(
int x)
const {
return x % 2 == 0; }
};
{
for (int i = 1; i <= 10; ++i)
for (; it.has_curr(); it.next())
{
auto x = it.get_curr();
(void) x;
}
}
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.
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.
struct RoadInfo {
double distance;
bool is_highway;
};
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; }
};
{
G g;
auto * s = g.insert_node(0);
auto * t = g.insert_node(1);
g.insert_arc(s, t, RoadInfo{10.0, true});
g.insert_arc(s, t, RoadInfo{12.0, false});
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.
Graph implemented with double-linked adjacency lists.
DynList< T > maps(const C &c, Op op)
Classic map operation.
Arc of graph implemented with double-linked adjacency lists.
Distance accessor functor for Dijkstra algorithm.
double operator()(CityGraph::Arc *arc) const
Generic graph and digraph implementations.
Notes:
- The filter functor (
NoHighways) is the SA template parameter in Dijkstra_Min_Paths.
- The distance functor (
RoadDistance) defines how arc weights are read.