~ubuntu-branches/ubuntu/wily/coq-doc/wily

« back to all changes in this revision

Viewing changes to lib/bstack.ml

  • Committer: Bazaar Package Importer
  • Author(s): Stéphane Glondu, Stéphane Glondu, Samuel Mimram
  • Date: 2010-01-07 22:50:39 UTC
  • mfrom: (1.2.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20100107225039-n3cq82589u0qt0s2
Tags: 8.2pl1-1
[ Stéphane Glondu ]
* New upstream release (Closes: #563669)
  - remove patches
* Packaging overhaul:
  - use git, advertise it in Vcs-* fields of debian/control
  - use debhelper 7 and dh with override
  - use source format 3.0 (quilt)
* debian/control:
  - set Maintainer to d-o-m, set Uploaders to Sam and myself
  - add Homepage field
  - bump Standards-Version to 3.8.3
* Register PDF documentation into doc-base
* Add debian/watch
* Update debian/copyright

[ Samuel Mimram ]
* Change coq-doc's description to mention that it provides documentation in
  pdf format, not postscript, closes: #543545.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
(************************************************************************)
 
2
(*  v      *   The Coq Proof Assistant  /  The Coq Development Team     *)
 
3
(* <O___,, * CNRS-Ecole Polytechnique-INRIA Futurs-Universite Paris Sud *)
 
4
(*   \VV/  **************************************************************)
 
5
(*    //   *      This file is distributed under the terms of the       *)
 
6
(*         *       GNU Lesser General Public License Version 2.1        *)
 
7
(************************************************************************)
 
8
 
 
9
(* $Id: bstack.ml 10441 2008-01-15 16:37:46Z lmamane $ *)
 
10
 
 
11
(* Queues of a given length *)
 
12
 
 
13
open Util
 
14
 
 
15
(* - size  is the count of elements actually in the queue
 
16
   - depth is the the amount of elements pushed in the queue (and not popped)
 
17
   in particular, depth >= size always and depth > size if the queue overflowed
 
18
   (and forgot older elements)
 
19
 *)
 
20
 
 
21
type 'a t = {mutable pos : int;
 
22
             mutable size : int;
 
23
             mutable depth : int;
 
24
             stack : 'a array}
 
25
 
 
26
let create depth e =
 
27
  {pos = 0;
 
28
   size = 1;
 
29
   depth = 1;
 
30
   stack = Array.create depth e}
 
31
 
 
32
(*
 
33
let set_depth bs n = bs.depth <- n
 
34
*)
 
35
 
 
36
let incr_pos bs =
 
37
  bs.pos <- if bs.pos = Array.length bs.stack - 1 then 0 else bs.pos + 1
 
38
 
 
39
let incr_size bs =
 
40
  if bs.size < Array.length bs.stack then bs.size <- bs.size + 1
 
41
 
 
42
let decr_pos bs =
 
43
  bs.pos <- if bs.pos = 0 then Array.length bs.stack - 1 else bs.pos - 1
 
44
 
 
45
let push bs e =
 
46
  incr_pos bs;
 
47
  incr_size bs;
 
48
  bs.depth <- bs.depth + 1;
 
49
  bs.stack.(bs.pos) <- e
 
50
          
 
51
let pop bs =
 
52
  if bs.size > 1 then begin
 
53
    bs.size <- bs.size - 1; 
 
54
    bs.depth <- bs.depth - 1;
 
55
    let oldpos = bs.pos in
 
56
    decr_pos bs;
 
57
    (* Release the memory at oldpos, by copying what is at new pos *)
 
58
    bs.stack.(oldpos) <- bs.stack.(bs.pos)
 
59
  end
 
60
 
 
61
let top bs =
 
62
  if bs.size >= 1 then bs.stack.(bs.pos)
 
63
  else error "Nothing on the stack"
 
64
          
 
65
let app_push bs f =
 
66
  if bs.size = 0 then error "Nothing on the stack"
 
67
  else push bs (f (bs.stack.(bs.pos)))
 
68
 
 
69
let app_repl bs f =
 
70
  if bs.size = 0 then error "Nothing on the stack"
 
71
  else bs.stack.(bs.pos) <- f (bs.stack.(bs.pos))
 
72
 
 
73
let depth bs = bs.depth
 
74
 
 
75
let size bs = bs.size