compact-word-vectors-0.2.0.2: Small vectors of small integers stored very compactly.
Safe HaskellNone
LanguageHaskell2010

Data.Vector.Compact.IntVec

Description

Signed integer version of dynamic word vectors.

See Data.Vector.Compact.WordVec for more details.

Note: for unsigned integers, you really should use WordVec instead, because that is significantly faster, and has much more specialized functions implemented.

This module should be imported qualified (to avoid name clashes with Prelude).

Synopsis

The dynamic Word vector type

newtype IntVec Source #

A dynamic int vector is a (small) vector of small signed integers stored compactly

Constructors

IntVec WordVec 

Instances

Instances details
Eq IntVec Source # 
Instance details

Defined in Data.Vector.Compact.IntVec

Methods

(==) :: IntVec -> IntVec -> Bool #

(/=) :: IntVec -> IntVec -> Bool #

Ord IntVec Source # 
Instance details

Defined in Data.Vector.Compact.IntVec

Show IntVec Source # 
Instance details

Defined in Data.Vector.Compact.IntVec

data Shape Source #

The "shape" of a dynamic word vector

Constructors

Shape 

Fields

Instances

Instances details
Eq Shape Source # 
Instance details

Defined in Data.Vector.Compact.WordVec

Methods

(==) :: Shape -> Shape -> Bool #

(/=) :: Shape -> Shape -> Bool #

Show Shape Source # 
Instance details

Defined in Data.Vector.Compact.WordVec

Methods

showsPrec :: Int -> Shape -> ShowS #

show :: Shape -> String #

showList :: [Shape] -> ShowS #

vecLen :: IntVec -> Int Source #

The length of the vector

vecBits :: IntVec -> Int Source #

The number of bits per element used to encode the vector

Show instance

Empty vector, singleton

Conversion to/from lists

fromList :: [Int] -> IntVec Source #

Note: fromList xs = fromList' (lenMinMax xs)

fromList' :: (Int, (Int, Int)) -> [Int] -> IntVec Source #

usage: fromList' (len,(min,max)) xs where min and max are the minimum and maximum (or just a lower and upper bound) appearing in the list.

fromList'' :: Shape -> [Int] -> IntVec Source #

Don't use this unless you really know what you are doing!

lenMinMax :: [Int] -> (Int, (Int, Int)) Source #

Computes the length, minimum and maximum of a list, traversing it only once (instead of 3 times).

toRevList :: IntVec -> [Int] Source #

toRevList == reverse . toList

Indexing

unsafeIndex :: Int -> IntVec -> Int Source #

Indexing starts from 0. No bound checks are done.

Head, tail, etc

cons :: Int -> IntVec -> IntVec Source #

Prepends an element

snoc :: IntVec -> Int -> IntVec Source #

Appends an element

Generic operations

fold :: (a -> Int -> a) -> a -> IntVec -> a Source #

Left fold

boundedMap :: (Int, Int) -> (Int -> Int) -> IntVec -> IntVec Source #

If you have (nearly sharp) lower and upper bounds for the result of your of function on your vector, mapping can be more efficient

boundedZipWith :: (Int, Int) -> (Int -> Int -> Int) -> IntVec -> IntVec -> IntVec Source #

If you have (nearly sharp) lower and upper bounds for the result of your of function on your vector, zipping can be more efficient

listZipWith :: (Int -> Int -> a) -> IntVec -> IntVec -> [a] Source #

Number of bits needed

bitsNeededForMinMax :: (Int, Int) -> Int Source #

usage: bitsNeededForMinMax (min,max)

bitsNeededFor :: Int -> Int Source #

Note: this automatically rounds up to multiples of 4

roundBits :: Int -> Int Source #

We only allow multiples of 4.