mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-06 11:15:31 -05:00
style: reindent in ccdeque
This commit is contained in:
parent
2fa12665dd
commit
2ed821bbe1
1 changed files with 165 additions and 159 deletions
|
|
@ -74,7 +74,6 @@ let is_empty d =
|
|||
assert (bool_eq res (d.cur = Empty));
|
||||
res
|
||||
|
||||
(*let rec cur = { cell=Zero; prev=cur; next=cur } in*)
|
||||
let push_front d x =
|
||||
incr_size_ d;
|
||||
match d.cur with
|
||||
|
|
@ -82,7 +81,7 @@ let push_front d x =
|
|||
let rec node = { cell=One x; prev = node; next = node } in
|
||||
d.cur <- Node node
|
||||
| Node n ->
|
||||
match n.cell with
|
||||
begin match n.cell with
|
||||
| One y -> n.cell <- Two (x, y)
|
||||
| Two (y, z) -> n.cell <- Three (x,y,z)
|
||||
| Three _ ->
|
||||
|
|
@ -90,6 +89,7 @@ let push_front d x =
|
|||
n.prev.next <- node;
|
||||
n.prev <- node;
|
||||
d.cur <- Node node (* always point to first node *)
|
||||
end
|
||||
|
||||
let push_back d x =
|
||||
incr_size_ d;
|
||||
|
|
@ -99,13 +99,14 @@ let push_back d x =
|
|||
d.cur <- Node node
|
||||
| Node cur ->
|
||||
let n = cur.prev in (* last node *)
|
||||
match n.cell with
|
||||
begin match n.cell with
|
||||
| One y -> n.cell <- Two (y, x)
|
||||
| Two (y,z) -> n.cell <- Three (y, z, x)
|
||||
| Three _ ->
|
||||
let elt = { cell = One x; next=cur; prev=n; } in
|
||||
n.next <- elt;
|
||||
cur.prev <- elt
|
||||
end
|
||||
|
||||
let peek_front_opt d =
|
||||
match d.cur with
|
||||
|
|
@ -263,12 +264,14 @@ let update_front d f =
|
|||
match cur.cell with
|
||||
| One x ->
|
||||
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.next.prev <- cur.prev;
|
||||
d.cur <- Node cur.next;
|
||||
) else (
|
||||
d.cur <- Empty
|
||||
)
|
||||
else d.cur <- Empty
|
||||
| Some x -> cur.cell <- One x
|
||||
end
|
||||
| Two (x, y) ->
|
||||
|
|
@ -307,7 +310,8 @@ let update_back d f =
|
|||
match n.cell with
|
||||
| One x ->
|
||||
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
|
||||
| Some x -> n.cell <- One x
|
||||
end
|
||||
|
|
@ -492,7 +496,7 @@ let filter_in_place (d:_ t) f : unit =
|
|||
d.size <- d.size - size_cell_ n.cell;
|
||||
match filter_cell_ f n.cell with
|
||||
| None -> None
|
||||
|Some n as new_cell->
|
||||
| Some n as new_cell->
|
||||
d.size <- d.size + size_cell_ n;
|
||||
new_cell
|
||||
in
|
||||
|
|
@ -538,7 +542,8 @@ let filter_in_place (d:_ t) f : unit =
|
|||
d.cur <- Node n;
|
||||
loop ~stop_at:n n.next
|
||||
end
|
||||
| Some c -> cur.cell <- c;
|
||||
| Some c ->
|
||||
cur.cell <- c;
|
||||
loop ~stop_at:cur cur.next
|
||||
|
||||
(*$R
|
||||
|
|
@ -593,7 +598,8 @@ let to_gen q =
|
|||
let first = cur in
|
||||
let cell = ref (Some cur.cell) 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 ->
|
||||
(* go to next node *)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue