Copyright | (c) Eduard Sergeev 2013 |
---|---|
License | BSD-style (see the file LICENSE) |
Maintainer | eduard.sergeev@gmail.com |
Stability | experimental |
Portability | non-portable (multi-param classes, flexible instances) |
Safe Haskell | None |
Language | Haskell2010 |
VectorCache - mutable-vector-based MonadCache
with unsafe operations.
This is a version of Control.Monad.Memo.Mutable.Vector but implemented using unsafe* vector operations. Faster than default implementation but you must be sure that your code doesn't try to read/write outside vector boundaries.
Synopsis
- type VectorCache s e = Cache Vector s e
- class MaybeLike e v => VectorMemo v e | v -> e
- unsafeEvalVectorMemo :: (PrimMonad m, VectorMemo v e) => VectorCache (PrimState m) e m a -> Int -> m a
- unsafeRunVectorMemo :: (PrimMonad m, VectorMemo v e) => VectorCache (PrimState m) e m a -> Int -> m (a, Vector (PrimState m) e)
- type UVectorCache s e = Cache UVector s e
- class MaybeLike e v => UVectorMemo v e | v -> e
- unsafeEvalUVectorMemo :: (PrimMonad m, UVectorMemo v e, MVector UVector e) => UVectorCache (PrimState m) e m a -> Int -> m a
- unsafeRunUVectorMemo :: (PrimMonad m, UVectorMemo v e, MVector UVector e) => UVectorCache (PrimState m) e m a -> Int -> m (a, UVector (PrimState m) e)
- newtype Container vec = Container {
- toVector :: vec
- type Cache vec k e = ReaderCache (Container (vec k e))
- genericUnsafeEvalVectorMemo :: (MaybeLike e v, PrimMonad m, MVector c e) => Cache c (PrimState m) e m a -> Int -> m a
- genericUnsafeRunVectorMemo :: (MaybeLike e v, PrimMonad m, MVector c e) => Cache c (PrimState m) e m a -> Int -> m (a, c (PrimState m) e)
VectorCache for boxed types
type VectorCache s e = Cache Vector s e Source #
MonadCache
based on boxed vector
class MaybeLike e v => VectorMemo v e | v -> e Source #
This is just to be able to infer the type of the VectorCache
element.
Instances
MaybeLike (Maybe v) v => VectorMemo v (Maybe v) Source # | |
Defined in Control.Monad.Memo.Vector.Instances |
:: (PrimMonad m, VectorMemo v e) | |
=> VectorCache (PrimState m) e m a | memoized computation |
-> Int | vector length |
-> m a | result |
Evaluate computation using mutable boxed vector and unsafe operations
Vector length must covers all possible keys used in computation otherwise the behaviour is undefined (i.e. segfault)
:: (PrimMonad m, VectorMemo v e) | |
=> VectorCache (PrimState m) e m a | memoized computation |
-> Int | vector length |
-> m (a, Vector (PrimState m) e) | result and final vector cache |
Evaluate computation using mutable boxed vector and unsafe operations. It also returns the final content of the vector cache
Vector length must covers all possible keys used in computation otherwise the behaviour is undefined (i.e. segfault)
UVectorCache for unboxed types
type UVectorCache s e = Cache UVector s e Source #
MonadCache
based on unboxed vector
class MaybeLike e v => UVectorMemo v e | v -> e Source #
This is just to be able to infer the type of the UVectorCache
element
Instances
MaybeLike v v => UVectorMemo v v Source # | |
Defined in Control.Monad.Memo.Vector.Instances |
unsafeEvalUVectorMemo Source #
:: (PrimMonad m, UVectorMemo v e, MVector UVector e) | |
=> UVectorCache (PrimState m) e m a | memoized computation |
-> Int | vector length |
-> m a | result |
Evaluate computation using mutable unboxed vector and unsafe operations
Vector length must covers all possible keys used in computation otherwise the behaviour is undefined (i.e. segfault)
:: (PrimMonad m, UVectorMemo v e, MVector UVector e) | |
=> UVectorCache (PrimState m) e m a | memoized computation |
-> Int | vector length |
-> m (a, UVector (PrimState m) e) | result and final vector cache |
Evaluate computation using mutable boxed vector and unsafe operations. It also returns the final content of the vector cache
Vector length must covers all possible keys used in computation otherwise the behaviour is undefined (i.e. segfault)
Generic functions for VectorCache
type Cache vec k e = ReaderCache (Container (vec k e)) Source #
Generic Vector-based memo cache