Sha256: 7fc4040244ba7646f6bccec7249c36ee11a2886418c694e791c74424fb99798d
Contents?: true
Size: 716 Bytes
Versions: 396
Compression:
Stored size: 716 Bytes
Contents
module CircularBuffer type CircularBuffer<'a> = { items: 'a list; size: int } let mkCircularBuffer size = { items = []; size = size } let clear buffer = { buffer with items = [] } let write value buffer = if List.length buffer.items = buffer.size then failwith "Cannot write to full buffer" else { buffer with items = buffer.items @ [value] } let forceWrite value buffer = if List.length buffer.items = buffer.size then { buffer with items = List.tail buffer.items @ [value] } else { buffer with items = buffer.items @ [value] } let read buffer = match buffer.items with | x::xs -> x, { buffer with items = xs } | [] -> failwith "Cannot read from empty buffer"
Version data entries
396 entries across 396 versions & 1 rubygems