unordered-containers-0.2.20.1: Efficient hashing-based container types

Safe Haskell | None
Language | Haskell2010

Data.HashMap.Internal.Array

Contents

- Creation
- Basic interface
- Folds

Description

# WARNING

This module is considered internal.

The Package Versioning Policy does not apply.

The contents of this module may change in any way whatsoever and without any warning between minor versions of this package.

Authors importing this module are expected to track development closely.

# Description

Zero based arrays.

Note that no bounds checking are performed.

Synopsis

- data Array a = Array {
  - unArray :: !(SmallArray# a)
  }
- data MArray s a = MArray {
  - unMArray :: !(SmallMutableArray# s a)
  }
- new :: Int -> a -> ST s (MArray s a)
- new_ :: Int -> ST s (MArray s a)
- singleton :: a -> Array a
- singletonM :: a -> ST s (Array a)
- snoc :: Array a -> a -> Array a
- pair :: a -> a -> Array a
- length :: Array a -> Int
- lengthM :: MArray s a -> Int
- read :: MArray s a -> Int -> ST s a
- write :: MArray s a -> Int -> a -> ST s ()
- index :: Array a -> Int -> a
- indexM :: Array a -> Int -> ST s a
- index# :: Array a -> Int -> (# a #)
- update :: Array e -> Int -> e -> Array e
- updateWith' :: Array e -> Int -> (e -> e) -> Array e
- unsafeUpdateM :: Array e -> Int -> e -> ST s ()
- insert :: Array e -> Int -> e -> Array e
- insertM :: Array e -> Int -> e -> ST s (Array e)
- delete :: Array e -> Int -> Array e
- sameArray1 :: (a -> b -> Bool) -> Array a -> Array b -> Bool
- unsafeFreeze :: MArray s a -> ST s (Array a)
- unsafeThaw :: Array a -> ST s (MArray s a)
- unsafeSameArray :: Array a -> Array b -> Bool
- run :: (forall s. ST s (MArray s e)) -> Array e
- copy :: Array e -> Int -> MArray s e -> Int -> Int -> ST s ()
- copyM :: MArray s e -> Int -> MArray s e -> Int -> Int -> ST s ()
- cloneM :: MArray s a -> Int -> Int -> ST s (MArray s a)
- foldl :: (b -> a -> b) -> b -> Array a -> b
- foldl' :: (b -> a -> b) -> b -> Array a -> b
- foldr :: (a -> b -> b) -> b -> Array a -> b
- foldr' :: (a -> b -> b) -> b -> Array a -> b
- foldMap :: Monoid m => (a -> m) -> Array a -> m
- all :: (a -> Bool) -> Array a -> Bool
- thaw :: Array e -> Int -> Int -> ST s (MArray s e)
- map :: (a -> b) -> Array a -> Array b
- map' :: (a -> b) -> Array a -> Array b
- traverse :: Applicative f => (a -> f b) -> Array a -> f (Array b)
- traverse' :: Applicative f => (a -> f b) -> Array a -> f (Array b)
- toList :: Array a -> [a]
- fromList :: Int -> [a] -> Array a
- fromList' :: Int -> [a] -> Array a
- shrink :: MArray s a -> Int -> ST s (MArray s a)

# Documentation

data Array a Source #

Constructors

Array |

Fields

- unArray :: !(SmallArray# a)

#### Instances

Instances details

NFData1 Array Source # | Since: 0.2.14.0
Instance details Defined in Data.HashMap.Internal.Array Methods liftRnf :: (a -> ()) -> Array a -> () Source #
Lift a => Lift (Array a :: Type) Source # | Since: 0.2.17.0
Instance details Defined in Data.HashMap.Internal.Array Methods lift :: Quote m => Array a -> m Exp Source # liftTyped :: forall (m :: Type -> Type). Quote m => Array a -> Code m (Array a) Source #
NFData a => NFData (Array a) Source # |
Instance details Defined in Data.HashMap.Internal.Array Methods rnf :: Array a -> () Source #
Show a => Show (Array a) Source # |
Instance details Defined in Data.HashMap.Internal.Array Methods showsPrec :: Int -> Array a -> ShowS Source # show :: Array a -> String Source # showList :: [Array a] -> ShowS Source #

data MArray s a Source #

Constructors

MArray |

Fields

- unMArray :: !(SmallMutableArray# s a)

# Creation

new :: Int -> a -> ST s (MArray s a) Source #

Create a new mutable array of specified size, in the specified state thread, with each element containing the specified initial value.

new_ :: Int -> ST s (MArray s a) Source #

singleton :: a -> Array a Source #

singletonM :: a -> ST s (Array a) Source #

snoc :: Array a -> a -> Array a Source #

pair :: a -> a -> Array a Source #

# Basic interface

length :: Array a -> Int Source #

lengthM :: MArray s a -> Int Source #

read :: MArray s a -> Int -> ST s a Source #

write :: MArray s a -> Int -> a -> ST s () Source #

index :: Array a -> Int -> a Source #

indexM :: Array a -> Int -> ST s a Source #

index# :: Array a -> Int -> (# a #) Source #

update :: Array e -> Int -> e -> Array e Source #

\(O(n)\) Update the element at the given position in this array.

updateWith' :: Array e -> Int -> (e -> e) -> Array e Source #

\(O(n)\) Update the element at the given position in this array, by applying a function to it. Evaluates the element to WHNF before inserting it into the array.

unsafeUpdateM :: Array e -> Int -> e -> ST s () Source #

\(O(1)\) Update the element at the given position in this array, without copying.

insert :: Array e -> Int -> e -> Array e Source #

\(O(n)\) Insert an element at the given position in this array, increasing its size by one.

insertM :: Array e -> Int -> e -> ST s (Array e) Source #

\(O(n)\) Insert an element at the given position in this array, increasing its size by one.

delete :: Array e -> Int -> Array e Source #

\(O(n)\) Delete an element at the given position in this array, decreasing its size by one.

sameArray1 :: (a -> b -> Bool) -> Array a -> Array b -> Bool Source #

unsafeFreeze :: MArray s a -> ST s (Array a) Source #

unsafeThaw :: Array a -> ST s (MArray s a) Source #

unsafeSameArray :: Array a -> Array b -> Bool Source #

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

copy :: Array e -> Int -> MArray s e -> Int -> Int -> ST s () Source #

Unsafely copy the elements of an array. Array bounds are not checked.

copyM :: MArray s e -> Int -> MArray s e -> Int -> Int -> ST s () Source #

Unsafely copy the elements of an array. Array bounds are not checked.

cloneM :: MArray s a -> Int -> Int -> ST s (MArray s a) Source #

# Folds

foldl :: (b -> a -> b) -> b -> Array a -> b Source #

foldl' :: (b -> a -> b) -> b -> Array a -> b Source #

foldr :: (a -> b -> b) -> b -> Array a -> b Source #

foldr' :: (a -> b -> b) -> b -> Array a -> b Source #

foldMap :: Monoid m => (a -> m) -> Array a -> m Source #

all :: (a -> Bool) -> Array a -> Bool Source #

Verifies that a predicate holds for all elements of an array.

thaw :: Array e -> Int -> Int -> ST s (MArray s e) Source #

map :: (a -> b) -> Array a -> Array b Source #

map' :: (a -> b) -> Array a -> Array b Source #

Strict version of `map`.

traverse :: Applicative f => (a -> f b) -> Array a -> f (Array b) Source #

traverse' :: Applicative f => (a -> f b) -> Array a -> f (Array b) Source #

toList :: Array a -> [a] Source #

fromList :: Int -> [a] -> Array a Source #

fromList' :: Int -> [a] -> Array a Source #

shrink :: MArray s a -> Int -> ST s (MArray s a) Source #

When `shrinkSmallMutableArray#` is available, the returned array is the same as the array given, as it is shrunk in place. Otherwise a copy is made.