Safe Haskell | None |
---|---|
Language | GHC2021 |
Synopsis
- data FlatBag a
- = EmptyFlatBag
- | UnitFlatBag !a
- | TupleFlatBag !a !a
- emptyFlatBag :: FlatBag a
- unitFlatBag :: a -> FlatBag a
- sizeFlatBag :: FlatBag a -> Word
- elemsFlatBag :: FlatBag a -> [a]
- mappendFlatBag :: FlatBag a -> FlatBag a -> FlatBag a
- fromList :: Word -> [a] -> FlatBag a
- fromSizedSeq :: SizedSeq a -> FlatBag a
Documentation
Store elements in a flattened representation.
A FlatBag
is a data structure that stores an ordered list of elements
in a flat structure, avoiding the overhead of a linked list.
Use this data structure, if the code requires the following properties:
- Elements are stored in a long-lived object, and benefit from a flattened representation.
- The
FlatBag
will be traversed but not extended or filtered. - The number of elements should be known.
- Sharing of the empty case improves memory behaviour.
A FlagBag
aims to have as little overhead as possible to store its elements.
To achieve that, it distinguishes between the empty case, singleton, tuple
and general case.
Thus, we only pay for the additional three words of an Array
if we have at least
three elements.
EmptyFlatBag | |
UnitFlatBag !a | |
TupleFlatBag !a !a |
Instances
Functor FlatBag Source # | |
Foldable FlatBag Source # | |
Defined in GHC.Data.FlatBag fold :: Monoid m => FlatBag m -> m # foldMap :: Monoid m => (a -> m) -> FlatBag a -> m # foldMap' :: Monoid m => (a -> m) -> FlatBag a -> m # foldr :: (a -> b -> b) -> b -> FlatBag a -> b # foldr' :: (a -> b -> b) -> b -> FlatBag a -> b # foldl :: (b -> a -> b) -> b -> FlatBag a -> b # foldl' :: (b -> a -> b) -> b -> FlatBag a -> b # foldr1 :: (a -> a -> a) -> FlatBag a -> a # foldl1 :: (a -> a -> a) -> FlatBag a -> a # elem :: Eq a => a -> FlatBag a -> Bool # maximum :: Ord a => FlatBag a -> a # minimum :: Ord a => FlatBag a -> a # | |
Traversable FlatBag Source # | |
NFData a => NFData (FlatBag a) Source # | |
Defined in GHC.Data.FlatBag |
emptyFlatBag :: FlatBag a Source #
unitFlatBag :: a -> FlatBag a Source #
Create a singleton FlatBag
.
sizeFlatBag :: FlatBag a -> Word Source #
Calculate the size of
elemsFlatBag :: FlatBag a -> [a] Source #
Get all elements that are stored in the FlatBag
.
Construction
fromList :: Word -> [a] -> FlatBag a Source #
Store the list in a flattened memory representation, avoiding the memory overhead of a linked list.
The size n
needs to be smaller or equal to the length of the list.
If it is smaller than the length of the list, overflowing elements are
discarded. It is undefined behaviour to set n
to be bigger than the
length of the list.