Kernel-reducible offset accumulation, including the final endpoint.
Equations
- Hex.SparseGraph.offsetsFrom [] x✝ = [x✝]
- Hex.SparseGraph.offsetsFrom (row :: rows) x✝ = x✝ :: Hex.SparseGraph.offsetsFrom rows (x✝ + row.length)
Instances For
Offsets of consecutive adjacency rows, including the final endpoint.
Equations
- Hex.SparseGraph.offsetsOf rows = Hex.SparseGraph.offsetsFrom rows 0
Instances For
A finite simple undirected graph with compressed, sorted adjacency lists.
Start of each row and the final endpoint.
Consecutive neighbour lists.
Every adjacency entry belongs to exactly one row.
- sorted (i : Fin n) : List.Pairwise (fun (x1 x2 : Fin n) => x1 < x2) (row self.offsets self.neighbors ↑i).toList
Rows are strictly increasing, hence duplicate-free.
- symm (i j : Fin n) : j ∈ row self.offsets self.neighbors ↑i ↔ i ∈ row self.offsets self.neighbors ↑j
Every edge has its reverse.
No vertex is adjacent to itself.
Instances For
The sorted neighbours of a vertex. Extracting a row copies its entries.
Equations
- G.nbrs i = Hex.SparseGraph.row G.offsets G.neighbors ↑i
Instances For
Adjacency is membership in a compressed row.
Instances For
Pack a vector of sorted, symmetric, loopless neighbour lists.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Dense conversion is explicit and allocates the full Boolean matrix.
Equations
- G.toDense = Hex.Graph.ofAdj G.adj ⋯ ⋯
Instances For
The offset array includes both endpoints of every row.
The constant-time degree operation counts the entries of the row.
Sorted rows and a packed layout make graph equality extensional.
The edgeless graph stores n + 1 zero offsets and no neighbours.
Equations
- Hex.SparseGraph.empty n = Hex.SparseGraph.ofRows (Vector.replicate n []) ⋯ ⋯ ⋯
Instances For
Explicit conversion scans the dense matrix once to build sorted sparse rows.
Equations
- G.toSparse = Hex.SparseGraph.ofRows (Vector.ofFn fun (i : Fin n) => (G.nbrs i).toList) ⋯ ⋯ ⋯