vmmd_console: further refactoring
This commit is contained in:
parent
eb146351e0
commit
84e7dee81b
|
@ -19,38 +19,25 @@ 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 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 =
|
let rec go s acc idx =
|
||||||
if idx = s then (* don't read it twice *)
|
if idx = s then (* don't read it twice *)
|
||||||
acc
|
acc
|
||||||
else
|
else
|
||||||
let entry = Array.get t.data idx in
|
let entry = Array.get t.data idx in
|
||||||
if written entry then go s (entry :: acc) (dec t idx)
|
if tst entry then acc else go s (entry :: acc) (dec t idx)
|
||||||
else acc
|
|
||||||
in
|
in
|
||||||
let idx = dec t t.write in
|
let idx = dec t t.write in
|
||||||
let s =
|
|
||||||
let entry = Array.get t.data idx in
|
let entry = Array.get t.data idx in
|
||||||
if written entry then [entry] else []
|
if tst entry then [] else go idx [entry] (dec t idx)
|
||||||
in
|
|
||||||
go idx s (dec t idx)
|
|
||||||
|
|
||||||
let earlier ts than =
|
let read t = read_some entry_not_written t
|
||||||
if ts = Ptime.min then true
|
|
||||||
else Ptime.is_earlier ts ~than
|
|
||||||
|
|
||||||
let read_history t than =
|
let read_history t than = read_some (earlier than) t
|
||||||
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)
|
|
||||||
|
|
Loading…
Reference in a new issue