54 using namespace Aleph;
60 template <
typename Node_Info = Empty_Class>
144 const auto new_array =
static_cast<void **
>(realloc(
arc_array, new_size *
sizeof(
void *)));
145 if (new_array ==
nullptr)
158 if (this->
num_arcs > contract_threshold)
198 for (
size_t i = 0; i < this->
num_arcs; ++i)
210 bool removed =
false;
211 for (
size_t i = 0; i < this->
num_arcs; ++i)
231 template <
typename Arc_Info = Empty_Class>
266 :
Base(src, tgt, data)
272 :
Base(src, tgt,
std::move(data))
279 template <
class __Graph_Node = Graph_Anode<
unsigned long>,
280 class __Graph_Arc = Graph_Aarc<
unsigned long>>
282 :
public GraphCommon<Array_Graph<__Graph_Node, __Graph_Arc>,
283 __Graph_Node, __Graph_Arc>
292 __Graph_Node, __Graph_Arc>;
295 __Graph_Node, __Graph_Arc>;
374 :
arcs(src->arc_array),
num_arcs(
static_cast<long>(src->num_arcs)),
406 <<
"Array_Iterator::get_curr(): no current item";
408 <<
"Array_Iterator::get_curr(): no current item";
429 <<
"Array_Iterator::next(): no current item";
444 <<
"Array_Iterator::prev(): no current item";
496 assert(p !=
nullptr);
497 assert(p->num_arcs == 0);
516 it.get_curr()->compress();
522 Arc *aptr =
static_cast<Arc *
>(a);
526 src->insert_arc(aptr);
532 tgt->insert_arc(aptr);
534 catch (
const std::bad_alloc &)
536 src->remove_arc(aptr);
546 catch (
const std::bad_alloc &)
548 src->remove_arc(aptr);
550 tgt->remove_arc(aptr);
567 bool compress_done =
false;
574 catch (
const std::bad_alloc &)
580 compress_done =
true;
591 src->remove_arc_ne(arc);
593 tgt->remove_arc_ne(arc);
617 for (
size_t i = 0, n = p->num_arcs; i < n; ++i)
645 return static_cast<Arc *
>(p->arc_array[0]);
706 template <
typename __Graph_Node = Graph_Anode<
int>,
707 typename __Graph_Arc = Graph_Aarc<
int>>
Exception handling system with formatted messages for Aleph-w.
#define ah_underflow_error_if(C)
Throws std::underflow_error if condition holds.
#define ah_overflow_error_if(C)
Throws std::overflow_error if condition holds.
#define ah_domain_error_if(C)
Throws std::domain_error if condition holds.
#define ah_bad_alloc_if(C)
Throws std::bad_alloc if condition holds.
#define ah_range_error_if(C)
Throws std::range_error if condition holds.
Iterator wrapper for C++ raw arrays and circular buffers.
Iterator over the arcs of a node.
void prev_ne() noexcept
Move to the previous arc; the iterator must be on an arc.
void reset_last() noexcept
Put the iterator on the last arc.
void next()
Move to the next arc.
Node_Arc_Iterator(Node *src) noexcept
Instantiate an iterator over node src.
Node * get_tgt_node_ne() const
Return the target node of the current arc.
Node * get_tgt_node() const
Return the target node of the current arc; it throws as get_curr().
void *const * get_base() const noexcept
Return the array of the arcs of the node.
void prev()
Move to the previous arc.
bool is_last() const noexcept
Return true if the iterator is on the last arc.
void reset_first() noexcept
Put the iterator on the first arc.
Node_Arc_Iterator() noexcept
Instantiate an empty (invalid) iterator.
void end() noexcept
Put the iterator past the last arc.
Node * Set_Type
The set type over which iteration is performed.
bool has_curr() const noexcept
Return true if the iterator is on an arc.
Arc * get_current_arc_ne() const noexcept
Return the current arc.
void next_ne() noexcept
Move to the next arc; the iterator must be on an arc.
Arc * get_curr_ne() const noexcept
Return the current arc, which must exist.
Arc * get_current_arc() const
Return the current arc.
void ** get_base() noexcept
Return the array of the arcs of the node.
Arc * get_curr() const
Return the current arc.
long get_pos() const noexcept
Return the position of the current arc, counted from 0.
void set_pos(const long new_pos) noexcept
Put the iterator on position new_pos; the number of arcs is the position past the last one.
void reset() noexcept
Put the iterator on the first arc.
typename Arc::Arc_Type Arc_Type
virtual void remove_arc(Arc *a)
virtual Node * insert_node(Node *p)
Inserts the node p, made with new, which the graph takes.
void swap(Array_Graph &g) noexcept
Arc * get_first_arc(Node *p) const
Arc * disconnect_arc(Arc *arc)
Dlink & get_arc_dlink() noexcept
Returns reference to internal arc Dlink for sorting operations.
Arc * try_insert_arc(Node *src, Node *tgt, void *a)
virtual ~Array_Graph() noexcept
virtual void remove_node(Node *p)
Arc * get_first_arc() const
Node * get_first_node() const
Arc * insert_arc(Node *src, Node *tgt, void *a)
Arc * connect_arc(Arc *arc)
typename Node::Node_Type Node_Type
Dlink & get_node_dlink() noexcept
Returns reference to internal node Dlink for sorting operations.
Generic directed graph (digraph) wrapper template.
Doubly linked circular list node.
Dlink * remove_first() noexcept
See remove_next().
constexpr Dlink *& get_first() const noexcept
If this is a header node, it return the first node of this
void init() noexcept
See reset().
constexpr bool is_empty() const noexcept
Return true if this (as header node) is empty.
void append(Dlink *node) noexcept
Insert node before this.
void swap(Dlink *link) noexcept
Swap this with list whose header is link.
Dlink * del() noexcept
Remove this from the list. this must not be a header node.
Doubly-linked list (defined in tpl_dynList.H).
T & append(const T &item)
Graph_Aarc(Arc_Info &&info=Arc_Info())
Graph_Aarc(const Arc_Info &info)
Graph_Aarc(void *src, void *tgt, const Arc_Info &data)
Graph_Aarc(const Graph_Aarc &arc)
Graph_Aarc(void *src, void *tgt, Arc_Info &&data=Arc_Info())
Graph_Aarc & operator=(const Graph_Aarc &arc)
Graph_Anode & operator=(const Graph_Anode &node)
void remove_arc(const void *arc)
static constexpr size_t Default_Cap
void * insert_arc(void *arc)
void remove_arc_ne(const void *arc) noexcept
Graph_Anode(Node_Info &&info)
size_t contract_threshold
void allocate_more(size_t new_size)
static constexpr size_t Contract_Factor
Graph_Anode(const Node_Info &info)
Graph_Anode(const Graph_Anode &node)
void contract_arc_array() noexcept
Graph_Anode(Graph_Anode *p)
void init(const size_t dim)
bool resize_arc_array(const size_t new_size) noexcept
Common methods for the arc of a graph.
void * tgt_node
Please don't use.
void * get_connected_node(void *node) noexcept
Common attributes and methods for nodes (vertexes) belonging to graphs.
NodeInfo & get_info() noexcept
Return a modifiable reference to the data contained in the node.
size_t num_arcs
data associated to the node. Access it with get_info()
Common methods to the Aleph-w ( ) graph classes.
Container< Arc * > arcs() const
Return a container with all the arcs of the graph.
Node * insert_node(const Node_Type &node_info)
Allocate a new node, set by copy its data content and insert it into the graph.
Node * get_src_node(Arc *arc) const noexcept
Return the source node of arc (only for directed graphs)
void common_swap(GT &g) noexcept
Arc * insert_arc(Node *src, Node *tgt, const Arc_Type &arc_info)
Create and insert a new arc linking two nodes and copying data.
constexpr size_t get_num_arcs() const noexcept
Return the number of arcs of the graph.
Node * get_tgt_node(Arc *arc) const noexcept
Return the target node of arc (only for directed graphs)
void remove_arcs_if(Predicate pred)
Remove all arcs matching a predicate.
__gmp_expr< typename __gmp_resolve_expr< T, V >::value_type, __gmp_binary_expr< __gmp_expr< T, U >, __gmp_expr< V, W >, __gmp_dim_function > > dim(const __gmp_expr< T, U > &expr1, const __gmp_expr< V, W > &expr2)
#define ALEPH_GRAPH_COPY_MOVE_CTORS(GraphClass)
Macro to generate copy/move constructors and assignment operators.
Main namespace for Aleph-w library functions.
and
Check uniqueness with explicit hash + equality functors.
Iterator over arcs of a graph.
Arc_Iterator(const Array_Graph &g)
Node_Iterator(const Array_Graph &g) noexcept
GTNodeIterator< Array_Graph > Base
Common arc iterator for graph having its arcs derived from Dlink class.
Common node iterator for graph having its node derived from Dlink class.
Dynamic set implementations based on balanced binary search trees.
Simple graph implementation with adjacency lists.