Documentation

CslibFrontier.DataStructure.Memory.Copy

Copying cells over the memory oracle #

Memory.copy src dst n copies the n cells from src to the n cells from dst, one read and one write per cell, in increasing order. A structure that grows into a larger block, such as a doubling array or a resizing hash table, moves its contents this way. When the two ranges do not overlap, the copy leaves memory as Cslib.WordRAM.ArrayCopy.copyPrefix describes, the same function that specifies the word RAM's copy routine. It costs 2 n memory units, and its operations are admissible when both ranges are allocated and the copied cells hold words.

Main definitions #

Main results #

Copy the n cells from src to the n cells from dst, in increasing order.

theorem Cslib.DataStructure.Memory.copy_succ (src dst n : ℕ) :
copy src dst (n + 1) = copy src dst n >>= fun (x : Unit) => read (src + n) >>= write (dst + n)

The last cell of a copy: a read and a write after the shorter copy.

theorem Cslib.DataStructure.Memory.clientState_copy {w : ℕ} (src dst n : ℕ) (s : State) (h : src + n ≤ dst ∨ dst + n ≤ src) :
(spec w).clientState s (copy src dst n) = { mem := WordRAM.ArrayCopy.copyPrefix s.mem src dst n, frontier := s.frontier }

The memory after a copy between non-overlapping ranges: the destination holds the source, and the frontier is unchanged.

theorem Cslib.DataStructure.Memory.totalCost_copy {w : ℕ} (src dst n : ℕ) (s : State) :
(spec w).totalCost charge s ((spec w).clientHistory s (copy src dst n)) = 2 * n

A copy of n cells costs 2 n memory units.

theorem Cslib.DataStructure.Memory.validHistory_copy {w : ℕ} (src dst n : ℕ) (s : State) (h : src + n ≤ dst ∨ dst + n ≤ src) (hsrc : src + n ≤ s.frontier) (hdst : dst + n ≤ s.frontier) (hfit : ∀ i < n, WordRAM.Fits w (s.mem (src + i))) :
(spec w).ValidHistory s ((spec w).clientHistory s (copy src dst n))

A copy is admissible when both ranges are allocated, they do not overlap, and the copied cells hold words.