7.4.6. Class Edge¶
An edge represents a relationship between the concepts mapped onto the nodes of the graph (e. g. a call relationship between two functions is expressed by a call edge between the nodes representing the two functions).
7.4.6.1. Obtaining an Edge¶
The constructor of class Edge returns either a new edge of type edge_type or the type in graph named edge_type_name respectively. An edge type can be acquired from the graph by using instance method edge_type, see Section Node and Edge Types. The third flavor of the constructor returns an existing edge of graph that matches the hash_value.
If a new edge is constructed, it is not contained in any view but it is already part of the graph. You have to insert it into a view. An edge as part of the RFG graph is automatically garbage collected when it is removed from the last view that contains it.
Caution
If you remove an edge from the last view it has been contained in, the edge is automatically garbage collected immediately. So make sure you first add an edge to a target view before removing it from a source view if you intend to transfer the edge between two views.
Note
If you created a new edge and want to get rid of it, you have to insert it into a view and remove it from that view. The edge will be garbage collected after the removal.
Caution
Edges contained in sets are not removed from the sets once they are garbage collected from an RFG.
All methods of the RFG interface that return edges return values of class Edge.
7.4.6.2. General Operations¶
graph()
Instance method graph returns the graph the edge is part of.
__str__()
Instance method __str__ returns a textual representation of the edge (only for debugging purposes). For user output, use the general attribute handling methods.
The two instance methods __eq__ and __ne__ check for equality respectively inequality of two edges.
Ordinarily, both functions are called by way of the == and != operators.
7.4.6.3. Hashing of Edges¶
__hash__()
The hash function is used for dictionaries. Hash values change between multiple runs of a script. They cannot be used for persistence.
7.4.6.4. Type of an Edge¶
The edge_type instance method returns the type of the edge which is represented as EdgeType. The instance method is_of_type takes a type descriptor or a string representing the name of the type as argument and checks whether the edge is of the given type (and not of a subtype). Instance method is_of_subtype includes subtypes (children) of the given type in the check. Instance method mutate changes the type of an edge.
7.4.6.5. Value Handling for Attributes¶
For a full explanation of the attribute handling, see Section Attributes.
Caution
An edge has to be inserted in at least one view of a graph before one can set values of attributes at that edge.
7.4.6.6. Membership in the View¶
Instance methods insert and add make the edge to be contained in the argument view. Instance method remove removes the edge from a view.
Note
Inserting an edge into a view also inserts the source and the target node of the edge if not already contained in the view.
Caution
If you remove an edge from the last view it has been contained in, the edge is automatically garbage collected immediately. So make sure you first add an edge to a target view before removing it from a source view if you intend to transfer the edge between two views.
The class View features a __contains__ method that can be used for checking whether an edge is contained in a view.
7.4.6.7. Querying the Neighborhood of Edges¶
The instance method attached returns a node set. The instance methods source and target return single nodes.
If parameter node_matcher is used, only nodes matching the node matcher are returned. In case of source and target, ’None’ is returned if the source/target node does not match the node matcher.