annotate lib/growvect.mli @ 0:bfdcc3820b32

Basis
author Mike Spivey <mike@cs.ox.ac.uk>
date Thu, 05 Oct 2017 08:04:15 +0100
parents
children
rev   line source
0
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
1 (* growvect.mli *)
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
2 (* Copyright (c) 2017 J. M. Spivey *)
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
3
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
4 (* This module provides an alternative implementation of arrays that
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
5 grow as needed to accommodate the indices used in assignments. *)
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
6
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
7 type 'a t
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
8
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
9 (* create -- make an empty vector with a specified initial capacity *)
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
10 val create : int -> 'a t
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
11
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
12 (* make -- make a vector of specified size *)
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
13 val make : int -> 'a -> 'a t
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
14
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
15 (* clear -- make vector empty again *)
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
16 val clear : 'a t -> unit
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
17
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
18 (* get -- fetch element at given index *)
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
19 val get : 'a t -> int -> 'a
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
20
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
21 (* size -- get current number of elements *)
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
22 val size : 'a t -> int
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
23
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
24 (* set -- change existing element at given index *)
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
25 val set : 'a t -> int -> 'a -> unit
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
26
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
27 (* append -- add new element at the end *)
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
28 val append : 'a t -> 'a -> unit
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
29
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
30 (* to_list -- convert to list *)
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
31 val to_list : 'a t -> 'a list
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
32
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
33 (* iter -- apply function to each element *)
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
34 val iter : ('a -> unit) -> 'a t -> unit