template<typename nodeview_t>
NodeView class
A NodeView class to act as gra.nodes for a XNetwork Graph Set operations act on the nodes without considering data. Iteration is over nodes. Node data can be looked up like a dict. Use NodeDataView to iterate over node data or to specify a data attribute for lookup. NodeDataView is created by calling the NodeView.
Parameters
graph : XNetwork graph-like class
Examples
> gra = xnetwork::path_graph(3); > NV = gra.nodes(); > 2 : NV true > for n : NV: print(n); 0 1 2 > assert(NV & {1, 2, 3} == {1, 2}); > gra.add_node(2, color="blue"); > NV[2]; {"color": "blue"} > gra.add_node(8, color="red"); > NDV = gra.nodes(data=true); > (2, NV[2]] : NDV true > for n, dd : NDV: print((n, dd.get("color", "aqua"))); (0, "aqua"); (1, "aqua"); (2, "blue"); (8, "red"); > NDV[2] == NV[2]; true > NVdata = gra.nodes(data="color", default="aqua"); > (2, NVdata[2]] : NVdata true > for n, dd : NVdata: print((n, dd)); (0, "aqua"); (1, "aqua"); (2, "blue"); (8, "red"); > NVdata[2] == NV[2]; // NVdata gets "color", NV gets datadict false
Constructors, destructors, conversion operators
Public functions
- auto size() const -> auto
- Get the number of nodes in the view.
- auto begin() const -> auto
- Get iterator to the beginning of the view.
- auto end() const -> auto
- Get iterator to the end of the view.
- auto operator[](const Node& node) const -> const auto & -> auto
- Access node data at specified node (const version)
- auto operator[](const Node& node) -> auto & -> auto
- Access node data at specified node (non-const version)
- auto contains(const Node& node) const -> bool -> auto
- Check if a node exists in the view.
Function documentation
template<typename nodeview_t>
auto xnetwork:: NodeView<nodeview_t>:: size() const
Get the number of nodes in the view.
| Returns | The size of the node container |
|---|
template<typename nodeview_t>
auto xnetwork:: NodeView<nodeview_t>:: begin() const
Get iterator to the beginning of the view.
| Returns | Iterator to the first node |
|---|
template<typename nodeview_t>
auto xnetwork:: NodeView<nodeview_t>:: end() const
Get iterator to the end of the view.
| Returns | Iterator past the last node |
|---|
template<typename nodeview_t>
auto xnetwork:: NodeView<nodeview_t>:: operator[](const Node& node) const -> const auto &
Access node data at specified node (const version)
| Parameters | |
|---|---|
| node | The node to access |
| Returns | Const reference to the node data |
template<typename nodeview_t>
auto xnetwork:: NodeView<nodeview_t>:: operator[](const Node& node) -> auto &
Access node data at specified node (non-const version)
| Parameters | |
|---|---|
| node | The node to access |
| Returns | Reference to the node data |
template<typename nodeview_t>
auto xnetwork:: NodeView<nodeview_t>:: contains(const Node& node) const -> bool
Check if a node exists in the view.
| Parameters | |
|---|---|
| node | The node to check for |
| Returns | true if the node exists, false otherwise |