mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2026-01-28 11:54:51 -05:00
style: improve new code
This commit is contained in:
parent
509dacb96f
commit
c1704d71ff
2 changed files with 33 additions and 28 deletions
|
|
@ -249,24 +249,25 @@ let update_front d f =
|
||||||
match d.cur.cell with
|
match d.cur.cell with
|
||||||
| Zero -> ()
|
| Zero -> ()
|
||||||
| One x ->
|
| One x ->
|
||||||
begin match f x with
|
begin match f x with
|
||||||
| None -> if Stdlib.(!=) d.cur.prev d.cur then (
|
| None -> if Stdlib.(!=) d.cur.prev d.cur then (
|
||||||
d.cur.prev.next <- d.cur.next;
|
d.cur.prev.next <- d.cur.next;
|
||||||
d.cur.next.prev <- d.cur.prev;
|
d.cur.next.prev <- d.cur.prev;
|
||||||
d.cur <- d.cur.next;
|
d.cur <- d.cur.next;
|
||||||
)
|
)
|
||||||
else d.cur.cell <- Zero
|
else d.cur.cell <- Zero
|
||||||
| Some x -> d.cur.cell <- One x
|
| Some x -> d.cur.cell <- One x
|
||||||
end
|
end
|
||||||
| Two (x, y) ->
|
| Two (x, y) ->
|
||||||
begin match f x with
|
begin match f x with
|
||||||
| None -> d.cur.cell <- One (y)
|
| None -> d.cur.cell <- One (y)
|
||||||
| Some x -> d.cur.cell <- Two (x,y)
|
| Some x -> d.cur.cell <- Two (x,y)
|
||||||
end
|
end
|
||||||
| Three (x,y,z) ->
|
| Three (x,y,z) ->
|
||||||
match f x with
|
begin match f x with
|
||||||
| None -> d.cur.cell <- Two (y,z)
|
| None -> d.cur.cell <- Two (y,z)
|
||||||
| Some x -> d.cur.cell <- Three (x,y,z)
|
| Some x -> d.cur.cell <- Three (x,y,z)
|
||||||
|
end
|
||||||
|
|
||||||
(*$T update_front
|
(*$T update_front
|
||||||
let q = of_list [1;2;3;4;5;6;7] in update_front q (fun _ -> None); to_list q = [2;3;4;5;6;7]
|
let q = of_list [1;2;3;4;5;6;7] in update_front q (fun _ -> None); to_list q = [2;3;4;5;6;7]
|
||||||
|
|
@ -290,20 +291,21 @@ let update_back d f =
|
||||||
match n.cell with
|
match n.cell with
|
||||||
| Zero -> ()
|
| Zero -> ()
|
||||||
| One x ->
|
| One x ->
|
||||||
begin match f x with
|
begin match f x with
|
||||||
| None -> if Stdlib.(!=) d.cur.prev d.cur then remove_node_ n
|
| None -> if Stdlib.(!=) d.cur.prev d.cur then remove_node_ n
|
||||||
else n.cell <- Zero
|
else n.cell <- Zero
|
||||||
| Some x -> n.cell <- One x
|
| Some x -> n.cell <- One x
|
||||||
end
|
end
|
||||||
| Two (x, y) ->
|
| Two (x, y) ->
|
||||||
begin match f y with
|
begin match f y with
|
||||||
| None -> n.cell <- One (x)
|
| None -> n.cell <- One (x)
|
||||||
| Some y -> n.cell <- Two (x,y)
|
| Some y -> n.cell <- Two (x,y)
|
||||||
end
|
end
|
||||||
| Three (x,y,z) ->
|
| Three (x,y,z) ->
|
||||||
match f z with
|
begin match f z with
|
||||||
| None -> n.cell <- Two (x,y)
|
| None -> n.cell <- Two (x,y)
|
||||||
| Some z -> n.cell <- Three (x,y,z)
|
| Some z -> n.cell <- Three (x,y,z)
|
||||||
|
end
|
||||||
|
|
||||||
(*$T update_back
|
(*$T update_back
|
||||||
let q = of_list [1;2;3;4;5;6;7] in update_back q (fun _ -> None); to_list q = [1;2;3;4;5;6]
|
let q = of_list [1;2;3;4;5;6;7] in update_back q (fun _ -> None); to_list q = [1;2;3;4;5;6]
|
||||||
|
|
|
||||||
|
|
@ -83,10 +83,13 @@ val take_front_opt : 'a t -> 'a option
|
||||||
|
|
||||||
val update_back : 'a t -> ('a -> 'a option) -> unit
|
val update_back : 'a t -> ('a -> 'a option) -> unit
|
||||||
(** Update last value. If the deque is empty do nothing.
|
(** Update last value. If the deque is empty do nothing.
|
||||||
|
If the function returns [None], remove last element;
|
||||||
|
if it returns [Some x], replace last element with [x].
|
||||||
@since NEXT_RELEASE *)
|
@since NEXT_RELEASE *)
|
||||||
|
|
||||||
val update_front : 'a t -> ('a -> 'a option) -> unit
|
val update_front : 'a t -> ('a -> 'a option) -> unit
|
||||||
(** Update first value. If the deque is empty do nothing.
|
(** Update first value. If the deque is empty do nothing.
|
||||||
|
Similar to {!update_back} but for the first value.
|
||||||
@since NEXT_RELEASE *)
|
@since NEXT_RELEASE *)
|
||||||
|
|
||||||
val append_front : into:'a t -> 'a t -> unit
|
val append_front : into:'a t -> 'a t -> unit
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue