MCPcopy
hub / github.com/networkx/networkx / OutEdgeView

Class OutEdgeView

networkx/classes/reportviews.py:1048–1192  ·  view source on GitHub ↗

A EdgeView class for outward edges of a DiGraph

Source from the content-addressed store, hash-verified

1046
1047# EdgeViews have set operations and no data reported
1048class OutEdgeView(Set, Mapping, EdgeViewABC):
1049 """A EdgeView class for outward edges of a DiGraph"""
1050
1051 __slots__ = ("_adjdict", "_graph", "_nodes_nbrs")
1052
1053 def __getstate__(self):
1054 return {"_graph": self._graph, "_adjdict": self._adjdict}
1055
1056 def __setstate__(self, state):
1057 self._graph = state["_graph"]
1058 self._adjdict = state["_adjdict"]
1059 self._nodes_nbrs = self._adjdict.items
1060
1061 @classmethod
1062 def _from_iterable(cls, it):
1063 return set(it)
1064
1065 dataview = OutEdgeDataView
1066
1067 def __init__(self, G):
1068 self._graph = G
1069 self._adjdict = G._succ if hasattr(G, "succ") else G._adj
1070 self._nodes_nbrs = self._adjdict.items
1071
1072 # Set methods
1073 def __len__(self):
1074 return sum(len(nbrs) for n, nbrs in self._nodes_nbrs())
1075
1076 def __iter__(self):
1077 for n, nbrs in self._nodes_nbrs():
1078 for nbr in nbrs:
1079 yield (n, nbr)
1080
1081 def __contains__(self, e):
1082 try:
1083 u, v = e
1084 return v in self._adjdict[u]
1085 except KeyError:
1086 return False
1087
1088 # Mapping Methods
1089 def __getitem__(self, e):
1090 if isinstance(e, slice):
1091 raise nx.NetworkXError(
1092 f"{type(self).__name__} does not support slicing, "
1093 f"try list(G.edges)[{e.start}:{e.stop}:{e.step}]"
1094 )
1095 u, v = e
1096 try:
1097 return self._adjdict[u][v]
1098 except KeyError as ex: # Customize msg to indicate exception origin
1099 raise KeyError(f"The edge {e} is not in the graph.")
1100
1101 # EdgeDataView methods
1102 def __call__(self, nbunch=None, data=False, *, default=None):
1103 if nbunch is None and data is False:
1104 return self
1105 return self.dataview(self, nbunch, data, default=default)

Callers 2

edgesMethod · 0.90
out_edgesMethod · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…