~/bend-docscommunity

defs.bend checks

raw source on the hub · import lawful-bytes@0.1.1.0/defs.bend as Defs

3 imports
import Base
import lawful-words@0.1.0.0/defs.bend as W
import lawful-arrays@0.1.0.0/defs.bend as A

Types

type Bytes source · line 11 · raw

Type

Bytes packed four to a word, little-endian, in a block of 2^d words: byte i is byte i & 3 of word i >> 2. len is the number of bytes in use; the bytes past len are unspecified.

Definitions

def unpack source · line 15 · raw

@ws:List<&2, U32> -> List<&2, U32>

The four bytes of each word, in order.

def view source · line 23 · raw

@b:Bytes -> List<&2, U32>

What a Bytes holds: its first len bytes.

def size source · line 28 · raw

@b:Bytes -> Nat

The number of bytes in use.

def cap source · line 33 · raw

@b:Bytes -> Nat

How many bytes fit: four per word.

def ok source · line 41 · raw

@b:Bytes -> @+d:Nat -> Bool

b is well formed with a block of depth d: a perfect block of 2^d words, d <= 29, and len within the block. A buffer holds at most 2^31 bytes (2 GiB), so every index and length fits in a U32; the laws' hypotheses keep sums of lengths in range too. Larger files are read in pieces.

def all_bytes source · line 46 · raw

@xs:List<&2, U32> -> Bool

Every element is a byte (below 256).

def slice source · line 54 · raw

@xs:List<&2, U32> -> @+i:Nat -> @+n:Nat -> List<&2, U32>

n elements from index i.

def run_len source · line 58 · raw

@xs:List<&2, U32> -> @+c:U32 -> Nat

How many leading elements are not c.

def run_len2 source · line 66 · raw

@xs:List<&2, U32> -> @+c1:U32 -> @+c2:U32 -> Nat

How many leading elements are neither c1 nor c2.

def first source · line 75 · raw

@xs:List<&2, U32> -> @+from:Nat -> @+to:Nat -> @+c:U32 -> Nat

The first index j with from <= j < to where xs has c; to if there is none (for from <= to <= length(xs), as the laws assume).

def first2 source · line 79 · raw

@xs:List<&2, U32> -> @+from:Nat -> @+to:Nat -> @+c1:U32 -> @+c2:U32 -> Nat

The same for either of two values (same assumptions).

def list_eq source · line 83 · raw

@xs:List<&2, U32> -> @ys:List<&2, U32> -> Bool

Two lists are equal, element by element.

def is_some source · line 95 · raw

@m:Maybe<&2, U32> -> @+c:U32 -> Bool

xs has c at index k.

def has source · line 102 · raw

@xs:List<&2, U32> -> @+k:Nat -> @+c:U32 -> Bool

def has2 source · line 106 · raw

@+xs:List<&2, U32> -> @+k:Nat -> @+c1:U32 -> @+c2:U32 -> Bool

xs has c1 or c2 at index k.