|
Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
|
Generic filter iterator wrapper. More...
#include <filter_iterator.H>
Public Types | |
| using | Item_Type = typename It::Item_Type |
| The type of element returned by get_curr() | |
| using | Iterator_Type = It |
| The type of the base iterator. | |
| using | Container_Type = Container |
| The type of container being iterated. | |
| using | Filter_Type = Show_Item |
| The type of the filter functor. | |
Public Member Functions | |
| const Container & | get_container () const |
| Returns a const reference to the container being iterated over. | |
| bool | has_container () const noexcept |
| Check if a container has been set. | |
| It & | get_iterator () noexcept |
| Returns a reference to the underlying base iterator. | |
| const It & | get_iterator () const noexcept |
| Returns a const reference to the underlying base iterator. | |
| Show_Item & | get_filter () noexcept |
| Returns a reference to the filter functor. | |
| const Show_Item & | get_filter () const noexcept |
| Returns a const reference to the filter functor. | |
| void | set_filter (Show_Item si) |
| Sets a new filter functor. | |
| void | set_cookie (void *__cookie) noexcept |
| Sets the cookie pointer. | |
| void * | get_cookie () const noexcept |
| Gets the cookie pointer. | |
| Filter_Iterator (Show_Item si=Show_Item()) noexcept | |
| Default constructor. | |
| Filter_Iterator (const Container &c, Show_Item si=Show_Item()) | |
| Constructs a filter iterator over a container. | |
| Filter_Iterator (const Container &c, void *__cookie, Show_Item si=Show_Item()) | |
| Constructs a filter iterator with a cookie. | |
| void | next () |
| Advances the iterator to the next filtered element. | |
| void | next_ne () noexcept |
| Advances the iterator to the next filtered element (noexcept version). | |
| void | prev () |
| Moves the iterator backward to the previous filtered element. | |
| void | prev_ne () noexcept |
| Moves the iterator backward (noexcept version). | |
| void | reset_first () |
| Resets the iterator to the first filtered element. | |
| void | reset_last () |
| Resets the iterator to the last filtered element. | |
| size_t | count () |
| Count the number of elements that pass the filter. | |
| bool | empty () |
| Check if there are no elements that pass the filter. | |
| template<typename Op > | |
| void | for_each (Op op) |
| Apply a function to all filtered elements. | |
| template<typename Pred > | |
| bool | find_if (Pred pred) |
| Find the first element that satisfies an additional predicate. | |
Private Member Functions | |
| void | goto_first_valid_item () |
| Advance to the first element that passes the filter. | |
| void | forward () |
| Move forward to the next element that passes the filter. | |
| void | goto_last_valid_item () |
| Move to the last element that passes the filter. | |
| void | backward () |
| Move backward to the previous element that passes the filter. | |
Private Attributes | |
| Show_Item | show_item |
| const Container * | container_ptr = nullptr |
| void * | cookie = nullptr |
| User-defined pointer for extensibility (e.g., passing context data to filter) | |
Generic filter iterator wrapper.
Filter_Iterator wraps an existing iterator and filters elements based on a user-defined predicate. Only elements that satisfy the filter predicate are visible during iteration.
This class is parameterized by the following types:
Show_Item::operator()(Item_Type) which must return true if the element should be shown, or false otherwise.The purpose of Filter_Iterator is to provide a generic iterator that filters elements according to a criterion defined by the Show_Item class. This allows generic algorithms using Filter_Iterator to have different behaviors depending on the Show_Item filter.
Aleph containers export two important types in the context of Filter_Iterator: Set_Type and Item_Type, which correspond to the type of container being iterated over and the type of element returned by the iterator It, respectively.
Usage example:
| Container | The container type being iterated over. Must be an Aleph container type that supports iteration. |
| It | The base iterator type for the container. Should be one of the iterator classes provided by Container. |
| Show_Item | A functor class that determines element visibility. Must provide: bool operator()(const Item_Type&) that returns true if the item should be shown, false otherwise. |
std::overflow_error and std::underflow_error internally to handle boundary conditions gracefully. Other exceptions from the filter functor will propagate to the caller.Definition at line 123 of file filter_iterator.H.
| using Aleph::Filter_Iterator< Container, It, Show_Item >::Container_Type = Container |
The type of container being iterated.
Definition at line 225 of file filter_iterator.H.
| using Aleph::Filter_Iterator< Container, It, Show_Item >::Filter_Type = Show_Item |
The type of the filter functor.
Definition at line 228 of file filter_iterator.H.
| using Aleph::Filter_Iterator< Container, It, Show_Item >::Item_Type = typename It::Item_Type |
The type of element returned by get_curr()
Definition at line 219 of file filter_iterator.H.
| using Aleph::Filter_Iterator< Container, It, Show_Item >::Iterator_Type = It |
The type of the base iterator.
Definition at line 222 of file filter_iterator.H.
|
inlinenoexcept |
Default constructor.
Creates a filter iterator with only a filter functor. The container must be set later by copy/assignment from another iterator that has a container.
| si | The filter functor to use (default constructed if not provided). |
Definition at line 314 of file filter_iterator.H.
|
inline |
Constructs a filter iterator over a container.
The iterator is automatically positioned at the first element that passes the filter predicate.
| c | The container to iterate over. |
| si | The filter functor to use (default constructed if not provided). |
| std::bad_alloc | if there is not enough memory. |
Definition at line 329 of file filter_iterator.H.
References Aleph::Filter_Iterator< Container, It, Show_Item >::goto_first_valid_item().
|
inline |
Constructs a filter iterator with a cookie.
The cookie is a user-defined pointer that can be used to attach arbitrary data to the iterator for extensibility purposes.
| c | The container to iterate over. |
| __cookie | User-defined pointer for extensibility. |
| si | The filter functor to use (default constructed if not provided). |
| std::bad_alloc | if there is not enough memory. |
Definition at line 345 of file filter_iterator.H.
References Aleph::Filter_Iterator< Container, It, Show_Item >::cookie, and Aleph::maps().
|
inlineprivate |
Move backward to the previous element that passes the filter.
First moves back past the current element, then continues moving backward until finding an element that satisfies the filter predicate, or until reaching the beginning of the sequence.
Catches std::underflow_error internally to handle beginning-of-sequence gracefully without propagating the exception.
Definition at line 205 of file filter_iterator.H.
References Aleph::maps(), and Aleph::Filter_Iterator< Container, It, Show_Item >::show_item.
Referenced by Aleph::Filter_Iterator< Container, It, Show_Item >::prev(), and Aleph::Filter_Iterator< Container, It, Show_Item >::prev_ne().
|
inline |
Count the number of elements that pass the filter.
Iterates through the entire sequence and counts elements that satisfy the filter predicate. This is a destructive operation that modifies the iterator position.
Definition at line 426 of file filter_iterator.H.
References Aleph::has_curr(), Aleph::Filter_Iterator< Container, It, Show_Item >::next(), and Aleph::Filter_Iterator< Container, It, Show_Item >::reset_first().
|
inline |
Check if there are no elements that pass the filter.
Resets the iterator to the first position and checks if any element passes the filter.
Definition at line 443 of file filter_iterator.H.
References Aleph::has_curr(), Aleph::maps(), and Aleph::Filter_Iterator< Container, It, Show_Item >::reset_first().
Referenced by TEST().
|
inline |
Find the first element that satisfies an additional predicate.
Searches through filtered elements until finding one that also satisfies the given predicate.
| Pred | A callable type that accepts Item_Type and returns bool. |
| pred | The additional predicate to check. |
Definition at line 482 of file filter_iterator.H.
References Aleph::get_curr(), Aleph::has_curr(), Aleph::Filter_Iterator< Container, It, Show_Item >::next(), pred, and Aleph::Filter_Iterator< Container, It, Show_Item >::reset_first().
|
inline |
Apply a function to all filtered elements.
Iterates through all elements that pass the filter and applies the given operation to each one.
| Op | A callable type that accepts Item_Type. |
| op | The operation to apply to each filtered element. |
Definition at line 464 of file filter_iterator.H.
References Aleph::get_curr(), Aleph::has_curr(), Aleph::Filter_Iterator< Container, It, Show_Item >::next(), and Aleph::Filter_Iterator< Container, It, Show_Item >::reset_first().
|
inlineprivate |
Move forward to the next element that passes the filter.
First advances past the current element, then continues advancing until finding an element that satisfies the filter predicate, or until reaching the end of the sequence.
Catches std::overflow_error internally to handle end-of-sequence gracefully without propagating the exception.
Definition at line 164 of file filter_iterator.H.
References Aleph::maps(), and Aleph::Filter_Iterator< Container, It, Show_Item >::show_item.
Referenced by Aleph::Filter_Iterator< Container, It, Show_Item >::next(), and Aleph::Filter_Iterator< Container, It, Show_Item >::next_ne().
|
inline |
Returns a const reference to the container being iterated over.
| std::domain_error | if the iterator was default-constructed without a container. |
Definition at line 236 of file filter_iterator.H.
References ah_domain_error_if, and Aleph::Filter_Iterator< Container, It, Show_Item >::container_ptr.
|
inlinenoexcept |
Gets the cookie pointer.
Definition at line 301 of file filter_iterator.H.
References Aleph::Filter_Iterator< Container, It, Show_Item >::cookie.
|
inlinenoexcept |
Returns a const reference to the filter functor.
Definition at line 276 of file filter_iterator.H.
References Aleph::Filter_Iterator< Container, It, Show_Item >::show_item.
|
inlinenoexcept |
Returns a reference to the filter functor.
Use this function if you need to access or modify the filter state. Note that the filter object will be destroyed when the ~Filter_Iterator() destructor is called.
Definition at line 270 of file filter_iterator.H.
References Aleph::Filter_Iterator< Container, It, Show_Item >::show_item.
Referenced by TEST().
|
inlinenoexcept |
Returns a const reference to the underlying base iterator.
Definition at line 260 of file filter_iterator.H.
|
inlinenoexcept |
Returns a reference to the underlying base iterator.
This provides access to the base iterator functionality if needed.
Definition at line 254 of file filter_iterator.H.
Referenced by TEST().
|
inlineprivate |
Advance to the first element that passes the filter.
Starting from the current position, advances the iterator until finding an element that satisfies the filter predicate, or until reaching the end of the sequence.
Catches std::overflow_error internally to handle end-of-sequence gracefully without propagating the exception.
Definition at line 141 of file filter_iterator.H.
References Aleph::maps(), and Aleph::Filter_Iterator< Container, It, Show_Item >::show_item.
Referenced by Aleph::Filter_Iterator< Container, It, Show_Item >::Filter_Iterator(), and Aleph::Filter_Iterator< Container, It, Show_Item >::reset_first().
|
inlineprivate |
Move to the last element that passes the filter.
Positions the iterator at the end, then moves backward until finding an element that satisfies the filter predicate, or until reaching the beginning of the sequence.
Catches std::underflow_error internally to handle beginning-of-sequence gracefully without propagating the exception.
Definition at line 185 of file filter_iterator.H.
References Aleph::maps(), and Aleph::Filter_Iterator< Container, It, Show_Item >::show_item.
Referenced by Aleph::Filter_Iterator< Container, It, Show_Item >::reset_last().
|
inlinenoexcept |
Check if a container has been set.
Definition at line 246 of file filter_iterator.H.
References Aleph::Filter_Iterator< Container, It, Show_Item >::container_ptr.
|
inline |
Advances the iterator to the next filtered element.
Moves forward in the sequence, skipping elements that don't pass the filter, until reaching the next visible element or the end.
Definition at line 357 of file filter_iterator.H.
References Aleph::Filter_Iterator< Container, It, Show_Item >::forward().
Referenced by JohnsonTest::computeFloydWarshall(), Aleph::Filter_Iterator< Container, It, Show_Item >::count(), Aleph::Filter_Iterator< Container, It, Show_Item >::find_if(), Aleph::Filter_Iterator< Container, It, Show_Item >::for_each(), RandomNetworkTest::is_valid_network(), main(), Aleph::Digraph_Iterator< GT, Filter >::next(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), and Aleph::vertex_connectivity().
|
inlinenoexcept |
Advances the iterator to the next filtered element (noexcept version).
This is the exception-safe version of next(). All exceptions are silently caught and the iterator remains in a valid state.
Definition at line 366 of file filter_iterator.H.
References Aleph::Filter_Iterator< Container, It, Show_Item >::forward().
Referenced by Aleph::Depth_First_Traversal< GT, Operation, SA >::__dft(), Aleph::__graph_to_tree_node(), Aleph::Test_Eulerian< GT, SN, SA >::analyze_digraph(), Aleph::Test_Eulerian< GT, SN, SA >::analyze_graph(), Aleph::arcs(), Aleph::Test_Hamiltonian_Sufficiency< GT, SN, SA >::are_adjacent(), Aleph::Breadth_First_Traversal< GT, Operation, SA >::bft(), Aleph::IndexArc< GT, Tree, SA >::build_index(), Aleph::IndexNode< GT, Compare, Tree, SN >::build_index(), Aleph::Karger_Min_Cut< GT, SA >::build_kgraph(), Aleph::build_level_graph(), Aleph::Network_Simplex< Net >::build_spanning_tree(), Aleph::Build_Subgraph< GT, SA >::build_subgraph(), Aleph::Find_Breadth_First_Spanning_Tree< GT, SA >::build_tree(), Aleph::capacity_scaling_maximum_flow(), Aleph::compute_bipartite(), Aleph::compute_bipartite_all_components(), Aleph::compute_flow_statistics(), Aleph::compute_maximum_cardinality_bipartite_matching(), Aleph::compute_min_cut(), Aleph::Matrix_Graph< GT, SA >::copy(), Aleph::Copy_Graph< GT, SN, SA >::copy(), Aleph::Compute_Cut_Nodes< GT, SA >::cut_nodes(), Aleph::decompose_flow(), Aleph::digraph_graphviz(), Aleph::dinic_maximum_flow(), Aleph::edge_connectivity(), Aleph::export_network_to_dimacs(), Aleph::export_network_to_dot(), Aleph::export_network_to_json(), Aleph::Test_Dirac_Condition< GT, SN, SA >::find_min_degree_vertex(), Aleph::Find_Eulerian_Path< GT, SN, SA >::find_start_vertex(), Aleph::for_each_arc(), Aleph::for_each_arc(), Aleph::for_each_node(), Aleph::forall_arc(), Aleph::forall_arc(), Aleph::forall_node(), Aleph::generate_dot_file(), Aleph::generate_graphpic(), Aleph::generate_graphviz(), Aleph::generate_graphviz(), Aleph::Graph_To_Tree_Node< GT, Key, Convert, SA >::graph_to_tree(), Aleph::Test_Hamiltonian_Sufficiency< GT, SN, SA >::has_arc(), Aleph::Find_Eulerian_Path< GT, SN, SA >::hierholzer_directed(), Aleph::Find_Eulerian_Path< GT, SN, SA >::hierholzer_undirected(), Aleph::hlpp_maximum_flow(), Aleph::hopcroft_karp_dfs(), Aleph::hopcroft_karp_matching(), Aleph::Nodes_Index< GT, Compare, Tree, SN >::init(), Aleph::Arcs_Index< GT, Compare, Tree, SA >::init(), Aleph::IndexArc< GT, Tree, SA >::init(), Aleph::IndexNode< GT, Compare, Tree, SN >::init(), Aleph::Stoer_Wagner_Min_Cut< GT, Distance, SA >::init_from_graph(), Aleph::Is_Graph_Acyclique< GT, SA >::is_acyclique(), Aleph::Test_Eulerian< GT, SN, SA >::is_connected(), Aleph::Test_Eulerian< GT, SN, SA >::is_strongly_connected(), is_valid_topological_order(), Aleph::Compute_Cut_Nodes< GT, SA >::map_cut_graph(), Aleph::Compute_Cut_Nodes< GT, SA >::map_subgraph(), Aleph::min_cut(), Aleph::Prim_Min_Spanning_Tree< GT, Distance, SA >::min_spanning_tree(), Aleph::network_to_dot_string(), Aleph::network_to_json_string(), Aleph::Digraph_Iterator< GT, Filter >::next_ne(), Aleph::Ady_Mat< GT, __Entry_Type, SA >::operate_all_arcs_list_graph(), Aleph::Ady_Mat< GT, __Entry_Type, SA >::operate_all_arcs_list_graph(), Aleph::Invert_Digraph< GT, SA >::operator()(), Aleph::Operate_On_Nodes< GT, Operation, SN >::operator()(), Aleph::Operate_On_Arcs< GT, Operation, SA >::operator()(), Aleph::Operate_On_Arcs< GT, Operation, SA >::operator()(), Aleph::Test_Single_Graph< GT, SN, SA >::operator()(), Aleph::Stoer_Wagner_Min_Cut< GT, Distance, SA >::operator()(), Aleph::Operate_On_Nodes< GT, Operation, SN >::operator()(), Aleph::Operate_On_Arcs< GT, Operation, SA >::operator()(), Aleph::Operate_On_Arcs< GT, Operation, SA >::operator()(), Aleph::Compute_Cut_Nodes< GT, SA >::paint_from_cut_node(), Aleph::Kruskal_Min_Spanning_Tree< GT, Distance, SA >::paint_min_spanning_tree(), Aleph::Prim_Min_Spanning_Tree< GT, Distance, SA >::paint_min_spanning_tree(), Aleph::Compute_Cut_Nodes< GT, SA >::paint_subgraph(), Aleph::Q_Topological_Sort< GT, Itor, SA >::perform(), Aleph::rank_graphviz(), Aleph::restore_flow_solution(), Aleph::IO_Graph< GT, Load_Node, Store_Node, Load_Arc, Store_Arc, NF, AF >::save(), Aleph::save_flow_solution(), Aleph::IO_Graph< GT, Load_Node, Store_Node, Load_Arc, Store_Arc, NF, AF >::save_in_text_mode(), Aleph::search_directed_arc(), Aleph::search_spanning_tree_arc(), Aleph::solve_circulation(), Aleph::solve_transshipment(), Aleph::ssp_init_potentials(), Aleph::ssp_shortest_path(), Aleph::successive_shortest_paths(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), Aleph::Test_For_Cycle< GT, SA >::test_cycle(), Aleph::Test_For_Cycle< GT, SA >::test_cycle(), Aleph::Test_Eulerian< GT, SN, SA >::test_degree_only(), Aleph::Test_Hamiltonian_Sufficiency< GT, SN, SA >::test_digraph(), Aleph::Test_Dirac_Condition< GT, SN, SA >::test_digraph(), TEST_F(), TEST_F(), Aleph::Test_Hamiltonian_Sufficiency< GT, SN, SA >::test_graph(), Aleph::Test_Dirac_Condition< GT, SN, SA >::test_graph(), Aleph::Test_Single_Graph< GT, SN, SA >::test_node(), Aleph::Test_For_Path< GT, SA >::test_path(), Aleph::Test_For_Path< GT, SA >::test_path(), verify_bipartition(), verify_flow_conservation(), and Aleph::vertex_connectivity().
|
inline |
Moves the iterator backward to the previous filtered element.
Moves backward in the sequence, skipping elements that don't pass the filter, until reaching the previous visible element or the beginning.
Definition at line 380 of file filter_iterator.H.
References Aleph::Filter_Iterator< Container, It, Show_Item >::backward().
Referenced by Aleph::Digraph_Iterator< GT, Filter >::prev(), TEST(), TEST(), TEST(), TEST(), and TEST().
|
inlinenoexcept |
Moves the iterator backward (noexcept version).
This is the exception-safe version of prev(). All exceptions are silently caught and the iterator remains in a valid state.
Definition at line 389 of file filter_iterator.H.
References Aleph::Filter_Iterator< Container, It, Show_Item >::backward().
Referenced by TEST().
|
inline |
Resets the iterator to the first filtered element.
Positions the iterator at the first element in the sequence that passes the filter predicate.
Definition at line 403 of file filter_iterator.H.
References Aleph::Filter_Iterator< Container, It, Show_Item >::goto_first_valid_item().
Referenced by Aleph::Filter_Iterator< Container, It, Show_Item >::count(), Aleph::Filter_Iterator< Container, It, Show_Item >::empty(), Aleph::Filter_Iterator< Container, It, Show_Item >::find_if(), Aleph::Filter_Iterator< Container, It, Show_Item >::for_each(), Aleph::Digraph_Iterator< GT, Filter >::reset_first(), TEST(), TEST(), and TEST().
|
inline |
Resets the iterator to the last filtered element.
Positions the iterator at the last element in the sequence that passes the filter predicate.
Definition at line 414 of file filter_iterator.H.
References Aleph::Filter_Iterator< Container, It, Show_Item >::goto_last_valid_item().
Referenced by Aleph::Digraph_Iterator< GT, Filter >::reset_last(), TEST(), TEST(), TEST(), TEST(), and TEST().
|
inlinenoexcept |
Sets the cookie pointer.
The cookie is a user-defined pointer for extensibility purposes, such as passing context data to the filter functor.
| __cookie | The new cookie value. |
Definition at line 295 of file filter_iterator.H.
References Aleph::Filter_Iterator< Container, It, Show_Item >::cookie, and Aleph::maps().
|
inline |
Sets a new filter functor.
This allows changing the filtering criterion after construction. After setting a new filter, you should call reset_first() or reset_last() to reposition the iterator according to the new filter.
| si | The new filter functor to use. |
Definition at line 286 of file filter_iterator.H.
References Aleph::maps(), and Aleph::Filter_Iterator< Container, It, Show_Item >::show_item.
Referenced by TEST().
|
private |
Definition at line 127 of file filter_iterator.H.
Referenced by Aleph::Filter_Iterator< Container, It, Show_Item >::get_container(), and Aleph::Filter_Iterator< Container, It, Show_Item >::has_container().
|
private |
User-defined pointer for extensibility (e.g., passing context data to filter)
Definition at line 130 of file filter_iterator.H.
Referenced by Aleph::Filter_Iterator< Container, It, Show_Item >::Filter_Iterator(), Aleph::Filter_Iterator< Container, It, Show_Item >::get_cookie(), and Aleph::Filter_Iterator< Container, It, Show_Item >::set_cookie().
|
private |
Definition at line 125 of file filter_iterator.H.
Referenced by Aleph::Filter_Iterator< Container, It, Show_Item >::backward(), Aleph::Filter_Iterator< Container, It, Show_Item >::forward(), Aleph::Filter_Iterator< Container, It, Show_Item >::get_filter(), Aleph::Filter_Iterator< Container, It, Show_Item >::get_filter(), Aleph::Filter_Iterator< Container, It, Show_Item >::goto_first_valid_item(), Aleph::Filter_Iterator< Container, It, Show_Item >::goto_last_valid_item(), and Aleph::Filter_Iterator< Container, It, Show_Item >::set_filter().