module Kwffa:sig..end
A fast functional array data structure using reverse diffs. This data structure can be used to translate imperative algorithms into pure functional programs without logarithmic overhead and without any special type system support (no monads or linear types).
Accesses/updates to the latest version of the array are always constant time. Access to older versions of the array have overhead proportional to the age (this can be improved using amortized rearrangement of the diff tree and instantiations of new array copies).
Derived from code originally written around 1990 for SML/NJ.
T h o m a s M. B r e u e l (t m b at n c a l . v e r i o . c o m)
Snarfed from: <http://caml.inria.fr/pub/ml-archives/caml-list/2000/07/bf198cc419e4449b856cdb777ff7fb41.en.html>
Hacked by KW 2011-03-18 <http://www.lib.uchicago.edu/keith/>
type 'a ffa
val make : int -> 'a -> 'a ffamake n init: create a fast functional array of size n with initial values set to init.val length : 'a ffa -> intlength a: return the length of a.val aget : 'a ffa -> int -> 'aaget a i: return the value of a.(i).val aset : 'a ffa -> int -> 'a -> 'a ffaaset a i v: set a.(i) to v.val achange : 'a ffa -> int -> ('a -> 'a) -> 'a ffaachange a i f: set a.(i) to f a.(i).val foldl : ('a -> int -> 'b -> 'a) -> 'a -> 'b ffa -> 'afoldl f acc a: fold left over array a.val map : ('a -> 'a) -> 'a ffa -> 'a ffamap f a: map f across array a.val mapi : (int -> 'a -> 'a) -> 'a ffa -> 'a ffamapi f a: map f across array a.val to_list : 'a ffa -> 'a listto_list a: convert array a to a list.