Go · Graphs

Graphs

import "github.com/unum-cloud/ustore" 1.0.0-rc.1 · 084197c4

Ask your coding agent about this page, or add the docs server to it

curl -s 'https://www.unum.cloud/docs/ustore/go/graphs.md' | claude -p "How would this fit my code?"

A graph collection, created with ModalityGraph, indexes every edge from both of its vertices, and an Edge is laid out as the source, target and identifier keys the ABI puts on its tapes, so a slice of edges crosses as three strided columns. GraphReadEdges answers Neighborhoods, the degree of every vertex and its edges, outgoing ones before incoming ones, and Edge.Neighbor names the other end. A VertexRole gives the whole batch one role and VertexRoles gives every vertex its own.

follows, err := database.CollectionCreate("follows", ustore.ModalityGraph)
edges := []ustore.Edge{
	{Source: first, Target: second, ID: ustore.EdgeIDDefault},
	{Source: first, Target: third, ID: ustore.EdgeIDDefault},
	{Source: second, Target: third, ID: seventh},
}
err = database.GraphWriteEdges(follows, edges, nil)

vertices := []ustore.Key{first, third}
found, err := database.GraphReadEdges(follows, vertices, ustore.VertexRoleAny, arena)
for index, vertex := range vertices {
	for _, edge := range found.Edges(uint(index)) {
		fmt.Println(vertex, "meets", edge.Neighbor(vertex))
	}
}
err = database.GraphRemoveVertices(follows, []ustore.Key{first}, nil)

API

Types

GraphRemoveVerticesConfigGraphRemoveVerticesConfig carries the optional arguments of DatabaseOn.GraphRemoveVertices.
db.go:339 ↗
type GraphRemoveVerticesConfig struct {
    EndVertices []Key
    Roles Roles
    Durability Durability
}

Fields

EndVertices[]KeyEndVertices turns every vertex into the inclusive start of a range ending before its end vertex, one per task, or removes the vertices alone when empty.
RolesRolesRoles are the roles of the vertices, needed only by joining graphs.
DurabilityDurabilityDurability is how durable the removals are once the call finishes at the head.
GraphScanConfigGraphScanConfig carries the optional arguments of DatabaseOn.GraphScanVertices.
db.go:396 ↗
type GraphScanConfig struct {
    StartKeys []Key
    EndKeys []Key
    Direction ScanDirection
    Predicate Admitter
    Mode ScanMode
    Progress ProgressCallback
}

Fields

StartKeys[]KeyStartKeys are the inclusive starts of the scans, one per task, or the first vertex in Direction when empty.
EndKeys[]KeyEndKeys are the vertices every scan stops before, one per task, or no bound when empty.
DirectionScanDirectionDirection is which way every scan goes from its start.
PredicateAdmitterPredicate admits or passes over the listed vertices.
ModeScanModeMode is in what order the vertices come.
ProgressProgressCallbackProgress reports the scans finished, and may cancel the call.
GraphVerticesCursorConfigGraphVerticesCursorConfig carries the optional arguments of DatabaseOn.GraphVerticesCursorInit.
db.go:468 ↗
type GraphVerticesCursorConfig struct {
    EndKey *Key
    Direction ScanDirection
    Predicate Admitter
}

Fields

EndKey*KeyEndKey is the vertex the walk stops before, or nil for no bound.
DirectionScanDirectionDirection is which way the walk goes from its start.
PredicateAdmitterPredicate admits or passes over the vertices of every page.
RolesRoles names the role of every vertex in a batch: a VertexRole the whole batch shares, or VertexRoles, one per vertex; nil stands for VertexRoleAny.
db.go:85 ↗
type Roles interface {
    // contains filtered or unexported methods
}
VertexRolesVertexRoles names one role per vertex of a batch.
db.go:90 ↗
type VertexRoles []VertexRole
StructEdgeEdge is a source, a target and an edge identifier, laid out as the three keys the library puts on its tapes, so a slice of edges crosses as three strided columns.1
graph.go:40 ↗
type Edge struct {
    Source Key
    Target Key
    ID     Key
}
NeighborNeighbor reports the end of the edge other than vertex.
graph.go:50 ↗
func (edge Edge) Neighbor(vertex Key) Key
StructNeighborhoodsNeighborhoods is the degree and the edges of every vertex a read named, readable until the arena serves another call.3
graph.go:135 ↗
type Neighborhoods struct {
    // contains filtered or unexported fields
}
DegreeDegree reports how many edges vertex index connects to, and false for a missing vertex.
graph.go:150 ↗
func (neighborhoods Neighborhoods) Degree(
    index uint,
) (uint32, bool)
EdgesEdges views the edges of vertex index in the arena: with both roles the outgoing ones first, sorted by target, then the incoming ones, sorted by source.
graph.go:159 ↗
func (neighborhoods Neighborhoods) Edges(index uint) []Edge
LenLen reports how many vertices the call read.
graph.go:144 ↗
func (neighborhoods Neighborhoods) Len() uint
EnumVertexRoleVertexRole is the role a vertex plays in the edges a call names.2
graph.go:58 ↗
type VertexRole int32

Values

VertexRoleUnknownVertexRoleUnknown is no role.
VertexRoleSourceVertexRoleSource is the vertex an edge leaves.
VertexRoleTargetVertexRoleTarget is the vertex an edge enters.
VertexRoleAnyVertexRoleAny is either end of an edge.
VertexRoleFromNameVertexRoleFromName reads a role back from the spelling VertexRole.String renders.
graph.go:77 ↗
func VertexRoleFromName(name string) (VertexRole, error)
StringString renders the role as the library spells it.
graph.go:72 ↗
func (role VertexRole) String() string

Constants

EdgeIDDefaultEdgeIDDefault is the identifier of an edge that was given none, every bit of it set.
db.go:47 ↗
var EdgeIDDefault = KeyUnknown