| Copyright | (c) Matt Hunzinger 2025 |
|---|---|
| License | BSD-style (see the LICENSE file in the distribution) |
| Maintainer | matt@hunzinger.me |
| Stability | provisional |
| Portability | non-portable (GHC extensions) |
| Safe Haskell | None |
| Language | Haskell2010 |
Data.SparseVector.Strict
Description
Synopsis
- newtype SparseVector a = SparseVector {
- unSparseVector :: Vector (Bool, a)
- empty :: SparseVector a
- emptyWith :: a -> SparseVector a
- insert :: Int -> a -> SparseVector a -> SparseVector a
- lookup :: Int -> SparseVector a -> Maybe a
- delete :: Int -> SparseVector a -> SparseVector a
- mapWithKey :: (Int -> a -> b) -> SparseVector a -> SparseVector b
- mapAccum :: (a -> b -> (a, c)) -> a -> SparseVector b -> (a, SparseVector c)
- intersection :: SparseVector a -> SparseVector b -> SparseVector a
- intersectionWith :: (a -> b -> c) -> SparseVector a -> SparseVector b -> SparseVector c
- intersectionWithKey :: (Int -> a -> b -> c) -> SparseVector a -> SparseVector b -> SparseVector c
- intersectionVec :: SparseVector a -> SparseVector b -> Vector a
- intersectionVecWith :: (a -> b -> c) -> SparseVector a -> SparseVector b -> Vector c
- intersectionVecWithKey :: (Int -> a -> b -> c) -> SparseVector a -> SparseVector b -> Vector c
- fromList :: [(Int, a)] -> SparseVector a
- toList :: SparseVector a -> [Maybe a]
- toPairList :: SparseVector a -> [(Bool, a)]
- fromVector :: Vector a -> SparseVector a
- toVector :: SparseVector a -> Vector a
- freeze :: PrimMonad m => MSparseVector (PrimState m) a -> m (SparseVector a)
- unsafeFreeze :: PrimMonad m => MSparseVector (PrimState m) a -> m (SparseVector a)
- thaw :: PrimMonad m => SparseVector a -> m (MSparseVector (PrimState m) a)
- unsafeThaw :: PrimMonad m => SparseVector a -> m (MSparseVector (PrimState m) a)
Sparse vectors
newtype SparseVector a Source #
Sparse n-dimensional vector.
A sparse vector is defined as a Vector (Bool, a),
where (Bool, a) is a cell for an element in the sparse vector.
The Bool indicates whether the cell contains a valid element.
Inserting elements at some dimension n will grow the vector up to n,
using (False, defaultVal) to create empty cells.
Constructors
| SparseVector | |
Fields
| |
Instances
Construction
empty :: SparseVector a Source #
Empty sparse vector (requires a default value for operations that need it).
emptyWith :: a -> SparseVector a Source #
Empty sparse vector with a default value.
Operations
insert :: Int -> a -> SparseVector a -> SparseVector a Source #
Insert an element at a given index into a SparseVector.
Inserting elements at some dimension n will grow the vector up to n,
using (False, defaultVal) to create empty cells.
>>>insert 0 'a' 'x' emptySparseVector {unSparseVector = [(True, 'a')]}
>>>insert 2 'b' 'x' emptySparseVector {unSparseVector = [(False, 'x'), (False, 'x'), (True, 'b')]}
lookup :: Int -> SparseVector a -> Maybe a Source #
Lookup an element at a given index in a SparseVector.
delete :: Int -> SparseVector a -> SparseVector a Source #
Delete an index from a SparseVector, replacing its cell with (False, defaultVal).
mapWithKey :: (Int -> a -> b) -> SparseVector a -> SparseVector b Source #
mapAccum :: (a -> b -> (a, c)) -> a -> SparseVector b -> (a, SparseVector c) Source #
Intersection
intersection :: SparseVector a -> SparseVector b -> SparseVector a Source #
intersectionWith :: (a -> b -> c) -> SparseVector a -> SparseVector b -> SparseVector c Source #
intersectionWithKey :: (Int -> a -> b -> c) -> SparseVector a -> SparseVector b -> SparseVector c Source #
intersectionVec :: SparseVector a -> SparseVector b -> Vector a Source #
intersectionVecWith :: (a -> b -> c) -> SparseVector a -> SparseVector b -> Vector c Source #
intersectionVecWithKey :: (Int -> a -> b -> c) -> SparseVector a -> SparseVector b -> Vector c Source #
Conversion
fromList :: [(Int, a)] -> SparseVector a Source #
toList :: SparseVector a -> [Maybe a] Source #
toPairList :: SparseVector a -> [(Bool, a)] Source #
fromVector :: Vector a -> SparseVector a Source #
toVector :: SparseVector a -> Vector a Source #
freeze :: PrimMonad m => MSparseVector (PrimState m) a -> m (SparseVector a) Source #
Freeze a MSparseVector into a SparseVector.
unsafeFreeze :: PrimMonad m => MSparseVector (PrimState m) a -> m (SparseVector a) Source #
Freeze a MSparseVector into a SparseVector.
thaw :: PrimMonad m => SparseVector a -> m (MSparseVector (PrimState m) a) Source #
Unfreeze a SparseVector into a MSparseVector.
unsafeThaw :: PrimMonad m => SparseVector a -> m (MSparseVector (PrimState m) a) Source #
Unfreeze a SparseVector into a MSparseVector.