edgegraph.structure.vertex.Vertex#

class edgegraph.structure.vertex.Vertex(*, links=None, uid=None, attributes=None, universes=None)#

Bases: BaseObject

Represents a vertex in an edge-vertex graph.

This class is a base class for anything that needs to “relate to” something else – another instance, or completely different types (as long as they both subclass this one, at some level).

__init__(*, links=None, uid=None, attributes=None, universes=None)#

Creates a new vertex.

Unlike BaseObject, the Vertex class will add itself to Universes provided to this method.

Parameters:

links (list[Link] | None) – iterable of link objects to associate this vertex with

See also

Methods

__init__(*[, links, uid, attributes, universes])

Creates a new vertex.

add_to_link(link)

Add this vertex to a link.

add_to_universe(universe)

Adds this object to a new universe.

remove_from_link(link)

Remove this vertex from a link.

remove_from_universe(universe)

Remove this vertex from the specified universe.

total_cache_stats()

Return a ready-to-print summary of caching statistics.

Attributes

NEIGHBOR_CACHING

Enable / disable neighbor caching program-wide.

links

Return a tuple of links that are attached to this object.

uid

Get the UID of this object.

universes

Get the universes this object belongs to.

NEIGHBOR_CACHING: bool = False#

Enable / disable neighbor caching program-wide.

See also

Vertex neighbor caching for more information on usage

Add this vertex to a link.

Roughly equivalent to calling the Link’s add_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 == vs is comparison. == duplicate links are allowed, is duplicate links are ignored.

Parameters:

link (Link) – the link to add this vertex to

add_to_universe(universe)#

Adds 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

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.

Remove this vertex from a link.

Parameters:

link (Link) – the link to remove this vertex from.

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.

Parameters:

universe (Universe) – the universe that this vertex will be removed from

Raises:

KeyError – if this object is not present in the given universe

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

Returns:

Human-readable string indicating size, hits, misses, invalidations, and insertions to the vertex neighbor cache.

Return type:

str

property uid: int#

Get the UID of this object.

property universes: frozenset[Universe]#

Get the universes this object belongs to.

Note that this gives you a frozenset; you cannot add or remove universes from this attribute.

See also

add_to_universe(), remove_from_universe() to add or remove this object from a given universe