- Notifications
You must be signed in to change notification settings - Fork142
An efficient implementation of Int-indexed arrays (both mutable and immutable), with a powerful loop optimisation framework .
License
haskell/vector
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
Vector is a collection of efficientInt-indexed array implementations:boxed, unboxed, storable, and primitive vectors(all can be mutable or immutable). The package features a generic API,polymorphic in vector type, and implementsstream fusion,a powerful optimisation framework that can help eliminate intermediate data structures.
A beginner-friendly tutorial for vectors can be found onMMHaskell.
If you have already started your adventure with vectors,the tutorial onHaskell Wikicovers more ground.
Arrays are data structures that can store a multitude of elementsand allow immediate access to every one of them. However, they areoften seen as legacy constructs that are rarely used in modern Haskell.Even though Haskell has a built-inData.Array module,arrays might be a bit overwhelming to use due to their complex API.Conversely, vectors incorporate the array’sO(1) access to elementswith a much friendlier API of lists. Since they allow for frameworkoptimisation via loop fusion, vectors emphasise efficiency and keepa rich interface. Unless you’re confident with arrays, it’swell-advised to use vectors when looking for a similar functionality.
Lazy boxed vectors (Data.Vector) store each of their elements as apointer to a heap-allocated value. Because of indirection, lazy boxed vectorsare slower in comparison to unboxed vectors.
Strict boxed vectors (Data.Vector.Strict) contain elements that arestrictly evaluated.
Unboxed vectors (Data.Vector.Unboxed) determine an array's representationfrom its elements' type. For example, vector of primitive types (e.g.Int) will bebacked by primitive array while vector of product types by structure of arrays.They are quite efficient due to the unboxed representation they use.
Storable vectors (Data.Vector.Storable) are backed by pinned memory, i.e.,they cannot be moved by the garbage collector. Their primary use case is C FFI.
Primitive vectors (Data.Vector.Primitive) are backed by simple byte array andcan store only data types that are represented in memory as a sequence of bytes withouta pointer, i.e., they belong to thePrim type class, e.g.,Int,Double, etc.It's advised to use unboxed vectors if you're looking for the performance of primitive vectors,but more versality.
An optimisation framework used by vectors, stream fusion is a technique that mergesseveral functions into one and prevents creation of intermediate data structures. For example,the expressionsum . filter g . map f won't allocate temporary vectors ifcompiled with optimisations.
About
An efficient implementation of Int-indexed arrays (both mutable and immutable), with a powerful loop optimisation framework .
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.