]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/ocaml/contrib/stdlib/stack.ml
update
[l4.git] / l4 / pkg / ocaml / contrib / stdlib / stack.ml
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.ml 4956 2002-06-27 08:48:26Z xleroy $ *)
15
16 type 'a t = { mutable c : 'a list }
17
18 exception Empty
19
20 let create () = { c = [] }
21
22 let clear s = s.c <- []
23
24 let copy s = { c = s.c }
25
26 let push x s = s.c <- x :: s.c
27
28 let pop s =
29   match s.c with
30     hd::tl -> s.c <- tl; hd
31   | []     -> raise Empty
32
33 let top s =
34   match s.c with
35     hd::_ -> hd
36   | []     -> raise Empty
37
38 let is_empty s = (s.c = [])
39
40 let length s = List.length s.c
41
42 let iter f s = List.iter f s.c