At the moment
- your edges have an identity.
- There are three types.
Abolishing both leads to a simpler implementation:
struct Edge {
Node* from;
Node* to;
double weight;
// optional: enum EdgeType type;
};
std::unordered_set<Edge> edges;
Circular edges have both pointing to the same node.
Bi-directional edges have a reversed duplicate.
And normal directional edges are simple.
If you actually need to differentiate between those often enough, adding an enum to cache that info is simplicity itself.
Until that day, revel in the simplicity of having only a single type.
If you save your nodes in a container, using indices might be a nice idea.
###Implementation:
Implementation:
Never import wholesale any namespace not designed for it, like
std
. Doing so can lead to conflicts which might silently or hopefully noisily break your code if the implementation changes even slightly.The
Node
s you leak might be a concern, outside this toy-example. At the very least make sure Consider saving them in some container by value (careful of invalidation-rules), or managing them with smart-pointers.Of more concern are the
Edge
s. If registering anEdge
fails, it is leaked. Allocate them withstd::make_unique
instead, to ensure they are always properly owned.
At the moment
- your edges have an identity.
- There are three types.
Abolishing both leads to a simpler implementation:
struct Edge {
Node* from;
Node* to;
double weight;
// optional: enum EdgeType type;
};
std::unordered_set<Edge> edges;
Circular edges have both pointing to the same node.
Bi-directional edges have a reversed duplicate.
And normal directional edges are simple.
If you actually need to differentiate between those often enough, adding an enum to cache that info is simplicity itself.
Until that day, revel in the simplicity of having only a single type.
If you save your nodes in a container, using indices might be a nice idea.
###Implementation:
Never import wholesale any namespace not designed for it, like
std
. Doing so can lead to conflicts which might silently or hopefully noisily break your code if the implementation changes even slightly.The
Node
s you leak might be a concern, outside this toy-example. At the very least make sure Consider saving them in some container by value (careful of invalidation-rules), or managing them with smart-pointers.Of more concern are the
Edge
s. If registering anEdge
fails, it is leaked. Allocate them withstd::make_unique
instead, to ensure they are always properly owned.
At the moment
- your edges have an identity.
- There are three types.
Abolishing both leads to a simpler implementation:
struct Edge {
Node* from;
Node* to;
double weight;
// optional: enum EdgeType type;
};
std::unordered_set<Edge> edges;
Circular edges have both pointing to the same node.
Bi-directional edges have a reversed duplicate.
And normal directional edges are simple.
If you actually need to differentiate between those often enough, adding an enum to cache that info is simplicity itself.
Until that day, revel in the simplicity of having only a single type.
If you save your nodes in a container, using indices might be a nice idea.
Implementation:
Never import wholesale any namespace not designed for it, like
std
. Doing so can lead to conflicts which might silently or hopefully noisily break your code if the implementation changes even slightly.The
Node
s you leak might be a concern, outside this toy-example. At the very least make sure Consider saving them in some container by value (careful of invalidation-rules), or managing them with smart-pointers.Of more concern are the
Edge
s. If registering anEdge
fails, it is leaked. Allocate them withstd::make_unique
instead, to ensure they are always properly owned.
At the moment
- your edges have an identity.
- There are three types.
Abolishing both leads to a simpler implementation:
struct Edge {
Node* from;
Node* to;
double weight;
// optional: enum EdgeType type;
};
std::unordered_set<Edge> edges;
Circular edges have both pointing to the same node.
Bi-directional edges have a reversed duplicate.
And normal directional edges are simple.
If you actually need to differentiate between those often enough, adding an enum to cache that info is simplicity itself.
Until that day, revel in the simplicity of having only a single type.
If you save your nodes in a container, using indices might be a nice idea.
###Implementation:
Never import wholesale any namespace not designed for it, like
std
. Doing so can lead to conflicts which might silently or hopefully noisily break your code if the implementation changes even slightly.The
Node
s you leak might be a concern, outside this toy-example. At the very least make sure Consider saving them in some container by value (careful of invalidation-rules), or managing them with smart-pointers.Of more concern are the
Edge
s. If registering anEdge
fails, it is leaked. Allocate them withstd::make_unique
instead, to ensure they are always properly owned.
At the moment
- your edges have an identity.
- There are three types.
Abolishing both leads to a simpler implementation:
struct Edge {
Node* from;
Node* to;
double weight;
// optional: enum EdgeType type;
};
std::unordered_set<Edge> edges;
Circular edges have both pointing to the same node.
Bi-directional edges have a reversed duplicate.
And normal directional edges are simple.
If you actually need to differentiate between those often enough, adding an enum to cache that info is simplicity itself.
If you save your nodes in a container, using indices might be a nice idea.
###Implementation:
Never import wholesale any namespace not designed for it, like
std
. Doing so can lead to conflicts which might silently or hopefully noisily break your code if the implementation changes even slightly.The
Node
s you leak might be a concern, outside this toy-example. At the very least make sure Consider saving them in some container by value (careful of invalidation-rules), or managing them with smart-pointers.Of more concern are the
Edge
s. If registering anEdge
fails, it is leaked. Allocate them withstd::make_unique
instead, to ensure they are always properly owned.
At the moment
- your edges have an identity.
- There are three types.
Abolishing both leads to a simpler implementation:
struct Edge {
Node* from;
Node* to;
double weight;
// optional: enum EdgeType type;
};
std::unordered_set<Edge> edges;
Circular edges have both pointing to the same node.
Bi-directional edges have a reversed duplicate.
And normal directional edges are simple.
If you actually need to differentiate between those often enough, adding an enum to cache that info is simplicity itself.
Until that day, revel in the simplicity of having only a single type.
If you save your nodes in a container, using indices might be a nice idea.
###Implementation:
Never import wholesale any namespace not designed for it, like
std
. Doing so can lead to conflicts which might silently or hopefully noisily break your code if the implementation changes even slightly.The
Node
s you leak might be a concern, outside this toy-example. At the very least make sure Consider saving them in some container by value (careful of invalidation-rules), or managing them with smart-pointers.Of more concern are the
Edge
s. If registering anEdge
fails, it is leaked. Allocate them withstd::make_unique
instead, to ensure they are always properly owned.
At the moment
- your edges have an identity.
- There are three types.
Abolishing both leads to a simpler implementation:
struct Edge {
Node* from;
Node* to;
double weight;
// optional: enum EdgeType type;
};
std::unordered_set<Edge> edges;
Circular edges have both pointing to the same node.
Bi-directional edges have a reversed duplicate.
And normal directional edges are simple.
If you actually need to differentiate between those often enough, adding an enum to cache that info is simplicity itself.
If you save your nodes in a container, using indices might be a nice idea.
###Implementation:
Never import wholesale any namespace not designed for it, like
std
. Doing so can lead to conflicts which might silently or hopefully noisily break your code if the implementation changes even slightly.The
Node
s you leak might be a concern, outside this toy-example. At the very least make sure Consider saving them in some container by value (careful of invalidation-rules), or managing them with smart-pointers.Of more concern are the
Edge
s. If registering anEdge
fails, it is leaked. Allocate them withstd::make_unique
instead, to ensure they are always properly owned.
At the moment
- your edges have an identity.
- There are three types.
Abolishing both leads to a simpler implementation:
struct Edge {
Node* from;
Node* to;
double weight;
// optional: enum EdgeType type;
};
std::unordered_set<Edge> edges;
Circular edges have both pointing to the same node.
Bi-directional edges have a reversed duplicate.
And normal directional edges are simple.
If you actually need to differentiate between those often enough, adding an enum to cache that info is simplicity itself.
###Implementation:
Never import wholesale any namespace not designed for it, like
std
. Doing so can lead to conflicts which might silently or hopefully noisily break your code if the implementation changes even slightly.The
Node
s you leak might be a concern, outside this toy-example. At the very least make sure Consider saving them in some container by value (careful of invalidation-rules), or managing them with smart-pointers.Of more concern are the
Edge
s. If registering anEdge
fails, it is leaked. Allocate them withstd::make_unique
instead, to ensure they are always properly owned.
At the moment
- your edges have an identity.
- There are three types.
Abolishing both leads to a simpler implementation:
struct Edge {
Node* from;
Node* to;
double weight;
// optional: enum EdgeType type;
};
std::unordered_set<Edge> edges;
Circular edges have both pointing to the same node.
Bi-directional edges have a reversed duplicate.
And normal directional edges are simple.
If you actually need to differentiate between those often enough, adding an enum to cache that info is simplicity itself.
If you save your nodes in a container, using indices might be a nice idea.
###Implementation:
Never import wholesale any namespace not designed for it, like
std
. Doing so can lead to conflicts which might silently or hopefully noisily break your code if the implementation changes even slightly.The
Node
s you leak might be a concern, outside this toy-example. At the very least make sure Consider saving them in some container by value (careful of invalidation-rules), or managing them with smart-pointers.Of more concern are the
Edge
s. If registering anEdge
fails, it is leaked. Allocate them withstd::make_unique
instead, to ensure they are always properly owned.