Skip to main content
Code Review

Return to Answer

Commonmark migration
Source Link

At the moment

  1. your edges have an identity.
  2. 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:

  1. 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.

  2. The Nodes 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.

  3. Of more concern are the Edges. If registering an Edge fails, it is leaked. Allocate them with std::make_unique instead, to ensure they are always properly owned.

At the moment

  1. your edges have an identity.
  2. 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:

  1. 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.

  2. The Nodes 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.

  3. Of more concern are the Edges. If registering an Edge fails, it is leaked. Allocate them with std::make_unique instead, to ensure they are always properly owned.

At the moment

  1. your edges have an identity.
  2. 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:

  1. 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.

  2. The Nodes 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.

  3. Of more concern are the Edges. If registering an Edge fails, it is leaked. Allocate them with std::make_unique instead, to ensure they are always properly owned.

added 73 characters in body
Source Link
Deduplicator
  • 19.6k
  • 1
  • 32
  • 65

At the moment

  1. your edges have an identity.
  2. 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:

  1. 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.

  2. The Nodes 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.

  3. Of more concern are the Edges. If registering an Edge fails, it is leaked. Allocate them with std::make_unique instead, to ensure they are always properly owned.

At the moment

  1. your edges have an identity.
  2. 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:

  1. 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.

  2. The Nodes 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.

  3. Of more concern are the Edges. If registering an Edge fails, it is leaked. Allocate them with std::make_unique instead, to ensure they are always properly owned.

At the moment

  1. your edges have an identity.
  2. 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:

  1. 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.

  2. The Nodes 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.

  3. Of more concern are the Edges. If registering an Edge fails, it is leaked. Allocate them with std::make_unique instead, to ensure they are always properly owned.

added 417 characters in body
Source Link
Deduplicator
  • 19.6k
  • 1
  • 32
  • 65

At the moment

  1. your edges have an identity.
  2. 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:

  1. 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.

  2. The Nodes 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.

  3. Of more concern are the Edges. If registering an Edge fails, it is leaked. Allocate them with std::make_unique instead, to ensure they are always properly owned.

At the moment

  1. your edges have an identity.
  2. 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:

  1. 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.

  2. The Nodes 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.

  3. Of more concern are the Edges. If registering an Edge fails, it is leaked. Allocate them with std::make_unique instead, to ensure they are always properly owned.

At the moment

  1. your edges have an identity.
  2. 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:

  1. 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.

  2. The Nodes 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.

  3. Of more concern are the Edges. If registering an Edge fails, it is leaked. Allocate them with std::make_unique instead, to ensure they are always properly owned.

added 417 characters in body
Source Link
Deduplicator
  • 19.6k
  • 1
  • 32
  • 65
Loading
Source Link
Deduplicator
  • 19.6k
  • 1
  • 32
  • 65
Loading
lang-cpp

AltStyle によって変換されたページ (->オリジナル) /