Commit 9474d364 authored by charguer's avatar charguer

DFS proof fixed

parent bce17edb
(** Representation of fixed-size circular buffers. *)
module Make (Capa : CapacitySig.S) (Item : InhabType.S) =
module Make (Capa : CapacitySig.S) (Item : InhabType.S) =
struct
(*--------------------------------------------------------------------------*)
......@@ -24,7 +23,7 @@ type t = {
(** Builds a new queue *)
let create () =
let create () =
{ head = 0;
size = 0;
data = Array.make capacity Item.inhab; }
......@@ -59,15 +58,15 @@ let wrap_down i =
(** Pop an element from the front (assumes non-empty queue) *)
let pop_front q =
let pop_front q =
let x = Array.get q.data q.head in
q.head <- wrap_up (q.head + 1);
q.size <- q.size - 1;
x
(** Pop an element from the back (assumes non-empty queue) *)
let pop_back q =
let pop_back q =
q.size <- q.size - 1;
let i = wrap_up (q.head + q.size) in
Array.get q.data i
......@@ -92,12 +91,12 @@ let push_back x q =
let debug = false
(** Internal: copy n elements from an array t1 of size capacity,
starting at index i1 and possibly wrapping around, into an
starting at index i1 and possibly wrapping around, into an
array t2 starting at index i2 and not wrapping around. *)
let copy_data_wrap_src t1 i1 t2 i2 n =
if (debug && (i1 < 0 || i1 > capacity || i2 < 0 || i2 + n > capacity || n < 0))
then failwith (Printf.sprintf "copy_data_wrap_src error: %d %d %d" i1 i2 n);
then failwith (Printf.sprintf "copy_data_wrap_src error: %d %d %d" i1 i2 n);
let j1 = i1 + n in
if j1 <= capacity then begin
Array.blit t1 i1 t2 i2 n
......@@ -107,7 +106,7 @@ let copy_data_wrap_src t1 i1 t2 i2 n =
Array.blit t1 i1 t2 i2 na;
Array.blit t1 0 t2 i2' (n - na);
end
(** Internal: copy n elements from an array t1 starting at index i1
and not wrapping around, into an array t2 of size capacity,
starting at index i2 and possibly wrapping around. *)
......@@ -126,7 +125,7 @@ let copy_data_wrap_dst t1 i1 t2 i2 n =
end
(** Internal: copy n elements from an array t1 starting at index i1
and possibly wrapping around, into an array t2 starting at index
and possibly wrapping around, into an array t2 starting at index
i2 and possibly wrapping around. Both arrays are assumed to be
of size capacity. *)
......@@ -149,7 +148,7 @@ let copy_data_wrap_src_and_dst t1 i1 t2 i2 n =
(** Transfer N items from the back of a buffer to the front of another buffer *)
let transfer_back_to_front n q1 q2 =
if n < 0 || n > q1.size || n + q2.size > capacity
if n < 0 || n > q1.size || n + q2.size > capacity
then invalid_arg "CircularArray.transfer_back_to_front";
let h1 = wrap_down (wrap_up (q1.head + q1.size) - n) in
let h2 = wrap_down (q2.head - n) in
......@@ -161,7 +160,7 @@ let transfer_back_to_front n q1 q2 =
(** Transfer N items from the front of a buffer to the back of another buffer *)
let transfer_front_to_back n q1 q2 =
if n < 0 || n > q1.size || n + q2.size > capacity
if n < 0 || n > q1.size || n + q2.size > capacity
then invalid_arg "CircularArray.transfer_front_to_back";
let h1 = q1.head in
let h2 = wrap_up (q2.head + q2.size) in
......@@ -187,8 +186,8 @@ let transfer_all_to_back q1 q2 =
(** Pop N elements from the front into an array *)
let popn_front_to_array n q =
if n < 0 || n > q.size
let popn_front_to_array n q =
if n < 0 || n > q.size
then invalid_arg "CircularArray.popn_front_to_array";
if n = 0 then [||] else begin
let h = q.head in
......@@ -201,7 +200,7 @@ let popn_front_to_array n q =
(** Pop N elements from the back into an array *)
let popn_back_to_array n q =
let popn_back_to_array n q =
if n < 0 || n > q.size then invalid_arg "CircularArray.popn_back_to_array";
if n = 0 then [||] else begin
let h = wrap_down (wrap_up (q.head + q.size) - n) in
......@@ -281,7 +280,7 @@ let to_list q =
let cell_at q i =
wrap_up (q.head + i)
let get q i =
let get q i =
q.data.(cell_at q i)
let set q i v =
......
This diff is collapsed.
......@@ -2,6 +2,7 @@ Set Implicit Arguments.
Require Import CFML.CFLib.
Require Import Demo_ml.
Require Import Stdlib.
Require LibListZ.
Import ZsubNoSimpl.
Open Scope tag_scope.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment