class Pf::BlockList(T)

Overview

A simple persistent linked list of blocks, storing at most 8x Ts per block. The block that you append to is copied wholesale, which is usually cheap enough while giving you semi-bearable locality during iteration (e.g. if T is pointer- sized, you get 64-byte blocks which are in theory big friends with the CPU, but let me not make myself sound like I understand what I'm talking about here!)

Included Modules

Defined in:

permafrost/block_list.cr

Constructors

Class Method Summary

Instance Method Summary

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, V
to_pf_map
to_pf_map
, to_pf_set : Pf::Set(T) to_pf_set, to_pf_uset32 : Pf::USet32 to_pf_uset32

Constructor Detail

def self.new : BlockList(T) #

Constructs an empty block list.


[View source]

Class Method Detail

def self.[](*objects) #

Constructs a block list containing objects.


[View source]

Instance Method Detail

def ==(other : BlockList(T)) : Bool #

Returns true if this list is equal to other.


[View source]
def [](index : Int) : T #

See Indexable#[].


[View source]
def []?(index : Int) : T | Nil #

See Indexable#[]?.


[View source]
def append(object : T) : BlockList(T) #

Inserts object at the back of this list.


[View source]
def each(& : T -> ) : Nil #

Yields elements in this list in front-to-back order.

This method may allocate some buffer memory because it must reverse the list to yield elements in the correct order.

NOTE All Enumerable methods eventually end up calling this method, so you must evaluate the costs (if that matters to you!)


[View source]
def fetch(index : Int, &) #

See Indexable#fetch(index : Int, &).


[View source]
def hash(hasher) #
Description copied from class Reference

See Object#hash(hasher)


[View source]
def last : T #

Returns the last element in this list. Raises IndexError if this list is empty.


[View source]
def last? : T | Nil #

Returns the last element in this list, or nil if this list is empty.


[View source]
def pretty_print(pp) #

[View source]
def prior : BlockList(T) #

Returns the part of this list before the last element. If this list is empty, returns an empty list.


[View source]
def reverse_each(& : T -> ) : Nil #

Yields elements in this list in back-to-front order.

Note that this is the memory order of BlockList, so this method is a pure traversal (compared to e.g. #each, which does additional work to give you elements in expected order).


[View source]
def rincludes?(object needle) : Bool #

Like includes?, but faster for BlockList in particular since it iterates in memory-order (using #reverse_each) vs. Enumerable's includes? which uses #each.


[View source]
def size : Int32 #

Returns the number of elements in this list.


[View source]