vmmd_console: further refactoring

This commit is contained in:
Hannes Mehnert 2019-01-27 13:10:09 +01:00
parent eb146351e0
commit 84e7dee81b

View file

@ -19,38 +19,25 @@ let write t entry =
let dec t n = (pred n + t.size) mod t.size
let written (ts, _) = not (Ptime.equal ts Ptime.min)
let not_written ts = Ptime.equal ts Ptime.min
let read t =
let entry_not_written (ts, _) = not_written ts
let earlier than (ts, v) =
if not_written ts then true else Ptime.is_earlier ts ~than
let read_some tst t =
let rec go s acc idx =
if idx = s then (* don't read it twice *)
acc
else
let entry = Array.get t.data idx in
if written entry then go s (entry :: acc) (dec t idx)
else acc
if tst entry then acc else go s (entry :: acc) (dec t idx)
in
let idx = dec t t.write in
let s =
let entry = Array.get t.data idx in
if written entry then [entry] else []
in
go idx s (dec t idx)
if tst entry then [] else go idx [entry] (dec t idx)
let earlier ts than =
if ts = Ptime.min then true
else Ptime.is_earlier ts ~than
let read t = read_some entry_not_written t
let read_history t than =
let rec go s acc idx =
if idx = s then (* don't read it twice *)
acc
else
let ts, v = Array.get t.data idx in
if earlier ts than then acc
else go s ((ts, v) :: acc) (dec t idx)
in
let idx = dec t t.write in
let ts, v = Array.get t.data idx in
if earlier ts than then []
else go idx [(ts,v)] (dec t idx)
let read_history t than = read_some (earlier than) t