Safe Haskell | Safe-Infered |
---|
- data Numbering a = UnsafeMkNumbering {}
- enumNu :: Enum a => a -> a -> Numbering a
- enumNu' :: Enum a => Int -> Int -> Numbering a
- nuFromSet :: Map Int ignored -> Numbering Int
- nuFromDistinctVector :: (Ord a, Show a, Vector v a) => v a -> Numbering a
- nuFromDistinctVectorG :: (Show a, Vector v a) => map -> ((a -> Int -> Int -> t) -> a -> Int -> map -> map) -> (a -> map -> Maybe Int) -> v a -> Numbering a
- finiteTypeNu :: (Enum a, Bounded a) => Numbering a
- idNu :: Int -> Numbering Int
- emptyNu :: Numbering a
- nuFromDistinctList :: (Ord a, Show a) => [a] -> Numbering a
- nuFromDistinctUnboxList :: (Ord a, Show a, Unbox a) => [a] -> Numbering a
- nuFromDistinctIntList :: [Int] -> Numbering Int
- nuFromList :: (Ord a, Show a) => [a] -> Numbering a
- nuFromUnboxList :: (Ord a, Show a, Unbox a) => [a] -> Numbering a
- nuFromIntList :: [Int] -> Numbering Int
- mapNu :: (a -> b) -> (b -> a) -> Numbering a -> Numbering b
- reindexNu :: Int -> (Int -> Int) -> (Int -> Int) -> Numbering a -> Numbering a
- consolidateNu :: (Ord a, Show a) => Numbering a -> Numbering a
- consolidateUnboxNu :: (Ord a, Show a, Unbox a) => Numbering a -> Numbering a
- nuTake :: Int -> Numbering a -> Numbering a
- reverseNu :: Numbering a -> Numbering a
- nuDrop :: Int -> Numbering a -> Numbering a
- sumNu :: (a1 -> a) -> (a2 -> a) -> ((a1 -> Int) -> (a2 -> Int) -> a -> Int) -> Numbering a1 -> Numbering a2 -> Numbering a
- eitherNu :: Numbering a -> Numbering b -> Numbering (Either a b)
- prodNu :: (a -> a2) -> (a -> a1) -> (a2 -> a1 -> a) -> Numbering a2 -> Numbering a1 -> Numbering a
- pairNu :: Numbering a -> Numbering b -> Numbering (a, b)
- nuIndices :: Numbering a -> [Int]
- nuElements :: Numbering a -> [a]
- nuToList :: Numbering a -> [a]
- nuToDistinctList :: Numbering a -> [a]
- nuToVector :: Vector v a => Numbering a -> v a
- nuToDistinctVector :: Vector v a => Numbering a -> v a
- data NumberingBrokenInvariantException a = NumberingBrokenInvariantException {}
- checkNu :: Numbering a -> Either (NumberingBrokenInvariantException a) ()
Documentation
Invariant:
For all i in 0 ..nuLength
- 1,toInt
(fromInt
i) == i
This implies that
For all a of the formfromInt
i (with i in 0 ..nuLength
- 1),fromInt
(toInt
a) = a
The behaviour of fromInt
for out-of-bounds indices and that of toInt
for elements not occuring in the numbering is undefined.
Thus, assuming the invariant holds, toInt
is uniquely determined by fromInt
(on valid inputs).
UnsafeMkNumbering | "Unsafe" because the invariant isn't checked. |
Construction
enumNu :: Enum a => a -> a -> Numbering aSource
enumNu a b
creates a numbering of the elements [a .. b]
(inclusively).
enumNu' :: Enum a => Int -> Int -> Numbering aSource
enumNu' i j
creates a numbering of the elements [toEnum i .. toEnum j]
(inclusively).
nuFromDistinctVector :: (Ord a, Show a, Vector v a) => v a -> Numbering aSource
The distinctness precondition is checked (we have to create a map anyway).
:: (Show a, Vector v a) | |
=> map |
|
-> ((a -> Int -> Int -> t) -> a -> Int -> map -> map) |
|
-> (a -> map -> Maybe Int) |
|
-> v a | |
-> Numbering a |
Allows customization of the map type used.
finiteTypeNu :: (Enum a, Bounded a) => Numbering aSource
Numbering of all elements of a finite type.
From a list
nuFromDistinctList :: (Ord a, Show a) => [a] -> Numbering aSource
See nuFromDistinctVector
.
nuFromDistinctUnboxList :: (Ord a, Show a, Unbox a) => [a] -> Numbering aSource
See nuFromDistinctVector
.
nuFromDistinctIntList :: [Int] -> Numbering IntSource
nuFromList :: (Ord a, Show a) => [a] -> Numbering aSource
Uniquifies the input first (resulting in an unspecified order).
nuFromUnboxList :: (Ord a, Show a, Unbox a) => [a] -> Numbering aSource
Uniquifies the input first (resulting in an unspecified order).
nuFromIntList :: [Int] -> Numbering IntSource
Uniquifies the input first (resulting in an unspecified order).
Transformation
:: Int | New |
-> (Int -> Int) | Old index to new index |
-> (Int -> Int) | New index to old index |
-> Numbering a | |
-> Numbering a |
In reindexNu k f g nu
, the arguments must satisfy
For all i in 0 .. k, (g . f) i == i
Note: Decreasing the length with this function will not release any memory retained
by the closures in the input numbering (e.g. the vector, for numberings created by nuFromDistinctVector
). Use consolidateNu
afterwards for that.
consolidateNu :: (Ord a, Show a) => Numbering a -> Numbering aSource
Semantic id
(for in-bounds inputs), but backs the numbering with a new vector and map having just the required length (example: consolidateNu (
).
nuTake
1 (nuFromDistinctVector
largeVector))
consolidateUnboxNu :: (Ord a, Show a, Unbox a) => Numbering a -> Numbering aSource
Like consolidateNu
, but uses unboxed vectors.
Particular reindexings
Combination
:: (a1 -> a) |
|
-> (a2 -> a) |
|
-> ((a1 -> Int) -> (a2 -> Int) -> a -> Int) |
|
-> Numbering a1 | |
-> Numbering a2 | |
-> Numbering a |
Creates a numbering for an Either
-like type, given numberings for the summand types.
:: (a -> a2) |
|
-> (a -> a1) |
|
-> (a2 -> a1 -> a) |
|
-> Numbering a2 | |
-> Numbering a1 | |
-> Numbering a |
Creates a numbering for an pair-like type, given numberings for the component types.
Destruction
nuElements :: Numbering a -> [a]Source
nuToList :: Numbering a -> [a]Source
= nuElements
.
nuToDistinctList :: Numbering a -> [a]Source
= nuElements
. Won't actually be distinct if the invariant is broken.
nuToVector :: Vector v a => Numbering a -> v aSource
nuToDistinctVector :: Vector v a => Numbering a -> v aSource
= nuToVector
. Won't actually be distinct if the invariant is broken.