Aleph-w 7.10.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
Aleph::shortest_path_detail Namespace Reference

Namespace for shortest path algorithm implementation details. More...

Classes

struct  Beyond_Max_Error
 The std::overflow_error of a painting that leaves out a node whose distance does not fit. More...
 

Functions

template<typename T >
T checked_add (const T &a, const T &b)
 Safely add two distance values with overflow checking.
 
template<typename T >
bool add_if_fits (const T &a, const T &b, T &out)
 Adds two distance values when the sum fits.
 

Detailed Description

Namespace for shortest path algorithm implementation details.

Function Documentation

◆ add_if_fits()

template<typename T >
bool Aleph::shortest_path_detail::add_if_fits ( const T &  a,
const T &  b,
T &  out 
)
inline

Adds two distance values when the sum fits.

As checked_add(), for a second operand that is not negative, but a sum beyond max() of an integral type gives false instead of throwing. A floating sum always fits.

Template Parameters
TDistance type (integral or floating-point).
Parameters
aFirst operand.
bSecond operand, not negative.
[out]outThe sum, when it fits; else untouched.
Returns
Whether the sum fits.

Definition at line 151 of file shortest_path_common.H.

References Aleph::and, and out.

Referenced by Aleph::k_shortest_paths_detail::build_suffix_index_digraph(), Aleph::k_shortest_paths_detail::build_suffix_index_with_itor(), Aleph::k_shortest_paths_detail::cost_of_arcs_if_fits(), and Aleph::k_shortest_paths_detail::generate_general_deviation_candidates().

◆ checked_add()

template<typename T >
T Aleph::shortest_path_detail::checked_add ( const T &  a,
const T &  b 
)
inline

Safely add two distance values with overflow checking.

For integral types, checks for overflow/underflow before performing the addition. For floating-point types, performs regular addition.

Template Parameters
TDistance type (integral or floating-point).
Parameters
aFirst operand.
bSecond operand.
Returns
Sum of a and b.
Exceptions
std::overflow_errorIf integer overflow/underflow would occur.

Definition at line 124 of file shortest_path_common.H.

References ah_overflow_error_if, and Aleph::and.

Referenced by Aleph::Shortest_Path_Base< GT, Distance, Itor, SA, HeapT >::checked_add(), Aleph::negative_cycles_detail::cycle_cost(), Aleph::find_disjoint_negative_cycles(), Aleph::k_shortest_paths_detail::generate_general_deviation_candidates(), Aleph::min_mean_cycle_detail::karp_answer(), Aleph::min_mean_cycle_detail::karp_table(), Aleph::most_negative_cycle_bounded(), and Aleph::negative_cycles_detail::offer_simple_components().