No matching definitions.

tur/sized-buf

stdlib/sized-buf.tur

SizedBuf: flat contiguous memory layout for sized types.

Since: Phase SZ2

defn

sized-buf-new

(sized-buf-new [n])

allocate a heap SizedBuf of n elements (uninitialized).

nnumber of elements to allocate

Opaque pointer to the new SizedBuf.

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

Since: Phase SZ2

defn

sized-buf-new-zeroed

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

allocate a heap SizedBuf of n elements, all zero.

nnumber of elements to allocate

Opaque pointer to the new SizedBuf with all elements set to 0.

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

Since: Phase SZ2

defn

sized-buf-free

(sized-buf-free [b])

free a heap-allocated SizedBuf and its data.

bSizedBuf pointer from sized-buf-new or sized-buf-new-zeroed

nil

(sized-buf-free b)

Since: Phase SZ2

defn

sized-buf-len

(sized-buf-len [b])

return the number of elements in a SizedBuf.

bSizedBuf pointer

Element count as :int.

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

Since: Phase SZ2

defn

sized-buf-get

(sized-buf-get [b i])

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

bSizedBuf pointer
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

defn

sized-buf-set!

(sized-buf-set! [b i v])

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

bSizedBuf pointer
izero-based index
vvalue to store

The same buffer pointer b (for chaining).

(sized-buf-set! b 0 42)

Since: Phase SZ2

defn

sized-buf-fill!

(sized-buf-fill! [b v])

set every element to v; returns the same buffer.

bSizedBuf pointer
vvalue to store in every slot

The same buffer pointer b.

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

Since: Phase SZ2

defn

sized-buf-copy!

(sized-buf-copy! [dst src])

copy all elements from src into dst via memcpy.

dstdestination SizedBuf
srcsource SizedBuf (same length as dst)

The destination buffer pointer dst.

(sized-buf-copy! dst src)

Since: Phase SZ2

defn

sized-buf-sum

(sized-buf-sum [b])

sum all elements of a SizedBuf.

bSizedBuf pointer

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

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

Since: Phase SZ2

defn

sized-buf-min

(sized-buf-min [b])

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

bSizedBuf pointer (must have at least one element)

Minimum int64 element value.

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

Since: Phase SZ2

defn

sized-buf-max

(sized-buf-max [b])

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

bSizedBuf pointer (must have at least one element)

Maximum int64 element value.

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

Since: Phase SZ2

defn

sized-buf-size

(sized-buf-size [b])

return the length of a SizedBuf as a Size expression.

bSizedBuf pointer

A (Static n) where n is the buffer length.

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

Since: Phase SZ2

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 buffer

The integer value returned by f.

(defn sum-init-buf [b] :int
    (sized-buf-set! b 0 10)
    (sized-buf-set! b 1 20)
    (sized-buf-set! b 2 30)
    (sized-buf-sum b))
  (sized-buf-with-stack 3 sum-init-buf)  ; => 60

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 [v])

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

va (SizedVec Size int) value

A heap-allocated SizedBuf with the same elements in the same order.

(let [b (unsafe (sized-buf-from-sized-vec (sized-vec-of-3 10 20 30)))]
    (println (sized-buf-sum b)))  ; => 60

Since: Phase SZ2

Internal definitions
__sized-buf-stack-threshold