Int +containers

module Data.IntMap
containers Data.IntMap
An efficient implementation of maps from integer keys to values (dictionaries). This module re-exports the value lazy Data.IntMap.Lazy API, plus several deprecated value strict functions. Please note that these functions have different strictness properties than those in Data.IntMap.Strict: they only evaluate the result of the combining function. For example, the default value to insertWith' is only evaluated if the combining function is called and uses it. These modules are intended to be imported qualified, to avoid name clashes with Prelude functions, e.g. > import Data.IntMap (IntMap) > import qualified Data.IntMap as IntMap The implementation is based on big-endian patricia trees. This data structure performs especially well on binary operations like union and intersection. However, my benchmarks show that it is also (much) faster on insertions and deletions when compared to a generic size-balanced map implementation (see Data.Map). * Chris Okasaki and Andy Gill, "Fast Mergeable Integer Maps", Workshop on ML, September 1998, pages 77-86, http://citeseer.ist.psu.edu/okasaki98fast.html * D.R. Morrison, "/PATRICIA -- Practical Algorithm To Retrieve Information Coded In Alphanumeric/", Journal of the ACM, 15(4), October 1968, pages 514-534. Operation comments contain the operation time complexity in the Big-O notation http://en.wikipedia.org/wiki/Big_O_notation. Many operations have a worst-case complexity of O(min(n,W)). This means that the operation can become linear in the number of elements with a maximum of W -- the number of bits in an Int (32 or 64).
module Data.IntSet
containers Data.IntSet
An efficient implementation of integer sets. These modules are intended to be imported qualified, to avoid name clashes with Prelude functions, e.g. > import Data.IntSet (IntSet) > import qualified Data.IntSet as IntSet The implementation is based on big-endian patricia trees. This data structure performs especially well on binary operations like union and intersection. However, my benchmarks show that it is also (much) faster on insertions and deletions when compared to a generic size-balanced set implementation (see Data.Set). * Chris Okasaki and Andy Gill, "Fast Mergeable Integer Maps", Workshop on ML, September 1998, pages 77-86, http://citeseer.ist.psu.edu/okasaki98fast.html * D.R. Morrison, "/PATRICIA -- Practical Algorithm To Retrieve Information Coded In Alphanumeric/", Journal of the ACM, 15(4), October 1968, pages 514-534. Additionally, this implementation places bitmaps in the leaves of the tree. Their size is the natural size of a machine word (32 or 64 bits) and greatly reduce memory footprint and execution times for dense sets, e.g. sets other. The asymptotics are not affected by this optimization. Many operations have a worst-case complexity of O(min(n,W)). This means that the operation can become linear in the number of elements with a maximum of W -- the number of bits in an Int (32 or 64).
data IntMap a
containers Data.IntMap.Strict, containers Data.IntMap.Lazy
A map of integers to values a.
data IntSet
containers Data.IntSet
A set of integers.
intersection :: IntMap a -> IntMap b -> IntMap a
containers Data.IntMap.Strict, containers Data.IntMap.Lazy
O(n+m). The (left-biased) intersection of two maps (based on keys). > intersection (fromList [(5, "a"), (3, "b")]) (fromList [(5, "A"), (7, "C")]) == singleton 5 "a"
intersection :: IntSet -> IntSet -> IntSet
containers Data.IntSet
O(n+m). The intersection of two sets.
intersection :: Ord a => Set a -> Set a -> Set a
containers Data.Set
O(n+m). The intersection of two sets. The implementation uses an efficient hedge algorithm comparable with hedge-union. Elements of the result come from the first set, so for example > import qualified Data.Set as S > data AB = A | B deriving Show > instance Ord AB > instance Eq AB > main = print (S.singleton A `S.intersection` S.singleton B, > S.singleton B `S.intersection` S.singleton A) prints (fromList [A],fromList [B]).
intersection :: Ord k => Map k a -> Map k b -> Map k a
containers Data.Map.Lazy, containers Data.Map.Strict
O(n+m). Intersection of two maps. Return data in the first map for the keys existing in both maps. (intersection m1 m2 == intersectionWith const m1 m2). The implementation uses an efficient hedge algorithm comparable with hedge-union. > intersection (fromList [(5, "a"), (3, "b")]) (fromList [(5, "A"), (7, "C")]) == singleton 5 "a"
intersectionWith :: (a -> b -> c) -> IntMap a -> IntMap b -> IntMap c
containers Data.IntMap.Strict, containers Data.IntMap.Lazy
O(n+m). The intersection with a combining function. > intersectionWith (++) (fromList [(5, "a"), (3, "b")]) (fromList [(5, "A"), (7, "C")]) == singleton 5 "aA"
intersectionWith :: Ord k => (a -> b -> c) -> Map k a -> Map k b -> Map k c
containers Data.Map.Lazy, containers Data.Map.Strict
O(n+m). Intersection with a combining function. The implementation uses an efficient hedge algorithm comparable with hedge-union. > intersectionWith (++) (fromList [(5, "a"), (3, "b")]) (fromList [(5, "A"), (7, "C")]) == singleton 5 "aA"
intersectionWithKey :: (Key -> a -> b -> c) -> IntMap a -> IntMap b -> IntMap c
containers Data.IntMap.Strict, containers Data.IntMap.Lazy
O(n+m). The intersection with a combining function. > let f k al ar = (show k) ++ ":" ++ al ++ "|" ++ ar > intersectionWithKey f (fromList [(5, "a"), (3, "b")]) (fromList [(5, "A"), (7, "C")]) == singleton 5 "5:a|A"
intersectionWithKey :: Ord k => (k -> a -> b -> c) -> Map k a -> Map k b -> Map k c
containers Data.Map.Lazy, containers Data.Map.Strict
O(n+m). Intersection with a combining function. The implementation uses an efficient hedge algorithm comparable with hedge-union. > let f k al ar = (show k) ++ ":" ++ al ++ "|" ++ ar > intersectionWithKey f (fromList [(5, "a"), (3, "b")]) (fromList [(5, "A"), (7, "C")]) == singleton 5 "5:a|A"