~/bend-docscommunity

array.bend checks

raw source on the hub · import bend-osdev-array@0.1.0.0/array.bend as MArray

bend-osdev-array: laws about Base's Array, the specification they are stated in, and the list model they are stated against.

Base defines Array<T> in Bend itself, as a tree of ALeaf / ANode, and indexes it by U32 (Array.size, Array.swap, Array.set, Array.get, Array.new). An array built by Array.new(T, d, v) is a perfect tree of depth d: 2^d slots, every leaf at depth d. Array.get and Array.set mask the index to its low d bits, so they read and write slot Arrays.index(d, i).

This file holds only the vocabulary the laws use; LAWS.bend states them and PROOF.bend proves them.

1 import
import Base

Definitions

def Arrays.slots source · line 15 · raw

@d:Nat -> Nat

2^d, the slot count of an array of depth d

def Arrays.is_perfect source · line 24 · raw

@-T:Type -> @+d:Nat -> @a:Array<T> -> Bool

whether a is a perfect tree of depth d (every leaf at depth d), the shape Array.new builds and Array.set keeps

def Arrays.leaves source · line 37 · raw

@-T:Data -> @a:Array<T> -> List<&2, T>

the slots of an array, in index order: the list model the laws compare Array.get and Array.set with (a specification: it walks the whole array)

def Arrays.index source · line 46 · raw

@d:Nat -> @i:U32 -> Nat

the slot that Array.get and Array.set use for index i on an array of depth d: i masked to its low d bits, as Base computes it

def Arrays.nth.or source · line 50 · raw

@-T:Data -> @m:Maybe<&2, T> -> @fill:T -> T

The list model's element at slot k, or fill past its end

def Arrays.nth source · line 57 · raw

@-T:Data -> @xs:List<&2, T> -> @k:Nat -> @fill:T -> T

def Arrays.of_list source · line 63 · raw

@-T:Data -> @+d:Nat -> @+xs:List<&2, T> -> @+fill:T -> Array<T>

The perfect array of depth d whose slots are xs in order (cut to 2^d slots, or padded with fill): an array built from a Data list, so that a proof can name it as often as it likes (a specification, like leaves)