style: reindent in ccdeque

This commit is contained in:
Simon Cruanes 2019-11-05 18:23:06 -06:00
parent 2fa12665dd
commit 2ed821bbe1

View file

@ -74,7 +74,6 @@ let is_empty d =
assert (bool_eq res (d.cur = Empty)); assert (bool_eq res (d.cur = Empty));
res res
(*let rec cur = { cell=Zero; prev=cur; next=cur } in*)
let push_front d x = let push_front d x =
incr_size_ d; incr_size_ d;
match d.cur with match d.cur with
@ -82,7 +81,7 @@ let push_front d x =
let rec node = { cell=One x; prev = node; next = node } in let rec node = { cell=One x; prev = node; next = node } in
d.cur <- Node node d.cur <- Node node
| Node n -> | Node n ->
match n.cell with begin match n.cell with
| One y -> n.cell <- Two (x, y) | One y -> n.cell <- Two (x, y)
| Two (y, z) -> n.cell <- Three (x,y,z) | Two (y, z) -> n.cell <- Three (x,y,z)
| Three _ -> | Three _ ->
@ -90,6 +89,7 @@ let push_front d x =
n.prev.next <- node; n.prev.next <- node;
n.prev <- node; n.prev <- node;
d.cur <- Node node (* always point to first node *) d.cur <- Node node (* always point to first node *)
end
let push_back d x = let push_back d x =
incr_size_ d; incr_size_ d;
@ -99,13 +99,14 @@ let push_back d x =
d.cur <- Node node d.cur <- Node node
| Node cur -> | Node cur ->
let n = cur.prev in (* last node *) let n = cur.prev in (* last node *)
match n.cell with begin match n.cell with
| One y -> n.cell <- Two (y, x) | One y -> n.cell <- Two (y, x)
| Two (y,z) -> n.cell <- Three (y, z, x) | Two (y,z) -> n.cell <- Three (y, z, x)
| Three _ -> | Three _ ->
let elt = { cell = One x; next=cur; prev=n; } in let elt = { cell = One x; next=cur; prev=n; } in
n.next <- elt; n.next <- elt;
cur.prev <- elt cur.prev <- elt
end
let peek_front_opt d = let peek_front_opt d =
match d.cur with match d.cur with
@ -263,12 +264,14 @@ let update_front d f =
match cur.cell with match cur.cell with
| One x -> | One x ->
begin match f x with begin match f x with
| None -> if Stdlib.(!=) cur.prev cur then ( | None ->
if Stdlib.(!=) cur.prev cur then (
cur.prev.next <- cur.next; cur.prev.next <- cur.next;
cur.next.prev <- cur.prev; cur.next.prev <- cur.prev;
d.cur <- Node cur.next; d.cur <- Node cur.next;
) else (
d.cur <- Empty
) )
else d.cur <- Empty
| Some x -> cur.cell <- One x | Some x -> cur.cell <- One x
end end
| Two (x, y) -> | Two (x, y) ->
@ -307,7 +310,8 @@ let update_back d f =
match n.cell with match n.cell with
| One x -> | One x ->
begin match f x with begin match f x with
| None -> if Stdlib.(!=) cur.prev cur then remove_node_ n | None ->
if Stdlib.(!=) cur.prev cur then remove_node_ n
else d.cur <- Empty else d.cur <- Empty
| Some x -> n.cell <- One x | Some x -> n.cell <- One x
end end
@ -538,7 +542,8 @@ let filter_in_place (d:_ t) f : unit =
d.cur <- Node n; d.cur <- Node n;
loop ~stop_at:n n.next loop ~stop_at:n n.next
end end
| Some c -> cur.cell <- c; | Some c ->
cur.cell <- c;
loop ~stop_at:cur cur.next loop ~stop_at:cur cur.next
(*$R (*$R
@ -593,7 +598,8 @@ let to_gen q =
let first = cur in let first = cur in
let cell = ref (Some cur.cell) in let cell = ref (Some cur.cell) in
let cur = ref cur in let cur = ref cur in
let rec next () = match !cell with let rec next () =
match !cell with
| None when Stdlib.(==) (!cur).next first -> None | None when Stdlib.(==) (!cur).next first -> None
| None -> | None ->
(* go to next node *) (* go to next node *)