Control.Monad.Memo.Vector (original) (raw)
Contents
Description
VectorCache - mutable-vector-based (IO
and ST
hosted) [MonadCache](Control-Monad-Memo-Class.html#t:MonadCache "Control.Monad.Memo.Class")
The fastest memoization cache, however it is even more limiting than Control.Monad.Memo.Array due to nature of Data.Vector.Mutable. Still if you can use this cache please do since it will give you dramatic calculation speed up in comparison to pure [Map](/package/containers-0.6.2.1/docs/Data-Map.html#v:Map "Data.Map")
-based cache, especially when unboxed [UVectorCache](Control-Monad-Memo-Vector.html#t:UVectorCache "Control.Monad.Memo.Vector")
is used.
Limitations: Since [MVector](/package/vector-0.12.3.1/docs/Data-Vector-Generic-Mutable-Base.html#t:MVector "Data.Vector.Generic.Mutable.Base")
is used as [MonadCache](Control-Monad-Memo-Class.html#t:MonadCache "Control.Monad.Memo.Class")
the key must be [Int](/package/base-4.14.1.0/docs/Data-Int.html#t:Int "Data.Int")
and the size of the cache's vector must be known beforehand with vector being allocated before the first call. In addition unboxed [UVectorCache](Control-Monad-Memo-Vector.html#t:UVectorCache "Control.Monad.Memo.Vector")
can only store [Unbox](/package/vector-0.12.3.1/docs/Data-Vector-Unboxed.html#v:Unbox "Data.Vector.Unboxed")
values (but it does it very efficiently).
Synopsis
- type Vector = MVector
- type VectorCache s e = Cache Vector s e
- class MaybeLike e v => VectorMemo v e | v -> e
- evalVectorMemo :: (PrimMonad m, VectorMemo v e) => VectorCache (PrimState m) e m a -> Int -> m a
- runVectorMemo :: (PrimMonad m, VectorMemo v e) => VectorCache (PrimState m) e m a -> Int -> m (a, Vector (PrimState m) e)
- type UVector = MVector
- type UVectorCache s e = Cache UVector s e
- class MaybeLike e v => UVectorMemo v e | v -> e
- evalUVectorMemo :: (PrimMonad m, MVector UVector e, UVectorMemo v e) => UVectorCache (PrimState m) e m a -> Int -> m a
- runUVectorMemo :: (PrimMonad m, MVector UVector e, UVectorMemo v e) => UVectorCache (PrimState m) e m a -> Int -> m (a, UVector (PrimState m) e)
- newtype Container vec = Container {
- toVector :: vec
}
- toVector :: vec
- type Cache vec s e = ReaderCache (Container (vec s e))
- genericEvalVectorMemo :: (MaybeLike e v, PrimMonad m, MVector c e) => Cache c (PrimState m) e m a -> Int -> m a
- genericRunVectorMemo :: (MaybeLike e v, PrimMonad m, MVector c e) => Cache c (PrimState m) e m a -> Int -> m (a, c (PrimState m) e)
Evaluate computation using mutable boxed vector
Vector length must covers all possible keys used in computation otherwise index out of bound error is generated by vector code
Evaluate computation using mutable boxed vector. It also returns the final content of the vector cache
Vector length must covers all possible keys used in computation otherwise index out of bound error is generated by vector code
UVectorCache for unboxed types
Evaluate computation using mutable unboxed vector
Vector length must covers all possible keys used in computation otherwise index out of bound error is generated by vector code
Evaluate computation using mutable unboxed vector. It also returns the final content of the vector cache
Vector length must covers all possible keys used in computation otherwise index out of bound error is generated by vector code