module Novika::Substrate(T)

Overview

Substrate is a fast, low-level copy-on-write wrapper for an array.

Defined in:

novika/substrate.cr

Class Method Summary

Instance Method Summary

Class Method Detail

def self.[] #

Initializes an empty substrate.


[View source]
def self.[](*elements) #

Initializes a substrate with elements.


[View source]
def self.for(elements : Array(T)) #

Initializes a substrate with elements as the underlying array.


[View source]

Instance Method Detail

def ==(other) #

[View source]
def at!(index) #

Unsafely fetches the element at index.


[View source]
def at?(index) #

Returns the element at index. Returns nil if index is out of bounds, i.e., not in 0 <= index < count.


[View source]
abstract def copy #

Returns a copy of this substrate.


[View source]
def count #

Returns the amount of elements in the array.


[View source]
abstract def delete?(at index) #

Deletes the element at index. Returns nil if index is out of bounds (see #at?).


[View source]
def each(*args, **options) #

Same as Array#each.


[View source]
def each(*args, **options, &) #

Same as Array#each.


[View source]
abstract def insert?(at index, element) #

Adds element before index. Returns nil if index is out of bounds (see #at?).


[View source]
abstract def map!(& : T -> T | Nil) #

Replaces elements of this substrate with the result of the block. If the result is nil, leaves the original element.


[View source]
def slice_at!(index) #

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.


[View source]
abstract def sort_using!(cmp : T, T -> Int32) #

Sorts elements of this substrate inplace, using a cmp comparator proc for comparing two elements.


[View source]
abstract def 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.

A lot of undefined behavior unless you are sure all numbers are good.


[View source]