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

class Edge(edge_type)
class Edge(graph, edge_type_name)
class Edge(graph, edge_id)

The constructor of class Edge returns either a new edge of type edge_type or a new edge of the type named edge_type_name in graph. An edge type can be acquired from the graph by using the instance method edge_type; see Section Node and Edge Types. The third variant of the constructor returns the existing edge in graph whose id is edge_id. It raises ValueError if no such edge exists.

If a new edge is constructed, it is not contained in any view, but it is already part of the graph. You must 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 containing it, the edge is immediately garbage collected. Therefore, ensure 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

To remove a newly created edge, you must first insert it into a view and then remove it from that view. The edge will be garbage collected after the removal.

Caution

Edges contained in sets are not removed from those 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()

The instance method graph returns the graph the edge is part of.

id()

The instance method id returns the number identifying the edge within its graph; see the constructor of class Edge.

__str__()

The instance method __str__ returns a textual representation of the edge (for debugging purposes only). For user output, use the general attribute handling methods.

__eq__(other)
__ne__(other)

The instance methods __eq__ and __ne__ check for the equality and inequality of two edges, respectively.

Typically, both methods are called using the == and != operators.

7.4.6.3. Hashing of Edges

__hash__()

The hash function is used for dictionaries. Hash values may change between runs of a script and cannot be used for persistence.

7.4.6.4. Type of an Edge

edge_type()
is_of_type(descriptor)
is_of_subtype(descriptor)
mutate(descriptor)

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 an argument and checks whether the edge is of the given type (and not of a subtype). The instance method is_of_subtype includes subtypes (children) of the given type in the check. The instance method mutate changes the type of an edge.

7.4.6.5. Value Handling for Attributes

For a full explanation of attribute handling, see Section Attributes.

has_key(key)
__getitem__(key)
__setitem__(key, value)
__delitem__(key)
__iter__()
keys()
items()
get_string_list(key)
set_string_list(key, value)
append_to_string_list(key, value)
These instance methods query and manipulate attributes of an edge. has_key checks whether attribute key is set, __getitem__ retrieves the stored value for attribute key, and __setitem__ sets a new value for the attribute. __iter__ iterates through the set attributes as name-value pairs. keys returns a list of the names of all set attributes. items returns a list of all set key-value pairs (where keys are strings). get_string_list interprets the string attribute as a list and returns it. set_string_list stores a string representation of the given string list. append_to_string_list appends the given string to the string list stored in the attribute.

7.4.6.6. Membership in the View

insert(view)
add(view)
remove(view)

The instance methods insert and add add the edge to the specified view. The instance method remove removes the edge from a view.

Note

Inserting an edge into a view also inserts the source and target nodes of the edge if they are not already contained in the view.

Caution

If you remove an edge from the last view containing it, the edge is immediately garbage collected. Therefore, ensure 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 to check whether an edge is contained in a view.

7.4.6.7. Querying the Neighborhood of Edges

attached([node_matcher])
source([node_matcher])
target([node_matcher])
These instance methods perform the operations described in Section Querying the Neighborhood of Nodes and Edges.

The instance method attached returns a node set. The instance methods source and target return single nodes.

If the node_matcher parameter is used, only nodes matching the matcher are returned. For source and target, None is returned if the source or target node does not match the node matcher.