Set.choose is an alias for Set.min_elt ; although this may not be in the future.
List.nth sure to suck if you need to do this very often.
The array will work fine, but if you need to add more elements or remove elements, this can be a nightmare for storing books.
Take a look at the versions of the Random Access Lists , which have a fairly optimal time for inserting, deleting, searching, and the cardinal, without being limited to arrays.
When I first encountered this problem, I expanded on the implementation of Set and Map to include random and nth . To expand the module, you need to re-implement the structure and add identification functions to convert between them. I wrote a new module called XSet with the following template:
module Make (Ord : Set.OrderedType) = struct include Set.Make(Ord) type impl = Empty | Node of impl * elt * impl * int external impl_of_t : t -> impl = "%identity" external t_of_impl : impl -> t = "%identity" ... end
You will need to use impl_of_t and vice versa to call ordinary Set functions or to call your private messages from the passed arguments - what is passed to your function should be Set.Make implementation of t not impl .
source share