talircd/lib/data/wheel.ml

25 lines
447 B
OCaml
Raw Normal View History

type 'a t = {
entries : 'a Dllist.t array;
mutable index : int;
}
let make n = {
entries = Array.init n (fun _ -> Dllist.create ());
index = 0;
}
let queue t =
t.entries.(t.index)
let add t v =
Dllist.add_r v (queue t) |> ignore
let[@tail_mod_cons] rec empty t =
match Dllist.take_l (queue t) with
| x -> x :: empty t
| exception Not_found -> []
let tick t =
t.index <- (t.index + 1) mod Array.length t.entries;
empty t