On this page
Verada.Containers.Graphs
A directed graph proved whole as a proof enclave.
Read the family guide for representation, ownership and cost rules. The complete declaration page retains exact signatures/contracts; the source specification is the implementation baseline.
Availability and ownership
A vertex is shared by every edge into it and edges may make cycles, which ownership forbids outside an enclave; the heap engine proves each operation against Model and proves that it changes only its own graph's cells, so clients reason about a graph as its model. Only memory limits the vertices and a vertex's edges: the table of vertices and each vertex's links double when full, and Add_Vertex and Add_Edge raise Storage_Error when memory cannot hold one more (Verada.Storage). It is limited: not copied by assignment, and cleared when it ends.
Import
with Verada.Containers.Graphs;import Verada.Containers.Graphs;
A Vibe module imports this unit's names with from Verada.Containers.Graphs import Name; see library use across syntaxes. In Varc, keep each name's declared spelling and write & on arguments the call changes.
API 001
Vertex_Count_Type (declaration) — A number of vertices, a Natural.
API 002
Vertex (declaration) — A vertex, by its number: vertices are numbered 1 .. the count, in the order they were added.
API 003
Degree_Type (declaration) — A vertex's out-degree, a Natural.
API 004
Edge (declaration) — An edge, from a vertex to a vertex (to itself when they are the same).
API 005
Edge_Sequences (declaration) — The functional sequences of edges the model uses.
API 006
Degree_Sequences (declaration) — The functional sequences of degrees the model uses.
API 007
Graph_Model (declaration) — A graph's value: the out-degree of each vertex (the vertices are 1 .. the length of Degrees) and the edges, each once, in the order they were added.
API 008
Graph (declaration) — A directed graph: limited, empty by default, cleared (every cell freed) when it ends. Its vertices are cells shared by every edge into them, and edges may make cycles; the heap engine proves its operations against Model.
Its default initial condition:
Degree_Sequences.Length (Model (Graph).Degrees) = 0
and then Edge_Sequences.Length (Model (Graph).Edges) = 0API 009
Model (declaration) — The graph's value, a ghost Graph_Model, in which the other contracts are stated.
Ghost: for contracts and ghost code, and left out of the program.
API 010
Vertex_Count (declaration) — The number of vertices.
On normal return the declared contract establishes:
Vertex_Count'Result = Degree_Sequences.Length (Model (G).Degrees)
and then Vertex_Count'Result < Verada.Storage.Length_BoundAPI 011
Has_Edge (declaration) — Whether a model has an edge from From to To (a ghost function of the model, so that clients see what it says).
Ghost: for contracts and ghost code, and left out of the program.
API 012
Out_Degree (declaration) — How many edges leave V.
Before this operation, establish:
V <= Vertex_Count (G)On normal return the declared contract establishes:
Out_Degree'Result = Degree_Sequences.Get (Model (G).Degrees, V)
and then Out_Degree'Result < Verada.Storage.Length_BoundAPI 013
Adjacent (declaration) — Whether an edge leads from From to To, found by following From's edges.
Before this operation, establish:
From <= Vertex_Count (G) and then To <= Vertex_Count (G)On normal return the declared contract establishes:
Adjacent'Result = Has_Edge (Model (G), From, To)API 014
Add_Vertex (declaration) — Add a vertex with no edges, numbered after the others, and give its number.
On normal return the declared contract establishes:
Model (G).Degrees = Degree_Sequences.Add (Model (G)'Old.Degrees, 0)
and Model (G).Edges = Model (G)'Old.Edges
and V = Vertex_Count (G)API 015
Add_Edge (declaration) — Add an edge from From to To that is not there yet.
Before this operation, establish:
From <= Vertex_Count (G) and then To <= Vertex_Count (G)
and then not Has_Edge (Model (G), From, To)On normal return the declared contract establishes:
Model (G).Degrees = Degree_Sequences.Set (Model (G)'Old.Degrees, From, Degree_Sequences.Get (Model (G)'Old.Degrees, From) + 1)
and Model (G).Edges = Edge_Sequences.Add (Model (G)'Old.Edges, Edge'(From, To))API 016
Clear (declaration) — Remove every vertex and edge and free their cells.
On normal return the declared contract establishes:
Vertex_Count (G) = 0 and then Edge_Sequences.Length (Model (G).Edges) = 0