~/bend-docscommunity

pure.bend checks

raw source on the hub · import bend-kit-storage@0.8.0.0/pure.bend as Pure

Pure storage model, digest ordering, and canonical encoding.

4 imports
import Base
import bend-kit-bytes@0.3.3.1/bytes.bend as Bytes
import bend-kit-collections@0.1.6.0/omap.bend as OMap
import bend-kit-collections@0.1.6.0/order.bend as Order

Types

type Tree source · line 8 · raw

@-B:Data -> Data

The content: a file, or a directory as a chain of named entries that ends in End.

type Obj source · line 14 · raw

@-D:Data -> @-B:Data -> Data

One stored object. An OItem names its child and the rest of its directory by digest.

type Store source · line 21 · raw

@-D:Data -> @-B:Data -> Data

Objects by digest, as a list: the model the laws reason about. get answers the first entry whose digest eq accepts. Index below answers the same in O(log n) comparisons.

type Blob source · line 405 · raw

Data

File octets and the SHA-256 of their canonical file encoding.

type Digest source · line 481 · raw

Data

A SHA-256 digest: its 32 octets packed four to a U32, low octet first, as Bytes packs them.

Definitions

def Store.new source · line 25 · raw

@-D:Data -> @-B:Data -> Store<D, B>

def Store.put.if source · line 52 · raw

@-D:Data -> @-B:Data -> @found:Bool -> @s:Store<D, B> -> @d:D -> @o:Obj<D, B> -> Store<D, B>

def Store.size source · line 71 · raw

@-D:Data -> @-B:Data -> @s:Store<D, B> -> U32

def Store.cat source · line 79 · raw

@-D:Data -> @-B:Data -> @xs:Store<D, B> -> @ys:Store<D, B> -> Store<D, B>

xs, then ys.

def Tree.item source · line 87 · raw

@-B:Data -> @n:String -> @c:Maybe<&2, Tree<B>> -> @r:Maybe<&2, Tree<B>> -> Maybe<&2, Tree<B>>

Some only when both halves loaded.

def closure.item source · line 114 · raw

@-D:Data -> @-B:Data -> @d:D -> @o:Obj<D, B> -> @c:Maybe<&2, Store<D, B>> -> @r:Maybe<&2, Store<D, B>> -> Maybe<&2, Store<D, B>>

def live.cat source · line 176 · raw

@-D:Data -> @-B:Data -> @a:Maybe<&2, Store<D, B>> -> @b:Maybe<&2, Store<D, B>> -> Maybe<&2, Store<D, B>>

def keep.if source · line 201 · raw

@-D:Data -> @-B:Data -> @live:Bool -> @k:D -> @o:Obj<D, B> -> @r:Store<D, B> -> Store<D, B>

def admit.if source · line 227 · raw

@-D:Data -> @-B:Data -> @ok:Bool -> @s:Store<D, B> -> @keep:Store<D, B> -> Maybe<&2, Store<D, B>>

def fits source · line 261 · raw

@-B:Data -> @fuel:Nat -> @t:Tree<B> -> Bool

True when load with this fuel reaches every node of t.

def Index source · line 283 · raw

@-D:Data -> @-B:Data -> Data

def Index.new source · line 286 · raw

@-D:Data -> @-B:Data -> Index(D, B)

def Index.size source · line 289 · raw

@-D:Data -> @-B:Data -> @m:Index(D, B) -> U32

def Index.admit.if source · line 391 · raw

@-D:Data -> @-B:Data -> @ok:Bool -> @s:Index(D, B) -> Maybe<&2, Index(D, B)>

def Blob.read source · line 409 · raw

@n:Nat -> @r:Pair(Array<U32>, U32) -> @+i:U32 -> @acc:List<&2, U32> -> List<&2, U32>

r is the array beside the word read at i - 1.

def Blob.pack source · line 417 · raw

@d:Digest -> @b:0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes -> Blob

def Blob.write source · line 421 · raw

@ws:List<&2, U32> -> @a:Array<U32> -> @+i:U32 -> Array<U32>

def Blob.bytes source · line 428 · raw

@x:Blob -> 0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes

def Blob.write.last source · line 433 · raw

@zero:Bool -> @a:Array<U32> -> @+j:U32 -> @+carry:U32 -> Array<U32>

A zero last carry may lie past the array, where a write would wrap to word 0.

def Blob.write.shift source · line 441 · raw

@ws:List<&2, U32> -> @a:Array<U32> -> @+j:U32 -> @+lo:Nat -> @+hi:Nat -> @+carry:U32 -> Array<U32>

Writes ws from octet 4 * j + lo / 8 on; carry holds the octets of word j below lo.

def limit source · line 450 · raw

Nat

Loads and collections give up past this many levels. Each directory entry is one level.

def char.ok source · line 453 · raw

@+c:U32 -> Bool

def chars.ok source · line 456 · raw

@s:String -> Bool

def name.ok source · line 464 · raw

@+n:String -> Bool

A directory entry name: one to 255 octets, not "." or "..", with no NUL, newline, or "/".

def hex.ok source · line 469 · raw

@s:String -> Bool

def digest.ok source · line 477 · raw

@+d:String -> Bool

64 lowercase hex characters.

def Digest.order source · line 484 · raw

@a:List<&2, U32> -> @b:List<&2, U32> -> Cmp

def Digest.cmp source · line 496 · raw

@a:Digest -> @b:Digest -> Cmp

A total order on digests (the digest_cmp_ laws). It is not hex order.

def Digest.hex source · line 501 · raw

@d:Digest -> String

def nibble source · line 506 · raw

@+c:U32 -> U32

def unhex source · line 510 · raw

@s:String -> List<&2, U32>

Two hex digits per octet.

def pack source · line 518 · raw

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

Four octets per word, low octet first.

def Digest.read.if source · line 525 · raw

@ok:Bool -> @s:String -> Maybe<&2, Digest>

def Digest.read source · line 533 · raw

@+s:String -> Maybe<&2, Digest>

The digest that 64 lowercase hex characters name, or None.

def encode.file.at source · line 536 · raw

@+len:U32 -> @ws:List<&2, U32> -> @+hl:U32 -> @r:Pair(Array<U32>, U32) -> 0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes

def encode.file.pick source · line 541 · raw

@aligned:Bool -> @+len:U32 -> @ws:List<&2, U32> -> @+hl:U32 -> @a:Array<U32> -> 0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes

def encode.file source · line 549 · raw

@+len:U32 -> @ws:List<&2, U32> -> @h:0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes -> 0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes

The header h, then the words of a Blob of len octets, written once without a byte loop.

def encode source · line 554 · raw

@o:Obj<Digest, Blob> -> 0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes

The canonical encoding: "file <len>\n" and the octets, "end\n", or "item <child> <rest> <name>\n".

def digest.of source · line 565 · raw

@r:Pair(U32, Array<U32>) -> Digest

def decode.when source · line 569 · raw

@ok:Bool -> @o:Obj<Digest, Blob> -> Maybe<&2, Obj<Digest, Blob>>

def decode.item.of source · line 576 · raw

@ok:Bool -> @n:String -> @c:Maybe<&2, Digest> -> @r:Maybe<&2, Digest> -> Maybe<&2, Obj<Digest, Blob>>

def decode.item source · line 584 · raw

@+rest:String -> Maybe<&2, Obj<Digest, Blob>>

rest is "<child> <rest> <name>".

def decode.file source · line 590 · raw

@m:Maybe<&2, U32> -> @d:Digest -> @+digits:String -> @+at:U32 -> @b:0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes -> Maybe<&2, Obj<Digest, Blob>>

def decode.head source · line 599 · raw

@d:Digest -> @+head:String -> @+at:U32 -> @b:0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes -> Maybe<&2, Obj<Digest, Blob>>

def decode.cut source · line 608 · raw

@d:Digest -> @+at:U32 -> @r:Pair(0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes, 0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes) -> Maybe<&2, Obj<Digest, Blob>>

def decode.at source · line 612 · raw

@d:Digest -> @r:Pair(0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes, Maybe<&2, U32>) -> Maybe<&2, Obj<Digest, Blob>>

def decode.hashed source · line 619 · raw

@d:Digest -> @b:0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes -> Maybe<&2, Obj<Digest, Blob>>

def digests.add source · line 622 · raw

@m:Maybe<&2, Digest> -> @ds:List<&2, Digest> -> List<&2, Digest>

def digests source · line 630 · raw

@names:List<&2, String> -> List<&2, Digest>

The digests that names name. Other names are left out.

Templates

template Store.head source · line 29 · raw

@-D:Data -> @-B:Data -> @-eq:(@_:D -> @_:D -> Bool) -> @s:Store<D, B> -> @+d:D -> Bool

eq(d, first key), or False when s is empty.

template Store.get.go source · line 37 · raw

@-D:Data -> @-B:Data -> @-eq:(@_:D -> @_:D -> Bool) -> @s:Store<D, B> -> @+d:D -> @hit:Bool -> Maybe<&2, Obj<D, B>>

hit is Store.head(s, d), so the walk stops at the first match.

template Store.get source · line 46 · raw

@-D:Data -> @-B:Data -> @-eq:(@_:D -> @_:D -> Bool) -> @+s:Store<D, B> -> @+d:D -> Maybe<&2, Obj<D, B>>

template Store.has source · line 49 · raw

@-D:Data -> @-B:Data -> @-eq:(@_:D -> @_:D -> Bool) -> @+s:Store<D, B> -> @+d:D -> Bool

template Store.put source · line 60 · raw

@-D:Data -> @-B:Data -> @-eq:(@_:D -> @_:D -> Bool) -> @+s:Store<D, B> -> @+d:D -> @o:Obj<D, B> -> Store<D, B>

Adds o under d unless d is present. The first object under a digest stays.

template Store.apply source · line 64 · raw

@-D:Data -> @-B:Data -> @-eq:(@_:D -> @_:D -> Bool) -> @xs:Store<D, B> -> @+s:Store<D, B> -> Store<D, B>

Puts each (digest, object) in order.

template load.go source · line 97 · raw

@-D:Data -> @-B:Data -> @-eq:(@_:D -> @_:D -> Bool) -> @fuel:Nat -> @+s:Store<D, B> -> @m:Maybe<&2, Obj<D, B>> -> Maybe<&2, Tree<B>>

m is the object under the digest being loaded.

template load source · line 111 · raw

@-D:Data -> @-B:Data -> @-eq:(@_:D -> @_:D -> Bool) -> @fuel:Nat -> @+s:Store<D, B> -> @+d:D -> Maybe<&2, Tree<B>>

The tree under d, or None when an object is missing or the tree is deeper than fuel.

template closure.go source · line 123 · raw

@-D:Data -> @-B:Data -> @-eq:(@_:D -> @_:D -> Bool) -> @fuel:Nat -> @+s:Store<D, B> -> @+d:D -> @m:Maybe<&2, Obj<D, B>> -> Maybe<&2, Store<D, B>>

template closure source · line 139 · raw

@-D:Data -> @-B:Data -> @-eq:(@_:D -> @_:D -> Bool) -> @fuel:Nat -> @+s:Store<D, B> -> @+d:D -> Maybe<&2, Store<D, B>>

Every object that load(fuel, s, d) reads, parents first, or None when load fails.

template need.head source · line 143 · raw

@-D:Data -> @-B:Data -> @-eq:(@_:D -> @_:D -> Bool) -> @+t:Store<D, B> -> @xs:Store<D, B> -> Bool

Store.has(t, first digest of xs), or False when xs is empty.

template need.go source · line 151 · raw

@-D:Data -> @-B:Data -> @-eq:(@_:D -> @_:D -> Bool) -> @xs:Store<D, B> -> @+t:Store<D, B> -> @found:Bool -> Store<D, B>

found is need.head(t, xs), so only the taken branch recurses.

template need source · line 162 · raw

@-D:Data -> @-B:Data -> @-eq:(@_:D -> @_:D -> Bool) -> @+xs:Store<D, B> -> @+t:Store<D, B> -> Store<D, B>

The entries of xs whose digest t lacks, each digest once. t grows as entries are taken.

template plan.of source · line 165 · raw

@-D:Data -> @-B:Data -> @-eq:(@_:D -> @_:D -> Bool) -> @+dst:Store<D, B> -> @m:Maybe<&2, Store<D, B>> -> Maybe<&2, Store<D, B>>

template plan source · line 173 · raw

@-D:Data -> @-B:Data -> @-eq:(@_:D -> @_:D -> Bool) -> @fuel:Nat -> @+src:Store<D, B> -> @+dst:Store<D, B> -> @+root:D -> Maybe<&2, Store<D, B>>

The objects dst needs to load root as src does, or None when src cannot load root.

template live source · line 186 · raw

@-D:Data -> @-B:Data -> @-eq:(@_:D -> @_:D -> Bool) -> @+fuel:Nat -> @+s:Store<D, B> -> @roots:List<&2, D> -> Maybe<&2, Store<D, B>>

The closures of every root, or None when one root does not load.

template mem source · line 194 · raw

@-D:Data -> @-B:Data -> @-eq:(@_:D -> @_:D -> Bool) -> @ls:Store<D, B> -> @+d:D -> Bool

eq(d, k) for some entry (k, o) of ls.

template keep source · line 209 · raw

@-D:Data -> @-B:Data -> @-eq:(@_:D -> @_:D -> Bool) -> @s:Store<D, B> -> @+ls:Store<D, B> -> Store<D, B>

The entries of s whose digest is in ls.

template gc.of source · line 216 · raw

@-D:Data -> @-B:Data -> @-eq:(@_:D -> @_:D -> Bool) -> @s:Store<D, B> -> @m:Maybe<&2, Store<D, B>> -> Maybe<&2, Store<D, B>>

template gc source · line 224 · raw

@-D:Data -> @-B:Data -> @-eq:(@_:D -> @_:D -> Bool) -> @fuel:Nat -> @+s:Store<D, B> -> @+roots:List<&2, D> -> Maybe<&2, Store<D, B>>

s without the objects that no retained root reaches, or None when a root does not load.

template admit source · line 235 · raw

@-D:Data -> @-B:Data -> @-eq:(@_:D -> @_:D -> Bool) -> @+s:Store<D, B> -> @+claimed:D -> @+computed:D -> @o:Obj<D, B> -> Maybe<&2, Store<D, B>>

Ingress: computed is the digest of o's encoding. None when it is not the claimed digest.

template hash source · line 239 · raw

@-D:Data -> @-B:Data -> @-H:(@_:Obj<D, B> -> D) -> @t:Tree<B> -> D

The Merkle digest of t under the object hash H.

template objects source · line 249 · raw

@-D:Data -> @-B:Data -> @-H:(@_:Obj<D, B> -> D) -> @t:Tree<B> -> Store<D, B>

The objects of t with their digests, children before parents; hash(t) is the last digest.

template valid source · line 273 · raw

@-D:Data -> @-B:Data -> @-H:(@_:Obj<D, B> -> D) -> @-eq:(@_:D -> @_:D -> Bool) -> @s:Store<D, B> -> Bool

True when every entry (k, o) has eq(k, H(o)).

template Index.get source · line 292 · raw

@-D:Data -> @-B:Data -> @-cmp:(@_:D -> @_:D -> Cmp) -> @m:Index(D, B) -> @+d:D -> Maybe<&2, Obj<D, B>>

template Index.has source · line 295 · raw

@-D:Data -> @-B:Data -> @-cmp:(@_:D -> @_:D -> Cmp) -> @m:Index(D, B) -> @+d:D -> Bool

template Index.put.if source · line 298 · raw

@-D:Data -> @-B:Data -> @-cmp:(@_:D -> @_:D -> Cmp) -> @found:Bool -> @m:Index(D, B) -> @+d:D -> @o:Obj<D, B> -> Index(D, B)

template Index.put source · line 306 · raw

@-D:Data -> @-B:Data -> @-cmp:(@_:D -> @_:D -> Cmp) -> @+m:Index(D, B) -> @+d:D -> @o:Obj<D, B> -> Index(D, B)

Adds o under d unless d is present, as Store.put does.

template Index.apply source · line 310 · raw

@-D:Data -> @-B:Data -> @-cmp:(@_:D -> @_:D -> Cmp) -> @xs:Store<D, B> -> @+m:Index(D, B) -> Index(D, B)

Puts each (digest, object) in order.

template Index.of source · line 317 · raw

@-D:Data -> @-B:Data -> @-cmp:(@_:D -> @_:D -> Cmp) -> @xs:Store<D, B> -> Index(D, B)

template Index.load.go source · line 320 · raw

@-D:Data -> @-B:Data -> @-cmp:(@_:D -> @_:D -> Cmp) -> @fuel:Nat -> @+s:Index(D, B) -> @m:Maybe<&2, Obj<D, B>> -> Maybe<&2, Tree<B>>

template Index.load source · line 333 · raw

@-D:Data -> @-B:Data -> @-cmp:(@_:D -> @_:D -> Cmp) -> @fuel:Nat -> @+s:Index(D, B) -> @+d:D -> Maybe<&2, Tree<B>>

template Index.closure.go source · line 336 · raw

@-D:Data -> @-B:Data -> @-cmp:(@_:D -> @_:D -> Cmp) -> @fuel:Nat -> @+s:Index(D, B) -> @+d:D -> @m:Maybe<&2, Obj<D, B>> -> Maybe<&2, Store<D, B>>

template Index.closure source · line 351 · raw

@-D:Data -> @-B:Data -> @-cmp:(@_:D -> @_:D -> Cmp) -> @fuel:Nat -> @+s:Index(D, B) -> @+d:D -> Maybe<&2, Store<D, B>>

template Index.need.head source · line 354 · raw

@-D:Data -> @-B:Data -> @-cmp:(@_:D -> @_:D -> Cmp) -> @+t:Index(D, B) -> @xs:Store<D, B> -> Bool

template Index.need.go source · line 361 · raw

@-D:Data -> @-B:Data -> @-cmp:(@_:D -> @_:D -> Cmp) -> @xs:Store<D, B> -> @+t:Index(D, B) -> @found:Bool -> Store<D, B>

template Index.need source · line 371 · raw

@-D:Data -> @-B:Data -> @-cmp:(@_:D -> @_:D -> Cmp) -> @+xs:Store<D, B> -> @+t:Index(D, B) -> Store<D, B>

template Index.plan.of source · line 374 · raw

@-D:Data -> @-B:Data -> @-cmp:(@_:D -> @_:D -> Cmp) -> @+dst:Index(D, B) -> @m:Maybe<&2, Store<D, B>> -> Maybe<&2, Store<D, B>>

template Index.plan source · line 381 · raw

@-D:Data -> @-B:Data -> @-cmp:(@_:D -> @_:D -> Cmp) -> @fuel:Nat -> @+src:Index(D, B) -> @+dst:Index(D, B) -> @+root:D -> Maybe<&2, Store<D, B>>

template Index.live source · line 384 · raw

@-D:Data -> @-B:Data -> @-cmp:(@_:D -> @_:D -> Cmp) -> @+fuel:Nat -> @+s:Index(D, B) -> @roots:List<&2, D> -> Maybe<&2, Store<D, B>>

template Index.admit source · line 399 · raw

@-D:Data -> @-B:Data -> @-cmp:(@_:D -> @_:D -> Cmp) -> @+s:Index(D, B) -> @+claimed:D -> @+computed:D -> @o:Obj<D, B> -> Maybe<&2, Index(D, B)>

admit on an index: None when claimed is not computed.