-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | A library that can be used for multiple Ord a => a -> b transformations. -- -- A library that can be used as a case ... of construction -- replacement for various cases. Since the 0.2.0.0 version also uses the -- cuckoo hashtables in the respective module. @package mmsyn2-array @version 0.2.0.0 -- | A library that can be used as a case ... of constuction -- analogue for the Hashable keys. For the large lists is expected to be -- more time efficient than CaseBi.Arr.getBFst' analogue. If you plan to -- use it together with the former one, please, use qualified import to -- avoid names ambiguity. module Case.Hashable.Cuckoo getBFstL' :: (Eq k, Hashable k) => v -> [(k, v)] -> k -> v -- | A library that can be used as a case ... of constuction -- analogue for the multiple Ord a => a -> b -- transformations and data representation. Uses Array internally. -- If you use the module in GHCi, then, please, run the interpreter with -- the flag -fobject-code. module CaseBi.Arr -- | The function that can be used instead of the 'case ... of' function -- case var of { a1 -> b1 ; a2 -> b2 ; a3 -> b3 ; ... ; an -- -> bn ; ~z -> defaultValue } If we follow a lot of -- teaching materials that explain the workflow of the construction we -- think that the complexity of it is about O(n) for the -- transformation of a to b here. David Feuer -- (david.feuer (at) gmail.com) said that 'case ... of' is already -- optimized in GHC. Some benchmarks show that its behaviour tends to be -- about of O(log n) complexity, the same as the proposed function -- getBFst'. Nevertheless, the last one shows better performance -- in some situations, is rather general and can be used for another data -- representation. Therefore, it can be preferred in some situations. -- getBFst' uses binary search algorithm and an Array of -- (a, b) as somewhat like a complicated filter or like a -- special sieve. The array must be sorted in ascending order here for -- the algorithm to be used correctly. For this you can use the function -- listArrSortedByFst or the similar ones. If you would like to -- use them both, please, consider usage of the getBFstLSorted' or -- getBFstL' instead. The function getBFst'' is used -- internally in the getBFst' that is recommended to be used in -- most cases. Nevertheless, it is provided here if you have precomputed -- the first two arguments or at least some parts of them so that you can -- reduce the needed amount of computations in the getBFst'. getBFst'' :: (Ord a, Ix i) => (# Int, (a, b) #) -> (# Int, (a, b) #) -> Array i (a, b) -> b -> a -> b -- | A generally written without extending variant of the getBFst''. getBFst' :: Ord a => (b, Array Int (a, b)) -> a -> b -- | Sorts the list of pairs by the first element in the tuples, then -- transforms them into an immutable array. Can be used only if the list -- contains no more than 2^31 - 1 elements though this is not checked, it -- is up to user to check this constraint before or provide its -- correctness by design. listArrSortedByFst :: Ord a => [(a, b)] -> Array Int (a, b) -- | If the list argument is sorted in the ascending order by the first -- element in every tuple, then to reduce computations instead of -- \def xs x -> getBFst' (def, listArray (0,length xs - 1) xs) x -- you can use this function. getBFstLSorted' :: Ord a => b -> [(a, b)] -> a -> b -- | If it is unknown whether the list argument is sorted in the ascending -- order by the first element in every tuple (or, definitely, it is not, -- speaking generally), then instead of \def xs x -> getBFst' -- (def, listArray (0,length xs - 1) . sortBy (comparing fst) $ xs) x -- you can use this function. getBFstL' :: Ord a => b -> [(a, b)] -> a -> b