Persistent array implementation. I.E. array which keep track of their history and allow rollback. They appear immutable. This implementation is pretty much exactly the one described by [Cochon and Filliâtre, 2007].
Every array operation get, set, size, diff reroot's the array at the given version. For best performance, avoid jumping between versions too often.
of_array arr creates the persistent array containing the same elements as arr This copies the array, so future modifications to arr will not corrupt the persistent array. O(Array.length arr) complexity.
of_list l creates a persistent array with the same elements as l. O(List.length l) complexity.
Array operations
All operations reroot the given array. This is constant time for mutliple accesses to the same version. When switching versions however, the cost is linear in the number of updates (set operations) between both version.
pretty ~pp_sep pp_elt t prints the array at t, using pp_elt to print elements and pp_sep to separate them. pp_sep defaults to printing a semicolon and a space).
diff a b create a table of differences i -> (a.(i), b.(i)) between a and b Requires a and b to share a common root (i.e. derive from the same init or make).
The diff table may include identical values i -> (v,v), these correspond to changes that are reverted on the chain from a to b. For example: let b = set (set a i x) i a.(i).
For performance: have a be the one closest to reroot (i.e. the last modified value).
O(d) complexity (after reroot at a), where d is the number of updates (set operations) between a and b.
Versioned persistent arrays also return the element with the lowest version tag.
diff_key a b is the same as diff a b, but only returns the keys i such that a.(i) and b.(i) may be different.
Versioned persistent arrays also return the element with the lowest version tag.
Array resizing
It is possible to extend persistent arrays (i.e. add elements at the back). These operations retro-actively modify all previous versions. They will all appear as though they always had the new size, so a get old_version i that would have failed before resize will now succeed.
append t arr extends t by adding the values from arr at the end. This modifies t and all previous versions of t. O(size t + Array.length arr) complexity (after reroot).
extend t n x extends t by appending n times the value x: [|t.(0); ...; t.(size t - 1); x; ...; x|]. This modifies t and all previous versions of t. O(size t + n) complexity.