]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/ocaml/contrib/stdlib/stack.mli
Inital import
[l4.git] / l4 / pkg / ocaml / contrib / stdlib / stack.mli
1 (***********************************************************************)
2 (*                                                                     *)
3 (*                           Objective Caml                            *)
4 (*                                                                     *)
5 (*            Xavier Leroy, projet Cristal, INRIA Rocquencourt         *)
6 (*                                                                     *)
7 (*  Copyright 1996 Institut National de Recherche en Informatique et   *)
8 (*  en Automatique.  All rights reserved.  This file is distributed    *)
9 (*  under the terms of the GNU Library General Public License, with    *)
10 (*  the special exception on linking described in file ../LICENSE.     *)
11 (*                                                                     *)
12 (***********************************************************************)
13
14 (* $Id: stack.mli 7164 2005-10-25 18:34:07Z doligez $ *)
15
16 (** Last-in first-out stacks.
17
18    This module implements stacks (LIFOs), with in-place modification.
19 *)
20
21 type 'a t
22 (** The type of stacks containing elements of type ['a]. *)
23
24 exception Empty
25 (** Raised when {!Stack.pop} or {!Stack.top} is applied to an empty stack. *)
26
27
28 val create : unit -> 'a t
29 (** Return a new stack, initially empty. *)
30
31 val push : 'a -> 'a t -> unit
32 (** [push x s] adds the element [x] at the top of stack [s]. *)
33
34 val pop : 'a t -> 'a
35 (** [pop s] removes and returns the topmost element in stack [s],
36    or raises [Empty] if the stack is empty. *)
37
38 val top : 'a t -> 'a
39 (** [top s] returns the topmost element in stack [s],
40    or raises [Empty] if the stack is empty. *)
41
42 val clear : 'a t -> unit
43 (** Discard all elements from a stack. *)
44
45 val copy : 'a t -> 'a t
46 (** Return a copy of the given stack. *)
47
48 val is_empty : 'a t -> bool
49 (** Return [true] if the given stack is empty, [false] otherwise. *)
50
51 val length : 'a t -> int
52 (** Return the number of elements in a stack. *)
53
54 val iter : ('a -> unit) -> 'a t -> unit
55 (** [iter f s] applies [f] in turn to all elements of [s],
56    from the element at the top of the stack to the element at the
57    bottom of the stack. The stack itself is unchanged. *)