aboutsummaryrefslogtreecommitdiffhomepage
path: root/lib
diff options
context:
space:
mode:
authorGravatar ppedrot <ppedrot@85f007b7-540e-0410-9357-904b9bb8a0f7>2013-09-06 17:18:44 +0000
committerGravatar ppedrot <ppedrot@85f007b7-540e-0410-9357-904b9bb8a0f7>2013-09-06 17:18:44 +0000
commitba524ddfaabc80b31a439544de46c40366565ae8 (patch)
treeff4350bc4ec7e225be1b6f9eeb5af83b45ab7f36 /lib
parentab7377de0a913ca6218bc7377fab33b8018f8f59 (diff)
Moving Searchstack to CStack, and normalizing names a bit.
git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/coq/trunk@16765 85f007b7-540e-0410-9357-904b9bb8a0f7
Diffstat (limited to 'lib')
-rw-r--r--lib/cSig.mli (renamed from lib/searchstack.mli)20
-rw-r--r--lib/cStack.ml (renamed from lib/searchstack.ml)20
-rw-r--r--lib/cStack.mli58
-rw-r--r--lib/clib.mllib1
-rw-r--r--lib/lib.mllib1
-rw-r--r--lib/util.ml7
-rw-r--r--lib/util.mli10
7 files changed, 94 insertions, 23 deletions
diff --git a/lib/searchstack.mli b/lib/cSig.mli
index 6c81a2a9c..4858d16c3 100644
--- a/lib/searchstack.mli
+++ b/lib/cSig.mli
@@ -6,20 +6,10 @@
(* * GNU Lesser General Public License Version 2.1 *)
(************************************************************************)
-type 'a t
-type ('a,'b) search = [ `Stop of 'b | `Cont of 'a ]
+(** Missing pervasive types from OCaml stdlib *)
-val create : unit -> 'a t
-val push : 'a -> 'a t -> unit
-val find : ('c -> 'a -> ('c, 'b) search) -> 'c -> 'a t -> 'b
-val is_empty : 'a t -> bool
-val iter : ('a -> unit) -> 'a t -> unit
-val clear : 'a t -> unit
-val length : 'a t -> int
+type ('a, 'b) union = Inl of 'a | Inr of 'b
+(** Union type *)
-(* may raise Stack.Empty *)
-val pop : 'a t -> 'a
-val top : 'a t -> 'a
-
-(* Extra *)
-val to_list : 'a t -> 'a list
+type ('a, 'b) seek = Stop of 'a | Next of 'b
+(** Type isomorphic to union used for browsable structures. *)
diff --git a/lib/searchstack.ml b/lib/cStack.ml
index 8d160e572..e0a3733f6 100644
--- a/lib/searchstack.ml
+++ b/lib/cStack.ml
@@ -6,18 +6,28 @@
(* * GNU Lesser General Public License Version 2.1 *)
(************************************************************************)
+open CSig
+
+exception Empty = Stack.Empty
+
type 'a t = 'a list ref
-type ('a,'b) search = [ `Stop of 'b | `Cont of 'a ]
let create () = ref []
let push x l = l := x :: !l
let pop l = match !l with [] -> raise Stack.Empty | x::xs -> l := xs; x
let top l = match !l with [] -> raise Stack.Empty | x::_ -> x
-let find f i l =
- let rec aux i = function
+let find f l = List.find f !l
+let find_map f l =
+ let rec aux = function
+ | [] -> raise Not_found
+ | x :: xs -> match f x with None -> aux xs | Some i -> i
+ in
+ aux !l
+let seek f accu l =
+ let rec aux accu = function
| [] -> raise Not_found
- | x::xs -> match f i x with `Stop x -> x | `Cont i -> aux i xs in
- aux i !l
+ | x :: xs -> match f accu x with Stop x -> x | Next i -> aux accu xs in
+ aux accu !l
let is_empty l = match !l with [] -> true | _ -> false
let iter f l = List.iter f !l
let clear l = l := []
diff --git a/lib/cStack.mli b/lib/cStack.mli
new file mode 100644
index 000000000..edca85448
--- /dev/null
+++ b/lib/cStack.mli
@@ -0,0 +1,58 @@
+(************************************************************************)
+(* v * The Coq Proof Assistant / The Coq Development Team *)
+(* <O___,, * INRIA - CNRS - LIX - LRI - PPS - Copyright 1999-2010 *)
+(* \VV/ **************************************************************)
+(* // * This file is distributed under the terms of the *)
+(* * GNU Lesser General Public License Version 2.1 *)
+(************************************************************************)
+
+(** Extended interface for OCaml stacks. *)
+
+open CSig
+
+type 'a t
+
+exception Empty
+(** Alias for Stack.Empty. *)
+
+val create : unit -> 'a t
+(** Create an empty stack. *)
+
+val push : 'a -> 'a t -> unit
+(** Add an element to a stack. *)
+
+val find : ('a -> bool) -> 'a t -> 'a
+(** Find the first element satisfying the predicate.
+ @raise Not_found it there is none. *)
+
+val find_map : ('a -> 'b option) -> 'a t -> 'b
+(** Find the first element that returns [Some _].
+ @raise Not_found it there is none. *)
+
+val seek : ('c -> 'a -> ('b, 'c) seek) -> 'c -> 'a t -> 'b
+(** Find the first element that returns [Some _].
+ @raise Not_found it there is none. *)
+
+val is_empty : 'a t -> bool
+(** Whether a stack is empty. *)
+
+val iter : ('a -> unit) -> 'a t -> unit
+(** Iterate a function over elements, from the last added one. *)
+
+val clear : 'a t -> unit
+(** Empty a stack. *)
+
+val length : 'a t -> int
+(** Length of a stack. *)
+
+val pop : 'a t -> 'a
+(** Remove and returns the first element of the stack.
+ @raise Empty if empty. *)
+
+val top : 'a t -> 'a
+(** Remove the first element of the stack without modifying it.
+ @raise Empty if empty. *)
+
+val to_list : 'a t -> 'a list
+(** Convert to a list. *)
+
diff --git a/lib/clib.mllib b/lib/clib.mllib
index 30821492e..833182bce 100644
--- a/lib/clib.mllib
+++ b/lib/clib.mllib
@@ -19,6 +19,7 @@ CObj
CList
CString
CArray
+CStack
Util
Loc
Flags
diff --git a/lib/lib.mllib b/lib/lib.mllib
index 9f29613d1..f45c34610 100644
--- a/lib/lib.mllib
+++ b/lib/lib.mllib
@@ -2,7 +2,6 @@ Xml_lexer
Xml_parser
Xml_printer
Errors
-Searchstack
Bigint
Dyn
Segmenttree
diff --git a/lib/util.ml b/lib/util.ml
index b7364cbc5..2db11131d 100644
--- a/lib/util.ml
+++ b/lib/util.ml
@@ -69,6 +69,10 @@ module Array : CArray.ExtS = CArray
module Map = CMap
+(* Stacks *)
+
+module Stack = CStack
+
(* Matrices *)
let matrix_transpose mat =
@@ -118,7 +122,8 @@ let delayed_force f = f ()
(* Misc *)
-type ('a,'b) union = Inl of 'a | Inr of 'b
+type ('a, 'b) union = ('a, 'b) CSig.union = Inl of 'a | Inr of 'b
+type ('a, 'b) seek = ('a, 'b) CSig.seek = Stop of 'a | Next of 'b
(*s interruption *)
diff --git a/lib/util.mli b/lib/util.mli
index 72217fd0e..8dec93e30 100644
--- a/lib/util.mli
+++ b/lib/util.mli
@@ -63,6 +63,10 @@ module Array : CArray.ExtS
module Map : module type of CMap
+(** {6 Stacks.} *)
+
+module Stack : module type of CStack
+
(** {6 Streams. } *)
val stream_nth : int -> 'a Stream.t -> 'a
@@ -90,7 +94,11 @@ val delayed_force : 'a delayed -> 'a
(** {6 Misc. } *)
-type ('a, 'b) union = Inl of 'a | Inr of 'b
+type ('a, 'b) union = ('a, 'b) CSig.union = Inl of 'a | Inr of 'b
+(** Union type *)
+
+type ('a, 'b) seek = ('a, 'b) CSig.seek = Stop of 'a | Next of 'b
+(** Type isomorphic to union used for browsable structures. *)
(** {6 ... } *)
(** Coq interruption: set the following boolean reference to interrupt Coq