tur/slice
stdlib/slice.tur
typed Slice[A]: bounds-checked borrowed view into A elements.
Since: Phase TC1-C
defstruct
Slice
(defstruct Slice [A])
parameterized view into a contiguous array of A.
Since: Phase TC1
defn
slice-new
(slice-new [data :ptr<void> length :int])
create a Slice[A] view over an existing int64_t array.
Parameters
| data | pointer to the start of the contiguous int64_t array | |
| length | number of elements in the view |
Returns
A new Slice[A] view (does not copy the data).
Example
(slice-new arr 4) ; => slice of first 4 elements
Since: Phase TC1
defn
slice-len
(slice-len [s :int])
return the number of elements in a Slice[A].
Parameters
| s | Slice[A] handle |
Returns
Element count.
Example
(slice-len s) ; => 4
Since: Phase TC1
defn
slice-get
(slice-get [s :int i :int])
bounds-checked element access.
Parameters
| s | Slice[A] handle | |
| i | zero-based index |
Returns
The element of type A at index i.
Example
(slice-get s 0) ; => first element
Since: Phase TC1
defn
slice-free
(slice-free [s :int])
free the Slice[A] header (does NOT free the underlying data).
Parameters
| s | Slice[A] handle |
Example
(slice-free s)
Since: Phase TC1
defn
slice-eq?
(slice-eq? [s1 :int s2 :int cmp-fn])
compare two Slice[A] element-wise using a comparator.
Parameters
| s1 | first Slice[A] | |
| s2 | second Slice[A] | |
| cmp-fn | comparator fn [a :int b :int] :bool |
Returns
true if same length and all element pairs satisfy cmp-fn.
Example
(slice-eq? sa sb (fn [a b] (= a b))) ; => true
Since: Phase TC1