Compressed-sparse-row word encoding of weighted directed graphs #
Shared input word-list layout and Cslib.WordRAM.Data.init memory-readback lemmas for weighted
directed multigraphs on Fin n given by adjacency lists adj : Fin n → List (Fin n × W), a
source vertex source : Fin n, and an edge-weight encoder encodeWeight : W → ℕ.
The encoded word list (Cslib.Algorithms.WordRAM.CSR.encode) stores:
n, the number of vertices;source, the source vertex;- the
n + 1cumulative edge offsetsoffset 0, …, offset n; - the
medges in vertex order as pairs(target, encodeWeight weight).
Used by both CslibFrontier.Algorithms.WordRAM.Dijkstra (encodeWeight := id on ℕ) and
CslibFrontier.Algorithms.WordRAM.BellmanFord (encodeWeight := Cslib.WordRAM.Signed.encode on
ℤ).
Main definitions #
Cslib.Algorithms.WordRAM.CSR.m: total number of directed edges∑ u, (adj u).length.Cslib.Algorithms.WordRAM.CSR.offset: cumulative edge count below vertexu.Cslib.Algorithms.WordRAM.CSR.encode: CSR word-list encoding of(n, source, adj).Cslib.Algorithms.WordRAM.CSR.dbase: first memory address past the encoded input inData.init.
Main results #
Cslib.Algorithms.WordRAM.CSR.encode_length: the encoded word list has lengthn + 2 * m + 3.Cslib.Algorithms.WordRAM.CSR.offset_succ,Cslib.Algorithms.WordRAM.CSR.offset_n,Cslib.Algorithms.WordRAM.CSR.offset_mono: cumulative-offset recurrences and monotonicity.Cslib.Algorithms.WordRAM.CSR.init_len,Cslib.Algorithms.WordRAM.CSR.init_n,Cslib.Algorithms.WordRAM.CSR.init_source,Cslib.Algorithms.WordRAM.CSR.init_offset,Cslib.Algorithms.WordRAM.CSR.init_target,Cslib.Algorithms.WordRAM.CSR.init_weight,Cslib.Algorithms.WordRAM.CSR.init_past: initial memory layout inData.init.Cslib.Algorithms.WordRAM.CSR.inputFits_encode:InputFitscertificate from an upper bound onn + 2 * m + 3and encoded weights.
theorem Cslib.Algorithms.WordRAM.CSR.inputFits_encode {W : Type u_1} (n : ℕ) (source : Fin n) (adj : Fin n → List (Fin n × W)) (encodeWeight : W → ℕ) {B w : ℕ} (hlen : n + 2 * m n adj + 3 ≤ B) (hw_le : ∀ (u : Fin n), ∀ e ∈ adj u, encodeWeight e.2 ≤ B) (hfit : WordRAM.Fits w B) :
WordRAM.InputFits w (encode n source adj encodeWeight)
encode satisfies InputFits w whenever n + 2 * m + 3 ≤ B, every encoded weight is at most
B, and Fits w B.