9concept Node = std::equality_comparable<N>;
11template<
typename NodeType,
typename N>
20template<
typename E,
typename N=E::node_type>
22 {E(cNodeRef,cNodeRef)};
24 {E::isDirected()} -> std::convertible_to<bool>;
25 {e.getFrom()} -> std::same_as<const N &>;
26 {e.getTo()} -> std::same_as<const N &>;
27 typename E::node_type;
28 typename E::hash_function;
29 typename E::equality_predicate;
35template<
typename F,
typename N,
typename A>
46template<
typename E,
typename N= E::node_type,
typename A=E::annotation_type,
typename W=E::weight_function>
48 {E(cNodeRef,cNodeRef,constARef)};
49 {E(cNodeRef,cNodeRef,ARval)};
50 {e.getWeight()} -> std::convertible_to<A>;
51 {e.unweighted()} -> std::convertible_to<E>;
52 typename E::annotation_type;
53 typename E::weight_function;
57namespace fishnet::graph::__impl{
66 template<Node N,
bool Directed, fishnet::util::HashFunction<N> Hash = std::hash<N>, fishnet::util::BiPredicate<N> Equal = std::equal_to<N>>
71 static inline Equal eq = Equal();
72 static inline Hash hasher = Hash();
75 using hash_function = Hash;
76 using equality_predicate = Equal;
78 constexpr static bool isDirected(){
82 BaseEdge(
const N & from,
const N & to):from(from),to(to){}
84 BaseEdge( N && from, N && to):from(
std::move(from)),to(
std::move(to)){}
86 const N & getFrom()
const {
90 const N & getTo()
const{
94 bool operator==(
const BaseEdge<N,false,Hash,Equal> & other)
const{
95 if constexpr(not Directed){
96 return (eq(from, other.getFrom()) and eq(to,other.getTo())) or
97 (eq(from, other.getTo()) and eq(to, other.getFrom()));
102 bool operator==(
const BaseEdge<N,true,Hash,Equal> & other)
const {
103 if constexpr(Directed){
104 return eq(from,other.getFrom()) && eq(to, other.getTo());
109 size_t inline hash()
const{
110 if constexpr(Directed){
111 size_t hashFrom = hasher(from);
112 size_t hashTo = hasher(to);
113 constexpr size_t shift =
sizeof(size_t) *4;
114 return (hashFrom << shift) | hashTo;
116 return hasher(from) ^ hasher(to);
120 std::string toString() const noexcept requires
fishnet::util::HasToString<N>{
121 std::ostringstream oss;
122 oss <<
"(" << this->from.toString() <<
")";
123 if constexpr(Directed){
128 oss <<
"(" << this->to.toString() <<
")";
140 template<Edge E,Annotation A,WeightFunction<
typename E::node_type,A> W>
141 class WeightedEdgeDecorator:
public E{
144 using N=
typename E::node_type;
146 using annotation_type=A;
147 using weight_function=W;
149 WeightedEdgeDecorator(
const N & from,
const N & to,
const A & weight): E(from,to),weight(weight){};
151 WeightedEdgeDecorator(
const N & from,
const N & to):E(from,to){
152 this->weight = W()(from,to);
155 WeightedEdgeDecorator(
const N & from,
const N & to, A &&weight): E(from,to),weight(
std::move(weight)){};
157 WeightedEdgeDecorator( E && edge ):WeightedEdgeDecorator(edge.getFrom(),edge.getTo()){}
159 WeightedEdgeDecorator(
const E & edge ):WeightedEdgeDecorator(edge.getFrom(),edge.getTo()){}
161 void setWeight(
const A & weight){
162 this->weight = weight;
165 const A& getWeight()
const{
169 E
inline unweighted()
const {
170 return E(this->getFrom(),this->getTo());
173 bool operator==(
const WeightedEdgeDecorator<E,A,W> & other)
const {
174 return this->unweighted() == other.unweighted() && this->weight == other.getWeight();
177 size_t inline hash()
const{
178 return this->unweighted().hash() + std::hash<A>{}(weight);
185template<Node N, fishnet::util::HashFunction<N> Hash = std::hash<N>, fishnet::util::BiPredicate<N> Equal = std::equal_to<N>>
188template<Node N, fishnet::util::HashFunction<N> Hash = std::hash<N>, fishnet::util::BiPredicate<N> Equal = std::equal_to<N>>
191template<Edge E, Annotation A , WeightFunction<
typename E::node_type,A> W>
Interface for an Edge.
Definition Edge.hpp:21
Interface for a weighted Edge.
Definition Edge.hpp:47
Definition NumericConcepts.hpp:7
Definition FunctionalConcepts.hpp:15
Helper concept which checks whether a class has a hash method.
Definition ObjectConcepts.hpp:22
Definition AdjacencyContainer.hpp:4
__impl::BaseEdge< N, true, Hash, Equal > DirectedEdge
Definition Edge.hpp:189
__impl::BaseEdge< N, false, Hash, Equal > UndirectedEdge
Definition Edge.hpp:186
__impl::WeightedEdgeDecorator< E, A, W > WeightEdge
Definition Edge.hpp:192
Definition BFSClustering.hpp:5