slang-netlist  0.9.0
Loading...
Searching...
No Matches
slang::netlist::Node< NodeType, EdgeType > Class Template Reference

#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< OutEdgeIndexoutEdgeIndex

Static Protected Attributes

static constexpr size_t outEdgeIndexThreshold = 16

Friends

auto operator== (NodeType const &A, NodeType const &B) noexcept -> bool

Detailed Description

template<class NodeType, class EdgeType>
class slang::netlist::Node< NodeType, EdgeType >

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.

Member Typedef Documentation

◆ const_in_iterator

template<class NodeType, class EdgeType>
using slang::netlist::Node< NodeType, EdgeType >::const_in_iterator = typename InEdgeListType::const_iterator

◆ const_iterator

template<class NodeType, class EdgeType>
using slang::netlist::Node< NodeType, EdgeType >::const_iterator = typename OutEdgeListType::const_iterator

◆ edge_descriptor

template<class NodeType, class EdgeType>
using slang::netlist::Node< NodeType, EdgeType >::edge_descriptor = EdgeType *

◆ in_iterator

template<class NodeType, class EdgeType>
using slang::netlist::Node< NodeType, EdgeType >::in_iterator = typename InEdgeListType::iterator

◆ InEdgeListType

template<class NodeType, class EdgeType>
using slang::netlist::Node< NodeType, EdgeType >::InEdgeListType = std::vector<EdgeType *>

◆ iterator

template<class NodeType, class EdgeType>
using slang::netlist::Node< NodeType, EdgeType >::iterator = typename OutEdgeListType::iterator

◆ OutEdgeIndex

template<class NodeType, class EdgeType>
using slang::netlist::Node< NodeType, EdgeType >::OutEdgeIndex = flat_hash_map<NodeType const *, EdgeType *>
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.

◆ OutEdgeListType

template<class NodeType, class EdgeType>
using slang::netlist::Node< NodeType, EdgeType >::OutEdgeListType = std::vector<OutEdgePtrType>

◆ OutEdgePtrType

template<class NodeType, class EdgeType>
using slang::netlist::Node< NodeType, EdgeType >::OutEdgePtrType = std::unique_ptr<EdgeType>

Constructor & Destructor Documentation

◆ Node() [1/3]

template<class NodeType, class EdgeType>
slang::netlist::Node< NodeType, EdgeType >::Node ( )
default

◆ ~Node()

template<class NodeType, class EdgeType>
virtual slang::netlist::Node< NodeType, EdgeType >::~Node ( )
virtualdefault

◆ Node() [2/3]

template<class NodeType, class EdgeType>
slang::netlist::Node< NodeType, EdgeType >::Node ( const Node< NodeType, EdgeType > & )
delete

◆ Node() [3/3]

template<class NodeType, class EdgeType>
slang::netlist::Node< NodeType, EdgeType >::Node ( Node< NodeType, EdgeType > && )
delete

Member Function Documentation

◆ addEdge()

template<class NodeType, class EdgeType>
auto slang::netlist::Node< NodeType, EdgeType >::addEdge ( NodeType & targetNode) -> EdgeType &
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).

◆ addNewEdge()

template<class NodeType, class EdgeType>
auto slang::netlist::Node< NodeType, EdgeType >::addNewEdge ( NodeType & targetNode) -> EdgeType &
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).

◆ begin() [1/2]

template<class NodeType, class EdgeType>
auto slang::netlist::Node< NodeType, EdgeType >::begin ( ) -> iterator
inline

◆ begin() [2/2]

template<class NodeType, class EdgeType>
auto slang::netlist::Node< NodeType, EdgeType >::begin ( ) const -> const_iterator
inline

◆ clearAllEdges()

template<class NodeType, class EdgeType>
void slang::netlist::Node< NodeType, EdgeType >::clearAllEdges ( )
inline

Remove all edges to/from this node.

◆ end() [1/2]

template<class NodeType, class EdgeType>
auto slang::netlist::Node< NodeType, EdgeType >::end ( ) -> iterator
inline

◆ end() [2/2]

template<class NodeType, class EdgeType>
auto slang::netlist::Node< NodeType, EdgeType >::end ( ) const -> const_iterator
inline

◆ findEdgeFrom() [1/2]

template<class NodeType, class EdgeType>
auto slang::netlist::Node< NodeType, EdgeType >::findEdgeFrom ( const NodeType & sourceNode) -> in_iterator
inline

Return an iterator to the edge connecting the source node.

◆ findEdgeFrom() [2/2]

template<class NodeType, class EdgeType>
auto slang::netlist::Node< NodeType, EdgeType >::findEdgeFrom ( const NodeType & sourceNode) const -> const_in_iterator
inline

Return an iterator to the edge connecting the source node.

◆ findEdgeTo() [1/2]

template<class NodeType, class EdgeType>
auto slang::netlist::Node< NodeType, EdgeType >::findEdgeTo ( const NodeType & targetNode) -> iterator
inline

Return an iterator to the edge connecting the target node.

◆ findEdgeTo() [2/2]

template<class NodeType, class EdgeType>
auto slang::netlist::Node< NodeType, EdgeType >::findEdgeTo ( const NodeType & targetNode) const -> const_iterator
inline

Return an iterator to the edge connecting the target node.

◆ getDerived() [1/2]

template<class NodeType, class EdgeType>
auto slang::netlist::Node< NodeType, EdgeType >::getDerived ( ) -> NodeType &
inlineprotected

◆ getDerived() [2/2]

template<class NodeType, class EdgeType>
auto slang::netlist::Node< NodeType, EdgeType >::getDerived ( ) const -> const NodeType &
inlineprotected

◆ getEdgesTo()

template<class NodeType, class EdgeType>
auto slang::netlist::Node< NodeType, EdgeType >::getEdgesTo ( const NodeType & targetNode,
std::vector< EdgeType * > & result ) -> bool
inline

Populate a result vector of edges from this node to the specified target node. Return true if at least one edge was found.

◆ getInEdges()

template<class NodeType, class EdgeType>
auto slang::netlist::Node< NodeType, EdgeType >::getInEdges ( ) const -> const InEdgeListType &
inline

Return the list of outgoing edges from this node.

◆ getOutEdges()

template<class NodeType, class EdgeType>
auto slang::netlist::Node< NodeType, EdgeType >::getOutEdges ( ) const -> const OutEdgeListType &
inline

◆ inBegin() [1/2]

template<class NodeType, class EdgeType>
auto slang::netlist::Node< NodeType, EdgeType >::inBegin ( ) -> in_iterator
inline

◆ inBegin() [2/2]

template<class NodeType, class EdgeType>
auto slang::netlist::Node< NodeType, EdgeType >::inBegin ( ) const -> const_in_iterator
inline

◆ inDegree()

template<class NodeType, class EdgeType>
auto slang::netlist::Node< NodeType, EdgeType >::inDegree ( ) const -> size_t
inline

Return the total number of edges incoming to this node.

◆ inEnd() [1/2]

template<class NodeType, class EdgeType>
auto slang::netlist::Node< NodeType, EdgeType >::inEnd ( ) -> in_iterator
inline

◆ inEnd() [2/2]

template<class NodeType, class EdgeType>
auto slang::netlist::Node< NodeType, EdgeType >::inEnd ( ) const -> const_in_iterator
inline

◆ isEqualTo()

template<class NodeType, class EdgeType>
auto slang::netlist::Node< NodeType, EdgeType >::isEqualTo ( const NodeType & node) const -> bool
inlineprotected

◆ operator=() [1/2]

template<class NodeType, class EdgeType>
auto slang::netlist::Node< NodeType, EdgeType >::operator= ( const Node< NodeType, EdgeType > & ) -> Node &=delete
delete

◆ operator=() [2/2]

template<class NodeType, class EdgeType>
auto slang::netlist::Node< NodeType, EdgeType >::operator= ( Node< NodeType, EdgeType > && ) -> Node &=delete
delete

◆ operator==()

template<class NodeType, class EdgeType>
auto slang::netlist::Node< NodeType, EdgeType >::operator== ( const NodeType & N) const -> bool
inline

◆ outDegree()

template<class NodeType, class EdgeType>
auto slang::netlist::Node< NodeType, EdgeType >::outDegree ( ) const -> size_t
inline

Return the total number of edges outgoing from this node.

◆ removeEdge()

template<class NodeType, class EdgeType>
auto slang::netlist::Node< NodeType, EdgeType >::removeEdge ( NodeType & targetNode) -> bool
inline

Remove an edge between this node and a target node. Return true if the edge existed and was removed, and false otherwise.

◆ operator==

template<class NodeType, class EdgeType>
auto operator== ( NodeType const & A,
NodeType const & B ) -> bool
friend

Static polymorphism: delegate implementation (via isEqualTo) to the derived class. Add friend operator to resolve ambiguity between operand ordering with C++20.

Member Data Documentation

◆ edgeMutex

template<class NodeType, class EdgeType>
std::mutex slang::netlist::Node< NodeType, EdgeType >::edgeMutex
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.

◆ inEdges

template<class NodeType, class EdgeType>
InEdgeListType slang::netlist::Node< NodeType, EdgeType >::inEdges
protected

◆ outEdgeIndex

template<class NodeType, class EdgeType>
std::unique_ptr<OutEdgeIndex> slang::netlist::Node< NodeType, EdgeType >::outEdgeIndex
protected

◆ outEdgeIndexThreshold

template<class NodeType, class EdgeType>
size_t slang::netlist::Node< NodeType, EdgeType >::outEdgeIndexThreshold = 16
staticconstexprprotected

Out-degree at which we switch from linear scans of outEdges to the lazily-allocated outEdgeIndex map.

◆ outEdges

template<class NodeType, class EdgeType>
OutEdgeListType slang::netlist::Node< NodeType, EdgeType >::outEdges
protected

The documentation for this class was generated from the following file: