proxygen
deadlock.DiGraph Class Reference
Inheritance diagram for deadlock.DiGraph:

Public Member Functions

def __init__ (self)
 
def neighbors (self, node)
 
def edges (self)
 
def nodes (self)
 
def attributes (self, node1, node2)
 
def add_edge (self, node1, node2, kwargs)
 
def remove_node (self, node)
 
def subgraph (self, nodes)
 
def node_link_data (self)
 

Public Attributes

 adjacency_map
 
 attributes_map
 

Detailed Description

Adapted from networkx: http://networkx.github.io/
Represents a directed graph. Edges can store (key, value) attributes.

Definition at line 9 of file deadlock.py.

Constructor & Destructor Documentation

def deadlock.DiGraph.__init__ (   self)

Definition at line 15 of file deadlock.py.

15  def __init__(self):
16  # Map of node -> set of nodes
17  self.adjacency_map = {}
18  # Map of (node1, node2) -> map string -> arbitrary attribute
19  # This will not be copied in subgraph()
20  self.attributes_map = {}
21 
def __init__(self)
Definition: deadlock.py:15

Member Function Documentation

def deadlock.DiGraph.add_edge (   self,
  node1,
  node2,
  kwargs 
)

Definition at line 38 of file deadlock.py.

References add, deadlock.DiGraph.adjacency_map, and deadlock.DiGraph.attributes_map.

38  def add_edge(self, node1, node2, **kwargs):
39  if node1 not in self.adjacency_map:
40  self.adjacency_map[node1] = set()
41  if node2 not in self.adjacency_map:
42  self.adjacency_map[node2] = set()
43  self.adjacency_map[node1].add(node2)
44  self.attributes_map[(node1, node2)] = kwargs
45 
auto add
Definition: BaseTest.cpp:70
def add_edge(self, node1, node2, kwargs)
Definition: deadlock.py:38
Definition: Traits.h:592
def deadlock.DiGraph.attributes (   self,
  node1,
  node2 
)

Definition at line 35 of file deadlock.py.

References deadlock.DiGraph.attributes_map.

35  def attributes(self, node1, node2):
36  return self.attributes_map[(node1, node2)]
37 
def attributes(self, node1, node2)
Definition: deadlock.py:35
def deadlock.DiGraph.edges (   self)

Definition at line 25 of file deadlock.py.

25  def edges(self):
26  edges = []
27  for node, neighbors in self.adjacency_map.items():
28  for neighbor in neighbors:
29  edges.append((node, neighbor))
30  return edges
31 
def edges(self)
Definition: deadlock.py:25
def deadlock.DiGraph.neighbors (   self,
  node 
)

Definition at line 22 of file deadlock.py.

Referenced by deadlock.DiGraph.subgraph().

22  def neighbors(self, node):
23  return self.adjacency_map.get(node, set())
24 
def neighbors(self, node)
Definition: deadlock.py:22
Definition: Traits.h:592
def deadlock.DiGraph.node_link_data (   self)
Returns the graph as a dictionary in a format that can be
serialized.

Definition at line 59 of file deadlock.py.

References append(), deadlock.DiGraph.attributes_map, and folly.copy().

59  def node_link_data(self):
60  '''
61  Returns the graph as a dictionary in a format that can be
62  serialized.
63  '''
64  data = {
65  'directed': True,
66  'multigraph': False,
67  'graph': {},
68  'links': [],
69  'nodes': [],
70  }
71 
72  # Do one pass to build a map of node -> position in nodes
73  node_to_number = {}
74  for node in self.adjacency_map.keys():
75  node_to_number[node] = len(data['nodes'])
76  data['nodes'].append({'id': node})
77 
78  # Do another pass to build the link information
79  for node, neighbors in self.adjacency_map.items():
80  for neighbor in neighbors:
81  link = self.attributes_map[(node, neighbor)].copy()
82  link['source'] = node_to_number[node]
83  link['target'] = node_to_number[neighbor]
84  data['links'].append(link)
85  return data
86 
87 
void append(std::unique_ptr< IOBuf > &buf, StringPiece str)
Definition: IOBufTest.cpp:37
def node_link_data(self)
Definition: deadlock.py:59
constexpr std::decay< T >::type copy(T &&value) noexcept(noexcept(typename std::decay< T >::type(std::forward< T >(value))))
Definition: Utility.h:72
def deadlock.DiGraph.nodes (   self)

Definition at line 32 of file deadlock.py.

32  def nodes(self):
33  return self.adjacency_map.keys()
34 
def nodes(self)
Definition: deadlock.py:32
def deadlock.DiGraph.remove_node (   self,
  node 
)

Definition at line 46 of file deadlock.py.

46  def remove_node(self, node):
47  self.adjacency_map.pop(node, None)
48  for _, neighbors in self.adjacency_map.items():
49  neighbors.discard(node)
50 
def remove_node(self, node)
Definition: deadlock.py:46
def deadlock.DiGraph.subgraph (   self,
  nodes 
)

Definition at line 51 of file deadlock.py.

References deadlock.DiGraph.neighbors().

51  def subgraph(self, nodes):
52  graph = DiGraph()
53  for node in nodes:
54  for neighbor in self.neighbors(node):
55  if neighbor in nodes:
56  graph.add_edge(node, neighbor)
57  return graph
58 
def neighbors(self, node)
Definition: deadlock.py:22
def subgraph(self, nodes)
Definition: deadlock.py:51

Member Data Documentation

deadlock.DiGraph.adjacency_map

Definition at line 17 of file deadlock.py.

Referenced by deadlock.DiGraph.add_edge().

deadlock.DiGraph.attributes_map

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