tur/rcvec
stdlib/rcvec.tur
a flat vector of rc<A> the cycle collector can trace through.
Since: collections-cannot-hold-rc-values item 3
defstruct
RcVec
(defstruct RcVec :move [managed-by-c : int])
opaque marker type for the container.
Since: collections-cannot-hold-rc-values item 3
defn
rcvec-new
(rcvec-new :)
allocate a fresh, empty rc vector.
Returns
A new empty vector, owned by the caller.
Example
(let [v (rcvec-new)]
(println (rcvec-len v))) ; => 0
Since: collections-cannot-hold-rc-values item 3
defn
rcvec-len
(rcvec-len [^borrow v : rc<RcVec>] :)
the number of elements in the vector.
Parameters
| v | the vector (borrowed) |
Returns
The element count.
Example
(rcvec-len (rcvec-new)) ; => 0
Since: collections-cannot-hold-rc-values item 3
defn
rcvec-push!
(rcvec-push! [A])
append an element to the vector.
Parameters
| v | the vector (borrowed) | |
| item | the element to append (borrowed; the vector retains its own) |
Returns
Nothing.
Example
(rcvec-push! v a) (println (rc/strong-count a)) ; caller's 1 + the vector's 1 = 2
Since: collections-cannot-hold-rc-values item 3
defn
rcvec-get
(rcvec-get [A])
the element at index i, as the caller's own reference.
Parameters
| v | the vector (borrowed) | |
| i | zero-based index |
Returns
A new strong reference to the element, or a null handle out of range.
Example
(let [e (rcvec-get v 0)]
(println (rc/strong-count e))) ; slot's + caller's counts
Since: collections-cannot-hold-rc-values item 3