diff options
-rw-r--r-- | lib/cStack.ml | 55 | ||||
-rw-r--r-- | lib/cStack.mli | 18 |
2 files changed, 9 insertions, 64 deletions
diff --git a/lib/cStack.ml b/lib/cStack.ml index 41ea5bf03..5ec872117 100644 --- a/lib/cStack.ml +++ b/lib/cStack.ml @@ -10,10 +10,9 @@ exception Empty = Stack.Empty type 'a t = { mutable stack : 'a list; - mutable context : ('a list * 'a list) option } -let create () = { stack = []; context = None } +let create () = { stack = [] } let push x s = s.stack <- x :: s.stack @@ -25,13 +24,7 @@ let top = function | { stack = [] } -> raise Stack.Empty | { stack = x::_ } -> x -let to_list = function - | { context = None; stack = s } -> s - | { context = Some (a,b); stack = s } -> a @ s @ b - -let to_lists = function - | { context = None; stack = s } -> [],s,[] - | { context = Some (a,b); stack = s } -> a,s,b +let to_list { stack = s } = s let find f s = List.find f (to_list s) @@ -50,41 +43,11 @@ let fold_until f accu s = | x :: xs -> match f accu x with Stop x -> x | Next i -> aux i xs in aux accu s.stack -let is_empty = function - | { stack = []; context = None } -> true - | _ -> false - -let iter f = function - | { stack = s; context = None } -> List.iter f s - | { stack = s; context = Some(a,b) } -> - List.iter f a; List.iter f s; List.iter f b - -let clear s = s.stack <- []; s.context <- None - -let length = function - | { stack = s; context = None } -> List.length s - | { stack = s; context = Some(a,b) } -> - List.length a + List.length s + List.length b - -let focus s ~cond_top:c_start ~cond_bot:c_stop = - if s.context <> None then raise (Invalid_argument "CStack.focus"); - let rec aux (a,s,b) grab = function - | [] -> raise (Invalid_argument "CStack.focus") - | x::xs when not grab -> - if c_start x then aux (a,s,b) true (x::xs) - else aux (x::a,s,b) grab xs - | x::xs -> - if c_stop x then a, x::s, xs - else aux (a,x::s,b) grab xs in - let a, stack, b = aux ([],[],[]) false s.stack in - s.stack <- List.rev stack; - s.context <- Some (List.rev a, b) - -let unfocus = function - | { context = None } -> raise (Invalid_argument "CStack.unfocus") - | { context = Some (a,b); stack } as s -> - s.context <- None; - s.stack <- a @ stack @ b - -let focused { context } = context <> None +let is_empty { stack = s } = s = [] + +let iter f { stack = s } = List.iter f s + +let clear s = s.stack <- [] + +let length { stack = s } = List.length s diff --git a/lib/cStack.mli b/lib/cStack.mli index 78d2563a1..12bec1457 100644 --- a/lib/cStack.mli +++ b/lib/cStack.mli @@ -58,21 +58,3 @@ type ('b, 'c) seek = ('b, 'c) CSig.seek = Stop of 'b | Next of 'c @raise Not_found it there is none. *) val fold_until : ('c -> 'a -> ('b, 'c) seek) -> 'c -> 'a t -> 'b -(** After [focus s c1 c2] the top of [s] is the topmost element [x] such that - [c1 x] is [true] and the bottom is the first element [y] following [x] - such that [c2 y] is [true]. After a focus push/pop/top/fold_until - only use the focused part. - @raise Invalid_argument "CStack.focus" if there is no such [x] and [y] *) -val focus : 'a t -> cond_top:('a -> bool) -> cond_bot:('a -> bool) -> unit - -(** Undoes a [focus]. - @raise Invalid_argument "CStack.unfocus" if the stack is not focused *) -val unfocus : 'a t -> unit - -(** Is the stack focused *) -val focused : 'a t -> bool - -(** Returns [top, s, bot] where [top @ s @ bot] is the full stack, and [s] - the focused part *) -val to_lists : 'a t -> 'a list * 'a list * 'a list - |