diff options
author | Samuel Mimram <smimram@debian.org> | 2008-07-25 15:12:53 +0200 |
---|---|---|
committer | Samuel Mimram <smimram@debian.org> | 2008-07-25 15:12:53 +0200 |
commit | a0cfa4f118023d35b767a999d5a2ac4b082857b4 (patch) | |
tree | dabcac548e299fee1da464c93b3dba98484f45b1 /lib/bstack.ml | |
parent | 2281410e38ef99d025ea77194585a9bc019fdaa9 (diff) |
Imported Upstream version 8.2~beta3+dfsgupstream/8.2.beta3+dfsg
Diffstat (limited to 'lib/bstack.ml')
-rw-r--r-- | lib/bstack.ml | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/lib/bstack.ml b/lib/bstack.ml index b86dccf9..35bbf32b 100644 --- a/lib/bstack.ml +++ b/lib/bstack.ml @@ -6,19 +6,27 @@ (* * GNU Lesser General Public License Version 2.1 *) (************************************************************************) -(* $Id: bstack.ml 5920 2004-07-16 20:01:26Z herbelin $ *) +(* $Id: bstack.ml 10441 2008-01-15 16:37:46Z lmamane $ *) (* Queues of a given length *) open Util +(* - size is the count of elements actually in the queue + - depth is the the amount of elements pushed in the queue (and not popped) + in particular, depth >= size always and depth > size if the queue overflowed + (and forgot older elements) + *) + type 'a t = {mutable pos : int; mutable size : int; + mutable depth : int; stack : 'a array} let create depth e = {pos = 0; size = 1; + depth = 1; stack = Array.create depth e} (* @@ -37,14 +45,16 @@ let decr_pos bs = let push bs e = incr_pos bs; incr_size bs; + bs.depth <- bs.depth + 1; bs.stack.(bs.pos) <- e let pop bs = if bs.size > 1 then begin bs.size <- bs.size - 1; + bs.depth <- bs.depth - 1; let oldpos = bs.pos in decr_pos bs; - (* Release the memory at oldpos, by coyping what is at new pos *) + (* Release the memory at oldpos, by copying what is at new pos *) bs.stack.(oldpos) <- bs.stack.(bs.pos) end @@ -60,4 +70,6 @@ let app_repl bs f = if bs.size = 0 then error "Nothing on the stack" else bs.stack.(bs.pos) <- f (bs.stack.(bs.pos)) -let depth bs = bs.size +let depth bs = bs.depth + +let size bs = bs.size |