|
slang-netlist
0.9.0
|
#include <DirectedGraph.hpp>
Public Types | |
| using | OutEdgePtrType = std::unique_ptr<EdgeType> |
| using | OutEdgeListType = std::vector<OutEdgePtrType> |
| using | InEdgeListType = std::vector<EdgeType *> |
| using | iterator = typename OutEdgeListType::iterator |
| using | const_iterator = typename OutEdgeListType::const_iterator |
| using | in_iterator = typename InEdgeListType::iterator |
| using | const_in_iterator = typename InEdgeListType::const_iterator |
| using | edge_descriptor = EdgeType * |
Public Member Functions | |
| Node ()=default | |
| virtual | ~Node ()=default |
| Node (const Node &)=delete | |
| Node (Node &&)=delete | |
| auto | operator= (const Node &) -> Node &=delete |
| auto | operator= (Node &&) -> Node &=delete |
| auto | begin () const -> const_iterator |
| auto | end () const -> const_iterator |
| auto | begin () -> iterator |
| auto | end () -> iterator |
| auto | inBegin () -> in_iterator |
| auto | inEnd () -> in_iterator |
| auto | inBegin () const -> const_in_iterator |
| auto | inEnd () const -> const_in_iterator |
| auto | operator== (const NodeType &N) const -> bool |
| auto | findEdgeFrom (const NodeType &sourceNode) -> in_iterator |
| Return an iterator to the edge connecting the source node. | |
| auto | findEdgeFrom (const NodeType &sourceNode) const -> const_in_iterator |
| Return an iterator to the edge connecting the source node. | |
| auto | findEdgeTo (const NodeType &targetNode) -> iterator |
| Return an iterator to the edge connecting the target node. | |
| auto | findEdgeTo (const NodeType &targetNode) const -> const_iterator |
| Return an iterator to the edge connecting the target node. | |
| auto | addEdge (NodeType &targetNode) -> EdgeType & |
| auto | addNewEdge (NodeType &targetNode) -> EdgeType & |
| auto | removeEdge (NodeType &targetNode) -> bool |
| void | clearAllEdges () |
| Remove all edges to/from this node. | |
| auto | getEdgesTo (const NodeType &targetNode, std::vector< EdgeType * > &result) -> bool |
| auto | getInEdges () const -> const InEdgeListType & |
| Return the list of outgoing edges from this node. | |
| auto | getOutEdges () const -> const OutEdgeListType & |
| auto | inDegree () const -> size_t |
| Return the total number of edges incoming to this node. | |
| auto | outDegree () const -> size_t |
| Return the total number of edges outgoing from this node. | |
Protected Types | |
| using | OutEdgeIndex = flat_hash_map<NodeType const *, EdgeType *> |
Protected Member Functions | |
| auto | isEqualTo (const NodeType &node) const -> bool |
| auto | getDerived () -> NodeType & |
| auto | getDerived () const -> const NodeType & |
Protected Attributes | |
| std::mutex | edgeMutex |
| InEdgeListType | inEdges |
| OutEdgeListType | outEdges |
| std::unique_ptr< OutEdgeIndex > | outEdgeIndex |
Static Protected Attributes | |
| static constexpr size_t | outEdgeIndexThreshold = 16 |
Friends | |
| auto | operator== (NodeType const &A, NodeType const &B) noexcept -> bool |
A class to represent a node in a directed graph.
Edges are owned by their source node via std::unique_ptr in outEdges. The target node stores a raw pointer in inEdges; lifetime is bounded by the source's outEdges entry.
| using slang::netlist::Node< NodeType, EdgeType >::const_in_iterator = typename InEdgeListType::const_iterator |
| using slang::netlist::Node< NodeType, EdgeType >::const_iterator = typename OutEdgeListType::const_iterator |
| using slang::netlist::Node< NodeType, EdgeType >::edge_descriptor = EdgeType * |
| using slang::netlist::Node< NodeType, EdgeType >::in_iterator = typename InEdgeListType::iterator |
| using slang::netlist::Node< NodeType, EdgeType >::InEdgeListType = std::vector<EdgeType *> |
| using slang::netlist::Node< NodeType, EdgeType >::iterator = typename OutEdgeListType::iterator |
|
protected |
Index from target-node pointer to the first edge in outEdges with that target. Allocated lazily once outEdges grows past outEdgeIndexThreshold so low-fanout nodes pay no per-node map overhead. Above the threshold the map keeps addEdge O(1) amortized regardless of out-degree. Protected by edgeMutex.
| using slang::netlist::Node< NodeType, EdgeType >::OutEdgeListType = std::vector<OutEdgePtrType> |
| using slang::netlist::Node< NodeType, EdgeType >::OutEdgePtrType = std::unique_ptr<EdgeType> |
|
default |
|
virtualdefault |
|
delete |
|
delete |
|
inline |
Add an edge between this node and a target node, only if it does not already exist. Return a reference to the newly-created edge.
O(1) amortized: outEdgeIndex memoizes the first edge to each target, avoiding the linear outEdges scan that becomes quadratic on high-fan-out nodes (e.g. shared clocks driving every instance after non-canonical-instance resolution). The index is allocated lazily once outEdges grows past outEdgeIndexThreshold; below that, a linear scan over the few outEdges is faster and avoids the map's empty-control-byte overhead per node.
Thread safety: safe to call concurrently. Lock ordering: source edgeMutex before target edgeMutex (self-edges use a single lock).
|
inline |
Unconditionally add a new edge between this node and a target node, even if one already exists (creating a parallel edge). The outEdgeIndex is left untouched: it points at the first edge to the target.
Thread safety: safe to call concurrently. Lock ordering: source edgeMutex before target edgeMutex (self-edges use a single lock).
|
inline |
|
inline |
|
inline |
Remove all edges to/from this node.
|
inline |
|
inline |
|
inline |
Return an iterator to the edge connecting the source node.
|
inline |
Return an iterator to the edge connecting the source node.
|
inline |
Return an iterator to the edge connecting the target node.
|
inline |
Return an iterator to the edge connecting the target node.
|
inlineprotected |
|
inlineprotected |
|
inline |
Populate a result vector of edges from this node to the specified target node. Return true if at least one edge was found.
|
inline |
Return the list of outgoing edges from this node.
|
inline |
|
inline |
|
inline |
|
inline |
Return the total number of edges incoming to this node.
|
inline |
|
inline |
|
inlineprotected |
|
delete |
|
delete |
|
inline |
|
inline |
Return the total number of edges outgoing from this node.
|
inline |
Remove an edge between this node and a target node. Return true if the edge existed and was removed, and false otherwise.
|
friend |
Static polymorphism: delegate implementation (via isEqualTo) to the derived class. Add friend operator to resolve ambiguity between operand ordering with C++20.
|
mutableprotected |
Per-node mutex protecting inEdges and outEdges. Lock ordering: when locking two nodes, always lock the source node (the one whose outEdges is modified) before the target node.
|
protected |
|
protected |
|
staticconstexprprotected |
Out-degree at which we switch from linear scans of outEdges to the lazily-allocated outEdgeIndex map.
|
protected |