lib.bend checks
raw source on the hub · import 0x831d2a84246839cb2e33f4e7653d3f09/lib.bend as Lib
RingBuf — fixed-capacity FIFO ring buffer for U32 values. Depends only on Base. Capacity is a Nat so any non-negative capacity is valid.
The backing storage is a fixed List of slots. start points at the logical
front and len is the number of live values; physical indices wrap modulo
capacity. Empty slots contain 0 and are never observable through the API.
push is fail-if-full: it returns None when the buffer is full and Some of
the updated buffer otherwise. It never overwrites an existing value.
1 import
import Base
Types
type RingBuf source · line 12 · raw
Data
RB@capacity:Nat -> @start:Nat -> @len:Nat -> @slots:List<&2, U32> -> RingBuf
type RingBuf.Push source · line 15 · raw
Data
PushResult@buffer:RingBuf -> RingBuf.Push
type RingBuf.Pop source · line 18 · raw
Data
PopResult@value:U32 -> @rest:RingBuf -> RingBuf.Pop
Definitions
def RingBuf.new source · line 23 · raw
@+capacity:Nat -> RingBuf
Allocate exactly capacity slots. A zero-capacity buffer is valid but cannot accept pushes.
def RingBuf.empty source · line 26 · raw
@capacity:Nat -> RingBuf
def RingBuf.capacity source · line 29 · raw
@r:RingBuf -> Nat
def RingBuf.length source · line 34 · raw
@r:RingBuf -> Nat
def RingBuf.is_empty source · line 39 · raw
@r:RingBuf -> Bool
def RingBuf.is_full source · line 42 · raw
@+r:RingBuf -> Bool
def RingBuf.read source · line 46 · raw
@slots:List<&2, U32> -> @index:Nat -> U32
Read a slot. Internal buffers always have a slot at every valid index.
def RingBuf.push.go source · line 49 · raw
@+capacity:Nat -> @+start:Nat -> @+len:Nat -> @slots:List<&2, U32> -> @x:U32 -> @available:Bool -> Maybe<&2, RingBuf.Push>
def RingBuf.push source · line 61 · raw
@r:RingBuf -> @x:U32 -> Maybe<&2, RingBuf.Push>
def RingBuf.pop.go source · line 66 · raw
@+capacity:Nat -> @+start:Nat -> @len:Nat -> @+slots:List<&2, U32> -> Maybe<&2, RingBuf.Pop>
def RingBuf.pop source · line 77 · raw
@r:RingBuf -> Maybe<&2, RingBuf.Pop>
def RingBuf.peek source · line 82 · raw
@r:RingBuf -> Maybe<&2, U32>
def RingBuf.to_list.go source · line 91 · raw
@+work:List<&2, Unit> -> @+capacity:Nat -> @+slots:List<&2, U32> -> @+index:Nat -> List<&2, U32>
def RingBuf.to_list source · line 102 · raw
@r:RingBuf -> List<&2, U32>