Adjacency arrays over the memory oracle #
The read-only adjacency-list interface AdjacencyList.spec n is implemented over
Memory.spec w by compressed adjacency arrays: a field offsets whose cell u holds the start
of the list of u in the edge array, so that the out-degree of u is the difference of two
consecutive offsets, and a field edges holding each edge as two cells, its target and its
weight. This is the layout in which a word RAM receives a graph as input. A degree query reads
two offsets, and an edge query reads an offset and the edge's two cells (amortized).
The interface never changes its state, so a refinement represents one graph adj: its invariant
says that the arrays hold adj (Holds), and its abstraction function is constant. The methods
write nothing (ops_triple), and the invariant reads only the two fields, so the arrays are
framed by their fields and share memory with other structures (framed).
Main definitions #
Layout,Layout.footprint,Layout.Valid: the two fields, their cells, and the length of the offset field.degree,edge,ops,methods: the queries as memory programs.Holds,Inv: the arrays hold a graph, and the implementation invariant.refinement,framed: the arrays as a refinement of the interface for the graph they hold, framed by their fields.
Main results #
ops_triple: each query returns the specified answer within three memory units, and writes nothing.amortized: every query costs at most three memory units.
References #
Adjacency arrays: the offset of each vertex's list, and the edges, two cells each.
- offsets : WordRAM.Block
Cell
uholds the position of the first edge out ofu; cellnthe end of the last list. - edges : WordRAM.Block
Edge
joccupies cells2 j(its target) and2 j + 1(its weight).
The cells of both fields.
The out-degree of u: the difference of two consecutive offsets.
The i-th edge out of u: its target and weight, from the edge at the offset of u plus
i. A target that is not a vertex cannot occur for an admissible query; the answer is then the
spec's placeholder (u, 0).
The queries as memory programs.
The queries as methods of AdjacencyList.spec n over Memory.spec w.
The memory m holds the graph adj in the layout: consecutive offsets differ by the
out-degrees, the edges out of u follow its offset in order, and every list ends within the edge
field.
The list of
uends where the list ofu + 1starts.Every list ends within the edge field.
- target (u : Fin n) (i : ℕ) (hi : i < (adj u).length) : m (L.edges.base + 2 * (m (L.offsets.base + ↑u) + i)) = ↑(adj u)[i].1
The target of each edge.
- weight (u : Fin n) (i : ℕ) (hi : i < (adj u).length) : m (L.edges.base + (2 * (m (L.offsets.base + ↑u) + i) + 1)) = (adj u)[i].2
The weight of each edge.
The implementation invariant for the graph adj: both fields are allocated and hold it.
The offset field is allocated.
The edge field is allocated.
The fields hold the graph.
Each query returns the specified answer within three memory units, and writes nothing.
The run of a query, by ops_triple.
The invariant reads only the two fields and survives a growing frontier.
The adjacency arrays, framed by their two fields.
Every query costs at most three memory units.