smallarray-0.2.1: low-level unboxed arrays, with minimal features.

Portabilityportable
Stabilityexperimental
Maintaineraslatter@gmail.com

Data.SmallArray

Contents

Description

Packed, unboxed, heap-resident arrays. Suitable for performance critical use, both in terms of large data quantities and high speed.

This module is intended to be imported qualified, to avoid name clashes with Prelude functions, e.g.

 import qualified Data.SmallArray as A

The names in this module resemble those in the Data.Array family of modules, but are shorter due to the assumption of qualifid naming.

Synopsis

Array types

data Array a Source

A simple array. Indexing starts from zero.

Instances

(Eq a, Elt a) => Eq (Array a) 
(Ord a, Elt a) => Ord (Array a) 
(Show e, Elt e) => Show (Array e) 
NFData (Array a) 
Hashable (Array a) 
Elt a => IArray (Array a) 

data MArray s a Source

A simple mutable array. Indexing starts from zero.

Instances

NFData (MArray s a) 
Elt a => IArray (MArray s a) 

class IArray a whereSource

Methods

length :: a -> IntSource

Return the length of an array.

Instances

Elt a => IArray (Array a) 
Elt a => IArray (MArray s a) 

class Elt e whereSource

Methods

index :: Array e -> Int -> eSource

Retrieve an element in an array at the specified location. Array indices start at zero.

read :: MArray s e -> Int -> ST s eSource

Retrieve an element from a mutable array at the specified location. Array indices start at zero.

write :: MArray s e -> Int -> e -> ST s ()Source

Write an element to a mutable array at the specified location. Array indices start at zero.

Creation

empty :: Elt e => Array eSource

The empty array

new :: Elt e => Int -> e -> ST s (MArray s e)Source

Create a new array with the specified default value.

run :: (forall s. ST s (MArray s e)) -> Array eSource

Execute an action creating a mutable array, and return the resulting equivalent pure array. No copy is performed.

run' :: (forall s. ST s (MArray s e, a)) -> (Array e, a)Source

fromList :: Elt e => [e] -> Array eSource

Create an array from a list.

copySource

Arguments

:: Elt e 
=> MArray s e

source array

-> MArray s e

destination array

-> ST s () 

Copy an array in its entirety. The destination array must be at least as big as the source.

Unpacking

toList :: Elt e => Array e -> [e]Source

Output the array to a list.