SmallVector<T> structv0.1.0
pub struct SmallVector<T> {
// private fields
}
Move-only: it owns its elements.
Type parameters
| Name | Description |
|---|---|
T | the element type |
Constructors
SmallVector
pub func SmallVector(allocator: Allocator) -> SmallVector<T>
An empty vector, holding its first elements inline.
| Name | Type | Description |
|---|---|---|
allocator | Allocator | where the storage comes from once they outgrow it |
Returns: the vector
Methods
InlineCapacity
pub func InlineCapacity(self: &SmallVector<T>) -> uint
How many elements fit inline: 64 bytes' worth, or none for an element larger than that or aligned to more than eight.
Returns: the inline capacity
IsInline
pub func IsInline(self: &SmallVector<T>) -> bool
Whether the elements are still inline, with nothing allocated.
Returns: whether it is inline
Length
pub func Length(self: &SmallVector<T>) -> uint
How many elements it holds.
Returns: the count
IsEmpty
pub func IsEmpty(self: &SmallVector<T>) -> bool
Whether it holds nothing.
Returns: whether it is empty
Capacity
pub func Capacity(self: &SmallVector<T>) -> uint
How many elements fit before the next allocation.
Returns: the capacity
Push
pub func Push(
self: &var SmallVector<T>,
value: T
) -> ! CollectionError
Appends value, moving it in, and allocating only once the inline room is full.
| Name | Type | Description |
|---|---|---|
value | T | the element |
Returns: nothing, or why there was no room; the vector is unchanged on failure
TryPop
pub func TryPop(
self: &var SmallVector<T>,
value: *var T
) -> bool
Takes the last element out.
| Name | Type | Description |
|---|---|---|
value | *var T | receives the element |
Returns: whether there was one
Get
pub func Get(self: &SmallVector<T>, index: uint) -> T?
A copy of the element at index.
| Name | Type | Description |
|---|---|---|
index | uint | which one |
Returns: the element, or none past the end
AsSlice
pub func AsSlice(self: &SmallVector<T>) -> T[..]
The elements, valid until the vector next changes or moves.
Returns: a view of them
AsMutableSlice
pub func AsMutableSlice(self: &var SmallVector<T>) -> var T[..]
The elements, writable, valid until the vector next changes or moves.
Returns: a view of them
Truncate
pub func Truncate(self: &var SmallVector<T>, length: uint)
Destroys the elements past length, keeping the storage.
| Name | Type | Description |
|---|---|---|
length | uint | how many to keep |
Clear
pub func Clear(self: &var SmallVector<T>)
Destroys every element, keeping the storage.
Destructor
func ~SmallVector(self: &var SmallVector<T>)