struct
Pf::Kit::HybridArray(T, N)
- Pf::Kit::HybridArray(T, N)
- Struct
- Value
- Object
Overview
A hybrid array stores N x Ts on the stack and spills over to heap.
NOTE This is a struct. You can assign it to a local variable or an instance
variable and use it safely. When passing it to functions, however, be careful.
First of all, naked HybridArrays are expected to be "huge structs" -- hundreds
to thousands of bytes. Besides, if you pass a naked HybridArray, the callee
will receive a copy -- not nice, most of the times. So prefer to use pointerof(var)
or pointerof(@ivar), but please be aware of their caveats (and unsafety!)
Inspiration: One of Walter Bright talks, at https://www.youtube.com/watch?v=_PB6Hdi4R7M&t=2606s
Included Modules
- Indexable::Mutable(T)
Defined in:
permafrost/kit/hybrid_array.crConstructors
Instance Method Summary
-
#<<(value : T) : Nil
Inserts value at the back of this array.
-
#clear : Nil
Removes all values from this array.
- #inspect(io)
-
#pop : T
Removes and returns the last value of this array.
-
#pop? : T | Nil
Removes and returns the last value of this array.
- #pretty_print(pp) : Nil
-
#push(value : T) : Nil
Inserts value at the back of this array.
-
#size : Int32
Returns the number of elements in this container.
-
#to_s(io : IO) : Nil
Same as
#inspect(io). -
#unsafe_fetch(index : Int) : T
Returns the element at the given index, without doing any bounds check.
-
#unsafe_put(index : Int, value : T) : Nil
Sets the element at the given index to value, without doing any bounds check.
-
#usize : UInt32
Returns the underlying
UInt32size of this array.
Instance methods inherited from module Enumerable(T)
to_pf_bidi
to_pf_bidi,
to_pf_map(& : T -> Tuple(K, V)) : Pf::Map(K, V) forall K, Vto_pf_map to_pf_map, to_pf_set : Pf::Set(T) to_pf_set, to_pf_uset32 : Pf::USet32 to_pf_uset32
Constructor Detail
Instance Method Detail
Inserts value at the back of this array.
NOTE Normally, in Crystal, << (and #push) return self; but for
HybridArray this would be malicious, since it's stored largely
on the stack.
Removes and returns the last value of this array. Raises IndexError if
this array is empty.
Removes and returns the last value of this array. Returns nil if
this array is empty.
Returns the number of elements in this container.
Returns the element at the given index, without doing any bounds check.
Indexable makes sure to invoke this method with index in 0...size,
so converting negative indices to positive ones is not needed here.
Clients never invoke this method directly. Instead, they access
elements with #[](index) and #[]?(index).
This method should only be directly invoked if you are absolutely sure the index is in bounds, to avoid a bounds check for a small boost of performance.
Sets the element at the given index to value, without doing any bounds check.
Indexable::Mutable makes sure to invoke this method with index in
0...size, so converting negative indices to positive ones is not needed
here.
Clients never invoke this method directly. Instead, they modify elements
with #[]=(index, value).
This method should only be directly invoked if you are absolutely sure the index is in bounds, to avoid a bounds check for a small boost of performance.