No matching definitions.

tur/sized-buf

stdlib/sized-buf.tur

SizedBuf: flat contiguous memory layout for sized types.

Since: Phase SZ2; phantom `n` lift Phase SZ8/P3.

defopaque

SizedBuf

(SizedBuf [n] :int))
defn

sized-buf-new

(sized-buf-new [n])

allocate a heap (SizedBuf n) of n elements (uninitialized).

knumber of elements to allocate

A fresh (SizedBuf n) where `n` is polymorphic; pin it via ascription, e.g. `(:: (sized-buf-new 4) (SizedBuf (Static 4)))`.

(let [b (sized-buf-new 4)] ...)

Since: Phase SZ2; (SizedBuf n) lift Phase SZ8/P3

defn

sized-buf-new-zeroed

(sized-buf-new-zeroed [n])

allocate a heap (SizedBuf n), all elements zero.

knumber of elements to allocate

A fresh (SizedBuf n) initialised to all zeros.

(let [b (sized-buf-new-zeroed 4)] ...)

Since: Phase SZ2; (SizedBuf n) lift Phase SZ8/P3

defn

sized-buf-free

(sized-buf-free [n])

free a heap-allocated (SizedBuf n) and its data.

b(SizedBuf n) from sized-buf-new or sized-buf-new-zeroed

nil

(sized-buf-free b)

Since: Phase SZ2; (SizedBuf n) lift Phase SZ8/P3

defn

sized-buf-len

(sized-buf-len [n])

return the element count of a (SizedBuf n).

b(SizedBuf n)

Runtime element count as :int. The static `n` index pins the length at compile time when the call site supplies a literal Size.

(sized-buf-len (sized-buf-new 8))  ; => 8

Since: Phase SZ2; (SizedBuf n) lift Phase SZ8/P3

defn

sized-buf-get

(sized-buf-get [n])

bounds-checked element read; aborts on out-of-range index.

b(SizedBuf n)
izero-based index (0 <= i < sized-buf-len b)

The int64 value at position i.

(sized-buf-get b 0)  ; => first element

Since: Phase SZ2; (SizedBuf n) lift Phase SZ8/P3

defn

sized-buf-set!

(sized-buf-set! [n])

bounds-checked element write; aborts on out-of-range index.

b(SizedBuf n)
izero-based index
vvalue to store

The same buffer (SizedBuf n) (for chaining).

(sized-buf-set! b 0 42)

Since: Phase SZ2; (SizedBuf n) lift Phase SZ8/P3

defn

sized-buf-fill!

(sized-buf-fill! [n])

set every element to v; returns the same buffer.

b(SizedBuf n)
vvalue to store in every slot

The same buffer (SizedBuf n).

(sized-buf-fill! b 0)  ; zero-fill

Since: Phase SZ2; (SizedBuf n) lift Phase SZ8/P3

defn

sized-buf-copy!

(sized-buf-copy! [n])

copy all elements from src into dst via memcpy.

dstdestination (SizedBuf n)
srcsource (SizedBuf n) (same n)

The destination (SizedBuf n).

(sized-buf-copy! dst src)

Since: Phase SZ2; (SizedBuf n) lift Phase SZ8/P3

defn

sized-buf-sum

(sized-buf-sum [n])

sum all elements of a (SizedBuf n).

b(SizedBuf n)

Integer sum of all elements; 0 for an empty buffer.

(sized-buf-sum b)  ; => sum of elements

Since: Phase SZ2; (SizedBuf n) lift Phase SZ8/P3

defn

sized-buf-min

(sized-buf-min [n])

minimum element of a non-empty (SizedBuf n); aborts if empty.

b(SizedBuf n) (must have at least one element)

Minimum int64 element value.

(sized-buf-min b)  ; => smallest element

Since: Phase SZ2; (SizedBuf n) lift Phase SZ8/P3

defn

sized-buf-max

(sized-buf-max [n])

maximum element of a non-empty (SizedBuf n); aborts if empty.

b(SizedBuf n) (must have at least one element)

Maximum int64 element value.

(sized-buf-max b)  ; => largest element

Since: Phase SZ2; (SizedBuf n) lift Phase SZ8/P3

defn

sized-buf-size

(sized-buf-size [n])

return the runtime length of a (SizedBuf n) as a Size expression.

b(SizedBuf n)

A (Static k) where k is the runtime buffer length.

(size-eval (sized-buf-size b))  ; => length of b

Since: Phase SZ2; (SizedBuf n) lift Phase SZ8/P3

defn

sized-buf-with-stack

(sized-buf-with-stack [n f])

scoped computation over a stack-allocated buffer.

nnumber of elements (should be a static/small constant)
fa non-capturing function (int -> int) that receives the raw
buffer handle

The integer value returned by f.

(defn sum-init-buf [b] :int
    (sized-buf-set! (:: b :SizedBuf) 0 10)
    (sized-buf-sum  (:: b :SizedBuf)))
  (sized-buf-with-stack 3 sum-init-buf)

Since: Phase SZ2

defn

sized-buf-compute

(sized-buf-compute [n])

compute a result from a buffer, choosing stack or heap.

nnumber of elements

Sum of 0 + 1 + ... + (n-1).

(sized-buf-compute 5)  ; => 10  (0+1+2+3+4)

Since: Phase SZ2

defn

sized-buf-from-sized-vec

(sized-buf-from-sized-vec [n])

convert a SizedVec (linked list) to a (SizedBuf n) (flat array).

va SizedVec value (the int64-carried GADT root handle)

A heap-allocated (SizedBuf n) with the same elements in the same order. Pin `n` via ascription on the result when a static length is known statically.

(let [b (sized-buf-from-sized-vec v)]
    (println (sized-buf-sum b)))

Since: Phase SZ2; (SizedBuf n) lift Phase SZ8/P3

Internal definitions
__sized-buf-new-raw
__sized-buf-new-zeroed-raw
__sized-buf-free-raw
__sized-buf-len-raw
__sized-buf-get-raw
__sized-buf-set!-raw
__sized-buf-fill!-raw
__sized-buf-copy!-raw
__sized-buf-sum-raw
__sized-buf-min-raw
__sized-buf-max-raw
__sized-buf-from-sized-vec-raw
__sized-buf-stack-threshold