12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364(***************************************************************************)(* *)(* UnionFind *)(* *)(* François Pottier, Inria Paris *)(* *)(* Copyright Inria. All rights reserved. This file is distributed under *)(* the terms of the GNU Library General Public License version 2, with a *)(* special exception on linking, as described in the file LICENSE. *)(***************************************************************************)(**The signature {!STORE} describes an implementation of first-class stores. *)moduletypeSTORE=sig(**A store can be thought of as a region of memory in which objects, known
as references, can be dynamically allocated, read, and written. Stores
are homogeneous: all references in a store of type ['a store] have the
content type, namely ['a]. In general, a store may be persistent or
mutable, depending on which data structure is used to implement it. *)type'astore(* We restrict our attention to homogeneous stores, because this is
simpler and allows a wider range of implementations. *)(**[new_store()] creates an empty store. *)valnew_store:unit->'astore(**A reference of type ['a rref] can be thought of as (a pointer to) an
object that exists in some store. *)type'arref(* The type parameter ['a] in ['a rref] could be considered redundant, as it
is not really necessary that both [store] and [rref] be parameterized.
However, one can think of instances where ['a store] is a phantom type
and ['a rref] really depends on ['a] AND of instances where the converse
holds. *)(* For regularity, each of the four operations below takes a store as a
parameter and returns a store as a result. One might think that [eq]
does not need a store parameter, and that [get] and [eq] do not need a
store result. However, in some implementations where the store is
self-organizing, this may be necessary, so we bite the bullet and pay
the cost in runtime and verbosity. *)(**[make s v] creates a fresh reference in the store [s] and sets its
content to [v]. It returns a pair of an updated store and the
newly-created reference. *)valmake:'astore->'a->'astore*'arref(**[get s x] reads the current content of the reference [x] in the store
[s]. It returns a pair of a possibly-updated store and the current
content of the reference. *)valget:'astore->'arref->'astore*'a(**[set s x v] updates the store [s] so as to set the content of the
reference [x] to [v]. It returns an updated store. *)valset:'astore->'arref->'a->'astore(**[eq s x y] determines whether the references [x] and [y] are the same
reference. It returns a pair of a possibly-updated store and a Boolean
result. The references [x] and [y] must belong to the store [s]. *)valeq:'astore->'arref->'arref->'astore*boolend