mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-06 03:05:28 -05:00
Merge commit '8bb78ab0d6bf95eea46d0cdedd8462525f2e1f7d' for sequence (fix bug)
This commit is contained in:
commit
6e031a7c03
7 changed files with 55 additions and 30 deletions
5
Makefile
5
Makefile
|
|
@ -108,4 +108,7 @@ update_next_tag:
|
||||||
sed -i "s/NEXT_VERSION/$(VERSION)/g" **/*.ml **/*.mli
|
sed -i "s/NEXT_VERSION/$(VERSION)/g" **/*.ml **/*.mli
|
||||||
sed -i "s/NEXT_RELEASE/$(VERSION)/g" **/*.ml **/*.mli
|
sed -i "s/NEXT_RELEASE/$(VERSION)/g" **/*.ml **/*.mli
|
||||||
|
|
||||||
.PHONY: examples push_doc tags qtest
|
udpate_sequence:
|
||||||
|
git subtree pull --prefix sequence sequence stable --squash
|
||||||
|
|
||||||
|
.PHONY: examples push_doc tags qtest update_sequence
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,9 @@
|
||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## 0.5.3
|
||||||
|
|
||||||
|
- bugfix: interaction between `take` and `is_empty`
|
||||||
|
|
||||||
## 0.5.2
|
## 0.5.2
|
||||||
|
|
||||||
- bugfix in `take`
|
- bugfix in `take`
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
# OASIS_START
|
# OASIS_START
|
||||||
# DO NOT EDIT (digest: f4f3ee8dc8cda763af26a927b88956e6)
|
# DO NOT EDIT (digest: 99194977427ba82f5912e81125f6cac0)
|
||||||
version = "0.5.2"
|
version = "0.5.3"
|
||||||
description = "Simple sequence (iterator) datatype and combinators"
|
description = "Simple sequence (iterator) datatype and combinators"
|
||||||
archive(byte) = "sequence.cma"
|
archive(byte) = "sequence.cma"
|
||||||
archive(byte, plugin) = "sequence.cma"
|
archive(byte, plugin) = "sequence.cma"
|
||||||
|
|
@ -8,7 +8,7 @@ archive(native) = "sequence.cmxa"
|
||||||
archive(native, plugin) = "sequence.cmxs"
|
archive(native, plugin) = "sequence.cmxs"
|
||||||
exists_if = "sequence.cma"
|
exists_if = "sequence.cma"
|
||||||
package "invert" (
|
package "invert" (
|
||||||
version = "0.5.2"
|
version = "0.5.3"
|
||||||
description = "Simple sequence (iterator) datatype and combinators"
|
description = "Simple sequence (iterator) datatype and combinators"
|
||||||
requires = "sequence delimcc"
|
requires = "sequence delimcc"
|
||||||
archive(byte) = "invert.cma"
|
archive(byte) = "invert.cma"
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
OASISFormat: 0.4
|
OASISFormat: 0.4
|
||||||
Name: sequence
|
Name: sequence
|
||||||
Version: 0.5.2
|
Version: 0.5.3
|
||||||
Homepage: https://github.com/c-cube/sequence
|
Homepage: https://github.com/c-cube/sequence
|
||||||
Authors: Simon Cruanes
|
Authors: Simon Cruanes
|
||||||
License: BSD-2-clause
|
License: BSD-2-clause
|
||||||
|
|
@ -45,7 +45,7 @@ Document sequence
|
||||||
XOCamlbuildLibraries: sequence
|
XOCamlbuildLibraries: sequence
|
||||||
|
|
||||||
Test all
|
Test all
|
||||||
Type: custom
|
Type: custom (0.4)
|
||||||
Command: make run-tests
|
Command: make run-tests
|
||||||
TestTools: run_tests
|
TestTools: run_tests
|
||||||
Run$: flag(tests)
|
Run$: flag(tests)
|
||||||
|
|
|
||||||
|
|
@ -319,33 +319,37 @@ let min ?(lt=fun x y -> x < y) seq =
|
||||||
| Some y -> if lt x y then ret := Some x);
|
| Some y -> if lt x y then ret := Some x);
|
||||||
!ret
|
!ret
|
||||||
|
|
||||||
exception ExitSequence
|
exception ExitHead
|
||||||
|
|
||||||
let head seq =
|
let head seq =
|
||||||
let r = ref None in
|
let r = ref None in
|
||||||
try
|
try
|
||||||
seq (fun x -> r := Some x; raise ExitSequence); None
|
seq (fun x -> r := Some x; raise ExitHead); None
|
||||||
with ExitSequence -> !r
|
with ExitHead -> !r
|
||||||
|
|
||||||
let head_exn seq =
|
let head_exn seq =
|
||||||
match head seq with
|
match head seq with
|
||||||
| None -> invalid_arg "Sequence.head_exn"
|
| None -> invalid_arg "Sequence.head_exn"
|
||||||
| Some x -> x
|
| Some x -> x
|
||||||
|
|
||||||
|
exception ExitTake
|
||||||
|
|
||||||
let take n seq k =
|
let take n seq k =
|
||||||
let count = ref 0 in
|
let count = ref 0 in
|
||||||
try
|
try
|
||||||
seq (fun x ->
|
seq (fun x ->
|
||||||
if !count = n then raise ExitSequence;
|
if !count = n then raise ExitTake;
|
||||||
incr count;
|
incr count;
|
||||||
k x;
|
k x;
|
||||||
)
|
)
|
||||||
with ExitSequence -> ()
|
with ExitTake -> ()
|
||||||
|
|
||||||
|
exception ExitTakeWhile
|
||||||
|
|
||||||
let take_while p seq k =
|
let take_while p seq k =
|
||||||
try
|
try
|
||||||
seq (fun x -> if p x then k x else raise ExitSequence)
|
seq (fun x -> if p x then k x else raise ExitTakeWhile)
|
||||||
with ExitSequence -> ()
|
with ExitTakeWhile -> ()
|
||||||
|
|
||||||
let drop n seq k =
|
let drop n seq k =
|
||||||
let count = ref 0 in
|
let count = ref 0 in
|
||||||
|
|
@ -362,29 +366,35 @@ let rev seq =
|
||||||
let l = MList.of_seq seq in
|
let l = MList.of_seq seq in
|
||||||
fun k -> MList.iter_rev k l
|
fun k -> MList.iter_rev k l
|
||||||
|
|
||||||
|
exception ExitForall
|
||||||
|
|
||||||
let for_all p seq =
|
let for_all p seq =
|
||||||
try
|
try
|
||||||
seq (fun x -> if not (p x) then raise ExitSequence);
|
seq (fun x -> if not (p x) then raise ExitForall);
|
||||||
true
|
true
|
||||||
with ExitSequence -> false
|
with ExitForall -> false
|
||||||
|
|
||||||
|
exception ExitExists
|
||||||
|
|
||||||
(** Exists there some element satisfying the predicate? *)
|
(** Exists there some element satisfying the predicate? *)
|
||||||
let exists p seq =
|
let exists p seq =
|
||||||
try
|
try
|
||||||
seq (fun x -> if p x then raise ExitSequence);
|
seq (fun x -> if p x then raise ExitExists);
|
||||||
false
|
false
|
||||||
with ExitSequence -> true
|
with ExitExists -> true
|
||||||
|
|
||||||
let mem ?(eq=(=)) x seq = exists (eq x) seq
|
let mem ?(eq=(=)) x seq = exists (eq x) seq
|
||||||
|
|
||||||
|
exception ExitFind
|
||||||
|
|
||||||
let find f seq =
|
let find f seq =
|
||||||
let r = ref None in
|
let r = ref None in
|
||||||
begin try
|
begin try
|
||||||
seq (fun x -> match f x with
|
seq (fun x -> match f x with
|
||||||
| None -> ()
|
| None -> ()
|
||||||
| Some _ as res -> r := res
|
| Some _ as res -> r := res; raise ExitFind
|
||||||
);
|
);
|
||||||
with ExitSequence -> ()
|
with ExitFind -> ()
|
||||||
end;
|
end;
|
||||||
!r
|
!r
|
||||||
|
|
||||||
|
|
@ -393,17 +403,19 @@ let length seq =
|
||||||
seq (fun _ -> incr r);
|
seq (fun _ -> incr r);
|
||||||
!r
|
!r
|
||||||
|
|
||||||
|
exception ExitIsEmpty
|
||||||
|
|
||||||
let is_empty seq =
|
let is_empty seq =
|
||||||
try seq (fun _ -> raise ExitSequence); true
|
try seq (fun _ -> raise ExitIsEmpty); true
|
||||||
with ExitSequence -> false
|
with ExitIsEmpty -> false
|
||||||
|
|
||||||
(** {2 Transform a sequence} *)
|
(** {2 Transform a sequence} *)
|
||||||
|
|
||||||
let empty2 k = ()
|
let empty2 k = ()
|
||||||
|
|
||||||
let is_empty2 seq2 =
|
let is_empty2 seq2 =
|
||||||
try ignore (seq2 (fun _ _ -> raise ExitSequence)); true
|
try ignore (seq2 (fun _ _ -> raise ExitIsEmpty)); true
|
||||||
with ExitSequence -> false
|
with ExitIsEmpty -> false
|
||||||
|
|
||||||
let length2 seq2 =
|
let length2 seq2 =
|
||||||
let r = ref 0 in
|
let r = ref 0 in
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
(* setup.ml generated for the first time by OASIS v0.4.4 *)
|
(* setup.ml generated for the first time by OASIS v0.4.4 *)
|
||||||
|
|
||||||
(* OASIS_START *)
|
(* OASIS_START *)
|
||||||
(* DO NOT EDIT (digest: 3e1599f233d66e02cd17bbb3a1c71d9e) *)
|
(* DO NOT EDIT (digest: 1c260750474eb19b8e9212954217b6fd) *)
|
||||||
(*
|
(*
|
||||||
Regenerated by OASIS v0.4.4
|
Regenerated by OASIS v0.4.4
|
||||||
Visit http://oasis.forge.ocamlcore.org for more information and
|
Visit http://oasis.forge.ocamlcore.org for more information and
|
||||||
|
|
@ -6826,7 +6826,7 @@ let setup_t =
|
||||||
alpha_features = [];
|
alpha_features = [];
|
||||||
beta_features = [];
|
beta_features = [];
|
||||||
name = "sequence";
|
name = "sequence";
|
||||||
version = "0.5.2";
|
version = "0.5.3";
|
||||||
license =
|
license =
|
||||||
OASISLicense.DEP5License
|
OASISLicense.DEP5License
|
||||||
(OASISLicense.DEP5Unit
|
(OASISLicense.DEP5Unit
|
||||||
|
|
@ -7044,7 +7044,7 @@ let setup_t =
|
||||||
cs_plugin_data = []
|
cs_plugin_data = []
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
test_type = (`Test, "custom", None);
|
test_type = (`Test, "custom", Some "0.4");
|
||||||
test_command =
|
test_command =
|
||||||
[(OASISExpr.EBool true, ("make", ["run-tests"]))];
|
[(OASISExpr.EBool true, ("make", ["run-tests"]))];
|
||||||
test_custom =
|
test_custom =
|
||||||
|
|
@ -7192,8 +7192,7 @@ let setup_t =
|
||||||
};
|
};
|
||||||
oasis_fn = Some "_oasis";
|
oasis_fn = Some "_oasis";
|
||||||
oasis_version = "0.4.4";
|
oasis_version = "0.4.4";
|
||||||
oasis_digest =
|
oasis_digest = Some "\214\tqh\b\169>\243\237\213\012\180\162\155`L";
|
||||||
Some "\142\243\242-\024\139\245\030\1867\186\147D\175\251\192";
|
|
||||||
oasis_exec = None;
|
oasis_exec = None;
|
||||||
oasis_setup_args = [];
|
oasis_setup_args = [];
|
||||||
setup_update = false
|
setup_update = false
|
||||||
|
|
@ -7201,6 +7200,6 @@ let setup_t =
|
||||||
|
|
||||||
let setup () = BaseSetup.setup setup_t;;
|
let setup () = BaseSetup.setup setup_t;;
|
||||||
|
|
||||||
# 7205 "setup.ml"
|
# 7204 "setup.ml"
|
||||||
(* OASIS_STOP *)
|
(* OASIS_STOP *)
|
||||||
let () = setup ();;
|
let () = setup ();;
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,8 @@ open Sequence.Infix
|
||||||
|
|
||||||
let pp_ilist l =
|
let pp_ilist l =
|
||||||
let b = Buffer.create 15 in
|
let b = Buffer.create 15 in
|
||||||
Format.bprintf b "@[<h>%a@]" (S.pp_seq Format.pp_print_int) (S.of_list l);
|
let fmt = Format.formatter_of_buffer b in
|
||||||
|
Format.fprintf fmt "@[<h>%a@]" (S.pp_seq Format.pp_print_int) (S.of_list l);
|
||||||
Buffer.contents b
|
Buffer.contents b
|
||||||
|
|
||||||
let test_empty () =
|
let test_empty () =
|
||||||
|
|
@ -197,6 +198,11 @@ let test_take () =
|
||||||
OUnit.assert_equal ~printer:pp_ilist [1;2;3;4;5] l;
|
OUnit.assert_equal ~printer:pp_ilist [1;2;3;4;5] l;
|
||||||
()
|
()
|
||||||
|
|
||||||
|
let test_regression1 () =
|
||||||
|
let s = S.(take 10 (repeat 1)) in
|
||||||
|
OUnit.assert_bool "not empty" (not (S.is_empty s));
|
||||||
|
()
|
||||||
|
|
||||||
let suite =
|
let suite =
|
||||||
"test_sequence" >:::
|
"test_sequence" >:::
|
||||||
[ "test_empty" >:: test_empty;
|
[ "test_empty" >:: test_empty;
|
||||||
|
|
@ -225,4 +231,5 @@ let suite =
|
||||||
"test_hashtbl" >:: test_hashtbl;
|
"test_hashtbl" >:: test_hashtbl;
|
||||||
"test_int_range" >:: test_int_range;
|
"test_int_range" >:: test_int_range;
|
||||||
"test_take" >:: test_take;
|
"test_take" >:: test_take;
|
||||||
|
"test_regression1" >:: test_regression1
|
||||||
]
|
]
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue