edgegraph.structure.universe.Universe#
- class edgegraph.structure.universe.Universe(*, vertices=None, uid=None, attributes=None)#
Bases:
VertexRepresents a universe that can contain vertices and links.
This is the container of vertices. It may also reasonably be called a “graph” object – the collection of all edges and vertices under examination at any given moment. However, it is more flexible in implementation, and can actually contain any subclass of
BaseObject(though they may not appear in graph-related operations, such as traversals or searches, if they do not subclassVertex.)Pay attention that this class itself is a subclass of
Vertex; this means that while containing an entire graph (or more) on its own, this object can also be treated as a vertex inside another universe. In this way, you can create graphs of other graphs, even recursively if you like. Whether or not this is a good idea greatly depends on the situation, but the implementation allows it (this is a feature, not an implementation detail).- __init__(*, vertices=None, uid=None, attributes=None)#
Instantiate a Universe.
See also
edgegraph.structure.vertex.Vertex.__init__(), the superclass constructor
Methods
__init__(*[, vertices, uid, attributes])Instantiate a Universe.
add_to_link(link)Add this vertex to a link.
add_to_universe(universe)Add this object to a new universe.
add_vertex(vert)Add a new vertex to this universe.
remove_from_link(link)Remove this vertex from a link.
remove_from_universe(universe)Remove this vertex from the specified universe.
remove_vertex(vert)Remove a vertex from this universe.
Return a ready-to-print summary of caching statistics.
Attributes
Enable / disable neighbor caching program-wide.
Return a tuple of links that are attached to this object.
Get the UID of this object.
Get the universes this object belongs to.
Return a list of vertices that this universe contains.
- NEIGHBOR_CACHING: bool = False#
Enable / disable neighbor caching program-wide.
See also
Vertex neighbor caching for more information on usage
- add_to_link(link)#
Add this vertex to a link.
Roughly equivalent to calling the
Link’sadd_vertex()with this object as an argument.If the given link is already associated with this vertex, no action is taken.
Attention
Duplicate links ARE allowed! However, the same link twice is not. The difference is that of a
==vsiscomparison.==duplicate links are allowed,isduplicate links are ignored.- Parameters:
link (Link) – the link to add this vertex to
- Concurrency:
Thread-safe
- add_to_universe(universe)#
Add this object to a new universe.
If it is already there, no action is taken.
In addition to the action(s) taken by the superclass (
add_to_universe()), this method also adds this vertex to the universes’ reference of vertices, if needed.- Parameters:
universe (Universe) – the new universe to add this object to
- Concurrency:
Thread-safe.
- add_vertex(vert)#
Add a new vertex to this universe.
The vertex in question will automatically have its universes updated to include this one, if needed. If the vertex is already present, no action is taken.
See also
verticesto see what vertices are present in this universe, andremove_vertex()to remove a vertex.- Parameters:
vert (Vertex) – the vertex to be added
- property links: tuple[Link, ...]#
Return a tuple of links that are attached to this object.
A tuple is given specifically to prevent the addition or removal of link objects using this attribute; it is intended to be immutable.
- Concurrency:
Thread-safe
- remove_from_link(link)#
Remove this vertex from a link.
- Parameters:
link (Link) – the link to remove this vertex from.
- Concurrency:
Thread-safe
- remove_from_universe(universe)#
Remove this vertex from the specified universe.
In addition to the superclass method, also removes the vertex from the universe’s record of vertices as well as simply removing the universe from this vertices’ record of universes if necessary.
- remove_vertex(vert)#
Remove a vertex from this universe.
The vertex in question will be removed from this universe’s record of vertices. If necessary. this universe will then be removed from the vertices’ record of universes as well.
- Parameters:
vert (Vertex) – the vertex to be removed
- classmethod total_cache_stats()#
Return a ready-to-print summary of caching statistics.
This function can be used to get human-readable cache statistics for the quick-access neighbor caching. It returns a string intended to be printed, logged, or written to file (it does not do anything other than build the string on its own).
See also
Vertex neighbor caching for more on caching
NEIGHBOR_CACHINGto enable / disable it
- Returns:
Human-readable string indicating size, hits, misses, invalidations, and insertions to the vertex neighbor cache.
- Concurrency:
Thread-safe
- Return type:
- property universes: list[Universe]#
Get the universes this object belongs to.
Note that the copy returned is just that, a copy. Modifications to this list that you may make will have no effect on the object.
See also
add_to_universe(),remove_from_universe()to add or remove this object from a given universe
- property vertices: list[Vertex]#
Return a list of vertices that this universe contains.
Note that the returned copy is just that, a copy. Modifications to the list that you may make will have no impact to the universe.
See also
add_vertex()can be used to add a vertex, andremove_vertex()can be used to remove one.- Returns:
vertices belonging to this universe, ordered by insertion order.