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.


def self.[](*elements) #

Initializes a substrate with elements.


def self.for(elements : Array(T)) #

Initializes a substrate with elements as the underlying array.


Instance Method Detail

def ==(other) #

def at!(index) #

Unsafely fetches the element at index.


def at?(index) #

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


abstract def copy #

Returns a copy of this substrate.


def count #

Returns the amount of elements in the array.


abstract def delete?(at index) #

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


def each(*args, **options) #

Same as Array#each.


def each(*args, **options, &) #

Same as Array#each.


abstract def insert?(at index, element) #

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


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.


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.


abstract def sort_using!(cmp : T, T -> Int32) #

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


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.