Template Class NodeView

Template Parameter Order

  1. typename nodeview_t

Class Documentation

template<typename nodeview_t>
class NodeView

A NodeView class to act as G.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

G = xn::path_graph(3); NV = G.nodes(); 2 : NV

true

for n : NV: print(n);

0 1 2

assert(NV & {1, 2, 3} == {1, 2}); G.add_node(2, color=”blue”); NV[2];

{“color”: “blue”}

G.add_node(8, color=”red”); NDV = G.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 = G.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

Public Functions

inline explicit NodeView(nodeview_t &nodes)
inline auto size()
inline auto begin()
inline auto end()
inline auto operator[](const Node &n)
inline bool contains(const Node &n)