module Novika::Substrate(T)
Overview
Substrate is a fast, low-level copy-on-write wrapper for an array.
Defined in:
novika/substrate.crClass Method Summary
-
.[]
Initializes an empty substrate.
-
.[](*elements)
Initializes a substrate with elements.
-
.for(elements : Array(T))
Initializes a substrate with elements as the underlying array.
Instance Method Summary
- #==(other)
-
#at!(index)
Unsafely fetches the element at index.
-
#at?(index)
Returns the element at index.
-
#copy
Returns a copy of this substrate.
-
#count
Returns the amount of elements in the array.
-
#delete?(at index)
Deletes the element at index.
-
#each(*args, **options)
Same as
Array#each
. -
#each(*args, **options, &)
Same as
Array#each
. -
#insert?(at index, element)
Adds element before index.
-
#map!(& : T -> T | Nil)
Replaces elements of this substrate with the result of the block.
-
#slice_at!(index)
Splits this substrate in two at index.
-
#sort_using!(cmp : T, T -> Int32)
Sorts elements of this substrate inplace, using a cmp comparator proc for comparing two elements.
-
#unsafe_paste(other : Substrate(T), index, other_start, other_insert_count)
Pastes count elements of other starting at begin, to dest index in self, without doing any checks whatsoever.
Class Method Detail
Initializes a substrate with elements as the underlying array.
Instance Method Detail
Returns the element at index. Returns nil if index is
out of bounds, i.e., not in 0 <= index < count
.
Deletes the element at index. Returns nil if index is
out of bounds (see #at?
).
Adds element before index. Returns nil if index is
out of bounds (see #at?
).
Replaces elements of this substrate with the result of the block. If the result is nil, leaves the original element.
Splits this substrate in two at index. Returns the two resulting substrates.
This method is unsafe: it does not check whether index is in bounds.
Sorts elements of this substrate inplace, using a cmp comparator proc for comparing two elements.
Pastes count elements of other starting at begin, to dest index in self, without doing any checks whatsoever.
A lot of undefined behavior unless you are sure all numbers are good.