vmm_ring revise implementation
This commit is contained in:
parent
8a113e5ce0
commit
ec9f00b39a
|
@ -19,13 +19,21 @@ let write t entry =
|
||||||
|
|
||||||
let dec t n = (pred n + t.size) mod t.size
|
let dec t n = (pred n + t.size) mod t.size
|
||||||
|
|
||||||
|
let get_valid t idx =
|
||||||
|
let our = Array.get t.data idx in
|
||||||
|
if Ptime.equal (fst our) Ptime.min then
|
||||||
|
None
|
||||||
|
else
|
||||||
|
Some our
|
||||||
|
|
||||||
let read_last t ?(tst = fun _ -> true) n =
|
let read_last t ?(tst = fun _ -> true) n =
|
||||||
let rec one idx count acc =
|
let rec one idx count acc =
|
||||||
let our = Array.get t.data idx in
|
if count = 0 then
|
||||||
|
acc
|
||||||
|
else match get_valid t idx with
|
||||||
|
| None -> acc
|
||||||
|
| Some our ->
|
||||||
if tst (snd our) then
|
if tst (snd our) then
|
||||||
if pred count = 0 then
|
|
||||||
our :: acc
|
|
||||||
else
|
|
||||||
one (dec t idx) (pred count) (our :: acc)
|
one (dec t idx) (pred count) (our :: acc)
|
||||||
else
|
else
|
||||||
one (dec t idx) count acc
|
one (dec t idx) count acc
|
||||||
|
@ -33,16 +41,15 @@ let read_last t ?(tst = fun _ -> true) n =
|
||||||
one (dec t t.write) n []
|
one (dec t t.write) n []
|
||||||
|
|
||||||
let read_history t ?(tst = fun _ -> true) since =
|
let read_history t ?(tst = fun _ -> true) since =
|
||||||
let rec go acc idx =
|
let rec go idx acc =
|
||||||
let entry = Array.get t.data idx in
|
match get_valid t idx with
|
||||||
if Ptime.equal (fst entry) Ptime.min then
|
| None -> acc
|
||||||
acc
|
| Some entry ->
|
||||||
else if tst (snd entry) then
|
|
||||||
if Ptime.is_earlier (fst entry) ~than:since then
|
if Ptime.is_earlier (fst entry) ~than:since then
|
||||||
acc
|
acc
|
||||||
|
else if tst (snd entry) then
|
||||||
|
go (dec t idx) (entry :: acc)
|
||||||
else
|
else
|
||||||
go (entry :: acc) (dec t idx)
|
go (dec t idx) acc
|
||||||
else
|
|
||||||
go acc (dec t idx)
|
|
||||||
in
|
in
|
||||||
go [] (dec t t.write)
|
go (dec t t.write) []
|
||||||
|
|
Loading…
Reference in a new issue