Copyright | (c) Galois Inc 2022 |
---|---|
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
conceptually (see NOTE) a map with FinMap
n a
keys, implying a maximum size of Fin
nn
. Here's how FinMap
compares to other
map-like types:
is conceptually isomorphic to aFinMap
n a
, but can be more space-efficient especially ifVector
n (Maybe
a)n
is large and the vector is populated with a small number ofJust
values.
is less general thanFinMap
Map
, because it has a fixed key type (
).Fin
n
is similar toFinMap
n a
, but it provides a static guarantee of a maximum size, and its operations (such asIntMap
asize
) allow the recovery of more type-level information.
is dissimilar from Data.Parameterized.Map.MapF in that neither the key nor value type ofFinMap
FinMap
is parameterized.
The type parameter n
doesn't track the current number of key-value pairs in
a
(i.e., the size of the map), but rather an upper bound.
FinMap
ninsert
and delete
don't alter n
, whereas incMax
does - despite the fact
that it has no effect on the keys and values in the FinMap
.
The FinMap
interface has two implementations:
- The implementation in Data.Parameterized.FinMap.Unsafe is backed by an
IntMap
, and must have a size of at most
. This module uses unsafe operations likemaxBound
::Int
unsafeCoerce
internally for the sake of time and space efficiency. - The implementation in Data.Parameterized.FinMap.Safe is backed by an
. All of its functions are implemented using safe operations.Map
(Fin
n)
The implementation in FinMap
is property
tested against that in FinMap
to ensure
they have the same behavior.
In this documentation, W is used in big-O notations the same way as in the Data.IntMap documentation.
NOTE: Where the word "conceptually" is used, it implies that this correspondence
is not literally true, but is true modulo some details such as differences
between bounded types like Int
and unbounded types like Integer
.
Several of the functions in both implementations are marked INLINE
or
INLINABLE
. There are three reasons for this:
- Some of these just have very small definitions and so inlining is likely more beneficial than harmful.
- Some participate in
RULES
relevant to functions used in their implementations. - They are thin wrappers (often just newtype wrappers) around functions marked
INLINE
, which should therefore also be inlined.