-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
breaking-change: Separate concerns weightedness and directedness (#48)
* handle directedness with tag dispatch * separate concerns weighted edges and graphs
- Loading branch information
Showing
33 changed files
with
293 additions
and
430 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#pragma once | ||
|
||
#include <concepts> | ||
#include <type_traits> | ||
|
||
namespace graaf { | ||
|
||
/** | ||
* @brief Interface for a weighted edge. | ||
* | ||
* This is what is stored internally and returned from a weighted graph in | ||
* order to make sure each edge in a weighted graph has a common interface to | ||
* extract the weight. | ||
* | ||
* @tparam WEIGHT_T The type of the weight. | ||
*/ | ||
template <typename WEIGHT_T = int> | ||
class weighted_edge { | ||
public: | ||
using weight_t = WEIGHT_T; | ||
|
||
virtual ~weighted_edge() = default; | ||
|
||
[[nodiscard]] virtual WEIGHT_T get_weight() const noexcept = 0; | ||
}; | ||
|
||
template <typename derived> | ||
concept derived_from_weighted_edge = | ||
std::is_base_of_v<weighted_edge<typename derived::weight_t>, derived>; | ||
|
||
/** | ||
* Overload set to get the weight from an edge | ||
*/ | ||
template <typename WEIGHTED_EDGE_T> | ||
requires derived_from_weighted_edge<WEIGHTED_EDGE_T> | ||
[[nodiscard]] auto get_weight(const WEIGHTED_EDGE_T& edge); | ||
|
||
template <typename EDGE_T> | ||
requires std::is_arithmetic_v<EDGE_T> | ||
[[nodiscard]] EDGE_T get_weight(const EDGE_T& edge); | ||
|
||
template <typename EDGE_T> | ||
[[nodiscard]] int get_weight(const EDGE_T& /*edge*/); | ||
|
||
} // namespace graaf | ||
|
||
#include "edge.tpp" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#pragma once | ||
|
||
namespace graaf { | ||
|
||
template <typename WEIGHTED_EDGE_T> | ||
requires derived_from_weighted_edge<WEIGHTED_EDGE_T> | ||
auto get_weight(const WEIGHTED_EDGE_T& edge) { | ||
return edge.get_weight(); | ||
} | ||
|
||
template <typename EDGE_T> | ||
requires std::is_arithmetic_v<EDGE_T> | ||
EDGE_T get_weight(const EDGE_T& edge) { | ||
return edge; | ||
} | ||
|
||
template <typename EDGE_T> | ||
int get_weight(const EDGE_T& /*edge*/) { | ||
// By default, an edge has unit weight | ||
return 1; | ||
} | ||
|
||
} // namespace graaf |
Oops, something went wrong.