add Wheel.iter for arbitrary order iteration
This commit is contained in:
parent
69f182d0c2
commit
04478ffa0e
|
@ -25,6 +25,11 @@ let%expect_test _ =
|
||||||
Wheel.add wh 6 |> ignore;
|
Wheel.add wh 6 |> ignore;
|
||||||
(* t=3 *)
|
(* t=3 *)
|
||||||
print_ints_nl (Wheel.tick wh); [%expect {| [] |}];
|
print_ints_nl (Wheel.tick wh); [%expect {| [] |}];
|
||||||
|
|
||||||
|
let every = ref [] in
|
||||||
|
Wheel.iter (fun x -> every := x :: !every) wh;
|
||||||
|
print_ints_nl (List.sort compare !every); [%expect {| [1;2;3;4;5;6] |}];
|
||||||
|
|
||||||
(* t=0 *)
|
(* t=0 *)
|
||||||
print_ints_nl (Wheel.tick wh); [%expect {| [1;2;3] |}];
|
print_ints_nl (Wheel.tick wh); [%expect {| [1;2;3] |}];
|
||||||
(* t=1 *)
|
(* t=1 *)
|
||||||
|
|
|
@ -22,3 +22,8 @@ let[@tail_mod_cons] rec empty t =
|
||||||
let tick t =
|
let tick t =
|
||||||
t.index <- (t.index + 1) mod Array.length t.entries;
|
t.index <- (t.index + 1) mod Array.length t.entries;
|
||||||
empty t
|
empty t
|
||||||
|
|
||||||
|
let iter f t =
|
||||||
|
for i = 0 to Array.length t.entries - 1 do
|
||||||
|
Dllist.iter_l f t.entries.(i)
|
||||||
|
done
|
||||||
|
|
Loading…
Reference in New Issue