Mojo · Graphs

Graphs

from ustore import VertexRole, Edges, GraphScanConfig, … 1.0.0-rc.1 · d6d40961

An edge is a source, a target and an optional edge identifier, so distinct identifiers let a pair of vertices share several edges. One collection holds an undirected or a directed graph over its own vertices, or a joining graph between two collections.

API

Types

VertexRolesViewA strided run of roles, ustore_vertex_roles_view_t; zeroed stands for ANY.
comptime VertexRolesView[origin: ImmOrigin = ImmUntrackedOrigin]: AnyStruct[StridedView[VertexRole, origin]] = StridedView[VertexRole, origin]
StructVertexRoleThe role a vertex plays in an edge, ustore_vertex_role_t; undirected graphs use ANY.
struct VertexRole

Fields

codec_intThe raw ustore_vertex_role_t value the ABI exchanges.

Values

UNKNOWNVertexRole(Int32(0))No role.
SOURCEVertexRole(Int32(1))The vertex an edge leaves.
TARGETVertexRole(Int32(2))The vertex an edge enters.
ANYVertexRole(Int32(3))Either end of an edge.

Conforms to

Copyable, Deinitable, Equatable, ImplicitlyCopyable, Movable, RegisterPassable, TrivialRegisterPassable
StructEdgesThe edges of a batch of vertices, three keys per edge, read in place from the arena a read borrows.5
struct Edges[origin: MutOrigin]

Parameters

originMutOrigincomptimeThe arena the edges live in, which this result borrows.

Fields

arenaPointer[Arena, origin]The arena holding the edges.
generationIntThe arena's call the edges came from.
writtenEdgesWrittenThe views the engine wrote.
countIntVertices the read carried.

Values

WrittenEdgesWritten

Conforms to

Answer, Deinitable, Movable, Sized
__init__
def __init__(out self, arena: Int, generation: Int, written: EdgesWritten, count: Int)
__len__The vertices the read carried.
def __len__(self) -> Int
degreesThe degree of every vertex, VERTEX_DEGREE_MISSING for a missing one.
def degrees(ref self) -> Span[UInt32, origin_of(self)]
offsetsThe vertices' boundaries in edges, one more of them than vertices; empty unless edges were asked for.
def offsets(ref self) -> Span[UInt64, origin_of(self)]
edgesThe edges of vertex vertex, each as its source, target and edge identifier.
def edges(ref self, vertex: Int) -> Span[Key, origin_of(self)]
StructGraphScanConfigThe bounds, order and verdict of a scan over vertices.1
struct GraphScanConfig[end_origin: ImmOrigin = ImmUntrackedOrigin]

Parameters

end_originImmOrigincomptimeThe borrowed end keys.

Fields

end_keysStridedView[Key, end_origin]Vertex every scan stops before, exclusive; zeroed bounds nothing.
directionScanDirectionAscending or descending from the start keys.
modeScanModeIn what order the vertices come.
predicatePredicateThe caller's verdict on the listed vertices.
progressProgressReports the scans finished, and stops the call where it says to.

Conforms to

Copyable, Deinitable, ImplicitlyCopyable, Movable
__init__Names only the knobs that differ from the defaults.
def __init__(
    out self,
    *,
    end_keys: StridedView[Key, end_origin] = StridedView(),
    direction: ScanDirection = ScanDirection.ASCENDING,
    mode: ScanMode = ScanMode.ORDERED,
    predicate: Predicate = Predicate(),
    progress: Progress = Progress()
)
StructGraphVerticesCursorA walk over the vertices of one graph collection, every pull resuming past the last vertex the pull before it handed out, freed when it goes out of scope. It holds its database open, and the transaction or snapshot it reads through.3
struct GraphVerticesCursor

Fields

libraryLibraryThe loaded engine.
databaseAddressThe ustore_database_t it walks.
addressAddressThe ustore_graph_vertices_cursor_t.

Conforms to

Deinitable, Movable
__init__Adopts a cursor the engine just opened.
def __init__(out self, *, library: Library, database: Int, address: Int)
__deinit__Frees the cursor and the holds it kept. Calls ustore_graph_vertices_cursor_free.
def __deinit__(deinit self)
nextPulls the next page of up to wanted vertices. Calls ustore_graph_vertices_cursor_next.
def next(
    self,
    executor: Executor,
    mut arena: Arena,
    wanted: Int,
    progress: Progress = Progress()
) -> Pulled[origin_of(arena)]

Raises

Error with CANCELLED when progress stops the pull, which leaves the cursor where it was.

Constants

VERTEX_DEGREE_MISSINGThe degree a read reports for a missing vertex.
comptime VERTEX_DEGREE_MISSING = UInt32(4294967295)