2*:      !"#$%&'()*+,-./0123456789:;<=:;<=>?@ABCDEFGHIJKLMNOPQRS>?@@ABCDBCDEFGHHIJKLMNJKLMNRSTUVTUV<WXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~&WZYXXYZ[\]^_`abcdefqstuvwxyz{|}~portable experimentallibraries@haskell.org:A Map from keys k to values a. O(log n). Find the value at a key.  Calls $ when the element can not be found. B fromList [(5,'a'), (3,'b')] ! 1 Error: element not in the map ( fromList [(5,'a'), (3,'b')] ! 5 == 'a' O(1). Is the map empty? ) Data.Map.null (empty) == True * Data.Map.null (singleton 1 'a') == False O(1)%. The number of elements in the map. 3 size empty == 0 3 size (singleton 1 'a') == 1 3 size (fromList([(1,'a'), (2,'c'), (3,'b')])) == 3 O(log n)+. Is the key a member of the map? See also . 0 member 5 (fromList [(5,'a'), (3,'b')]) == True 1 member 1 (fromList [(5,'a'), (3,'b')]) == False O(log n)/. Is the key not a member of the map? See also . 4 notMember 5 (fromList [(5,'a'), (3,'b')]) == False 3 notMember 1 (fromList [(5,'a'), (3,'b')]) == True O(log n)(. Lookup the value at a key in the map. 4The function will return the corresponding value as ( value),  or  if the key isn't in the map. An example of using lookup:   import Prelude hiding (lookup)  import Data.CompactMap  ; employeeDept = fromList([("John","Sales"), ("Bob","IT")]) < deptCountry = fromList([("IT","USA"), ("Sales","France")]) E countryCurrency = fromList([("USA", "Dollar"), ("France", "Euro")])  , employeeCurrency :: String -> Maybe String  employeeCurrency name = do & dept <- lookup name employeeDept ( country <- lookup dept deptCountry $ lookup country countryCurrency   main = do H putStrLn $ "John's currency: " ++ (show (employeeCurrency "John")) H putStrLn $ "Pete's currency: " ++ (show (employeeCurrency "Pete")) The output of this program:  John's currency: Just "Euro"  Pete's currency: Nothing O(log n). The expression ( def k map) returns  the value at key k or returns default value def ! when the key is not in the map. < findWithDefault 'x' 1 (fromList [(5,'a'), (3,'b')]) == 'x' < findWithDefault 'x' 5 (fromList [(5,'a'), (3,'b')]) == 'a' O(1). The empty map.  empty == fromList []  size empty == 0 O(1). A map with a single element. / singleton 1 'a' == fromList [(1, 'a')]  size (singleton 1 'a') == 1 O(log n)). Insert a new key and value in the map. C If the key is already present in the map, the associated value is # replaced with the supplied value.   is equivalent to    . M insert 5 'x' (fromList [(5,'a'), (3,'b')]) == fromList [(3, 'b'), (5, 'x')] W insert 7 'x' (fromList [(5,'a'), (3,'b')]) == fromList [(3, 'b'), (5, 'a'), (7, 'x')] ? insert 5 'x' empty == singleton 5 'x' O(log n)=. Insert with a function, combining new value and old value.    f key value mp ( will insert the pair (key, value) into mp if key does @ not exist in the map. If the key does exist, the function will  insert the pair (key, f new_value old_value). [ insertWith (++) 5 "xxx" (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "xxxa")] d insertWith (++) 7 "xxx" (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "a"), (7, "xxx")] L insertWith (++) 5 "xxx" empty == singleton 5 "xxx" O(log n)B. Insert with a function, combining key, new value and old value.    f key value mp ( will insert the pair (key, value) into mp if key does @ not exist in the map. If the key does exist, the function will  insert the pair (key,f key new_value old_value). 9 Note that the key passed to f is the same key passed to  . T let f key new_value old_value = (show key) ++ ":" ++ new_value ++ "|" ++ old_value ^ insertWithKey f 5 "xxx" (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "5:xxx|a")] d insertWithKey f 7 "xxx" (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "a"), (7, "xxx")] L insertWithKey f 5 "xxx" empty == singleton 5 "xxx" O(log n)6. Combines insert operation with old value retrieval.  The expression (  f k x map) 0 is a pair where the first element is equal to ( k map) " and the second element equal to (  f k x map).  T let f key new_value old_value = (show key) ++ ":" ++ new_value ++ "|" ++ old_value p insertLookupWithKey f 5 "xxx" (fromList [(5,"a"), (3,"b")]) == (Just "a", fromList [(3, "b"), (5, "5:xxx|a")]) v insertLookupWithKey f 7 "xxx" (fromList [(5,"a"), (3,"b")]) == (Nothing, fromList [(3, "b"), (5, "a"), (7, "xxx")]) ^ insertLookupWithKey f 5 "xxx" empty == (Nothing, singleton 5 "xxx") This is how to define  insertLookup using insertLookupWithKey: D let insertLookup kx x t = insertLookupWithKey (\_ a _ -> a) kx x t _ insertLookup 5 "x" (fromList [(5,"a"), (3,"b")]) == (Just "a", fromList [(3, "b"), (5, "x")]) i insertLookup 7 "x" (fromList [(5,"a"), (3,"b")]) == (Nothing, fromList [(3, "b"), (5, "a"), (7, "x")]) O(log n)?. Delete a key and its value from the map. When the key is not 4 a member of the map, the original map is returned. ; delete 5 (fromList [(5,"a"), (3,"b")]) == singleton 3 "b" I delete 7 (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "a")] 1 delete 5 empty == empty O(log n)M. Update a value at a specific key with the result of the provided function.  When the key is not 4 a member of the map, the original map is returned. Y adjust ("new " ++) 5 (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "new a")] U adjust ("new " ++) 7 (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "a")] = adjust ("new " ++) 7 empty == empty O(log n)8. Adjust a value at a specific key. When the key is not 4 a member of the map, the original map is returned. * let f key x = (show key) ++ ":new " ++ x X adjustWithKey f 5 (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "5:new a")] R adjustWithKey f 7 (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "a")] : adjustWithKey f 7 empty == empty O(log n). The expression ( f k map) updates the value x  at k (if it is in the map). If (f x) is , the element is  deleted. If it is ( y ), the key k is bound to the new value y. 6 let f x = if x == "a" then Just "new a" else Nothing O update f 5 (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "new a")] K update f 7 (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "a")] = update f 3 (fromList [(5,"a"), (3,"b")]) == singleton 5 "a" O(log n). The expression ( f k map) updates the  value x at k (if it is in the map). If (f k x) is , # the element is deleted. If it is ( y ), the key k is bound  to the new value y. G let f k x = if x == "a" then Just ((show k) ++ ":new a") else Nothing X updateWithKey f 5 (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "5:new a")] R updateWithKey f 7 (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "a")] D updateWithKey f 3 (fromList [(5,"a"), (3,"b")]) == singleton 5 "a" O(log n). Lookup and update. See also . 7 The function returns changed value, if it is updated. > Returns the original key value if the map entry is deleted. G let f k x = if x == "a" then Just ((show k) ++ ":new a") else Nothing p updateLookupWithKey f 5 (fromList [(5,"a"), (3,"b")]) == (Just "5:new a", fromList [(3, "b"), (5, "5:new a")]) d updateLookupWithKey f 7 (fromList [(5,"a"), (3,"b")]) == (Nothing, fromList [(3, "b"), (5, "a")]) V updateLookupWithKey f 3 (fromList [(5,"a"), (3,"b")]) == (Just "b", singleton 5 "a") O(log n). The expression ( f k map) alters the value x at k, or absence thereof.  7 can be used to insert, delete, or update a value in a .  In short :  k ( f k m) = f ( k m).  let f _ = Nothing J alter f 7 (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "a")] < alter f 5 (fromList [(5,"a"), (3,"b")]) == singleton 3 "b"   let f _ = Just "c" T alter f 7 (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "a"), (7, "c")] J alter f 5 (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "c")]  O(log n*m).  The expression ( t1 t2!) takes the left-biased union of t1 and t2.  It prefers t1& when duplicate keys are encountered,  i.e. ( ==  ). r union (fromList [(5, "a"), (3, "b")]) (fromList [(5, "A"), (7, "C")]) == fromList [(3, "b"), (5, "a"), (7, "C")]  O(log n*m)#. Union with a combining function. | unionWith (++) (fromList [(5, "a"), (3, "b")]) (fromList [(5, "A"), (7, "C")]) == fromList [(3, "b"), (5, "aA"), (7, "C")]  O(log n*m). " Union with a combining function. T let f key new_value old_value = (show key) ++ ":" ++ new_value ++ "|" ++ old_value  unionWithKey f (fromList [(5, "a"), (3, "b")]) (fromList [(5, "A"), (7, "C")]) == fromList [(3, "b"), (5, "5:a|A"), (7, "C")] The union of a list of maps:  ( ==    ). n unions [(fromList [(5, "a"), (3, "b")]), (fromList [(5, "A"), (7, "C")]), (fromList [(5, "A3"), (3, "B3")])] 0 == fromList [(3, "b"), (5, "a"), (7, "C")] n unions [(fromList [(5, "A3"), (3, "B3")]), (fromList [(5, "A"), (7, "C")]), (fromList [(5, "a"), (3, "b")])] 2 == fromList [(3, "B3"), (5, "A3"), (7, "C")] 9The union of a list of maps, with a combining operation:  ( f ==   ( f) ). w unionsWith (++) [(fromList [(5, "a"), (3, "b")]), (fromList [(5, "A"), (7, "C")]), (fromList [(5, "A3"), (3, "B3")])] 5 == fromList [(3, "bB3"), (5, "aAA3"), (7, "C")] O(n)-. Map a function over all values in the map. O map (++ "x") (fromList [(5,"a"), (3,"b")]) == fromList [(3, "bx"), (5, "ax")] O(n)-. Map a function over all values in the map. & let f key x = (show key) ++ ":" ++ x Q mapWithKey f (fromList [(5,"a"), (3,"b")]) == fromList [(3, "3:b"), (5, "5:a")]  O(n*log n).   f s! is the map obtained by applying f to each key of s. )The size of the result may be smaller if f maps two or more distinct F keys to the same new key. In this case the value at the smallest of  these keys is retained. e mapKeys (+ 1) (fromList [(5,"a"), (3,"b")]) == fromList [(4, "b"), (6, "a")] W mapKeys (\ _ -> 1) (fromList [(1,"b"), (2,"a"), (3,"d"), (4,"c")]) == singleton 1 "c" W mapKeys (\ _ -> 3) (fromList [(1,"b"), (2,"a"), (3,"d"), (4,"c")]) == singleton 3 "c"  O(n*log n).   c f s! is the map obtained by applying f to each key of s. )The size of the result may be smaller if f maps two or more distinct G keys to the same new key. In this case the associated values will be  combined using c. c mapKeysWith (++) (\ _ -> 1) (fromList [(1,"b"), (2,"a"), (3,"d"), (4,"c")]) == singleton 1 "cdab" c mapKeysWith (++) (\ _ -> 3) (fromList [(1,"b"), (2,"a"), (3,"d"), (4,"c")]) == singleton 3 "cdab" O(n).   f s ==  f s, but works only when f  is strictly monotonic.  That is, for any values x and y, if x < y then f x < f y.   The precondition is not checked.  Semi-formally, we have:  / and [x < y ==> f x < f y | x <- ls, y <- ls] = ==> mapKeysMonotonic f s == mapKeys f s  where ls = keys s This means that f9 maps distinct original keys to distinct resulting keys. + This function has better performance than . a mapKeysMonotonic (\ k -> k * 2) (fromList [(5,"a"), (3,"b")]) == fromList [(6, "b"), (10, "a")] O valid (mapKeysMonotonic (\ k -> k * 2) (fromList [(5,"a"), (3,"b")])) == True P valid (mapKeysMonotonic (\ _ -> 1) (fromList [(5,"a"), (3,"b")])) == False O(n)(. Fold the values in the map, such that   f z ==   f z . !.  For example,   elems map = fold (:) [] map  let f a len = len + (length a) / fold f 0 (fromList [(5,"a"), (3,"bbb")]) == 4 O(n)1. Fold the keys and values in the map, such that    f z ==   (  f) z . ).  For example,  1 keys map = foldWithKey (\k x ks -> k:ks) [] map A let f k a result = result ++ "(" ++ (show k) ++ ":" ++ a ++ ")" J foldWithKey f "Map: " (fromList [(5,"a"), (3,"b")]) == "Map: (5:a)(3:b)" !O(n). F Return all elements of the map in the ascending order of their keys. 2 elems (fromList [(5,"a"), (3,"b")]) == ["b","a"]  elems empty == [] "O(n)1. Return all keys of the map in ascending order. - keys (fromList [(5,"a"), (3,"b")]) == [3,5]  keys empty == [] #O(n)". The set of all keys of the map. B keysSet (fromList [(5,"a"), (3,"b")]) == Data.Set.fromList [3,5] ! keysSet empty == Data.Set.empty $O(n). Return all key//value pairs in the map in ascending key order. < assocs (fromList [(5,"a"), (3,"b")]) == [(3,"b"), (5,"a")]  assocs empty == [] % O(n*log n) . Build a map from a list of key/value pairs. See also *. K If the list contains more than one value for the same key, the last value  for the key is retained.  fromList [] == empty F fromList [(5,"a"), (3,"b"), (5, "c")] == fromList [(5,"c"), (3,"b")] F fromList [(5,"c"), (3,"b"), (5, "a")] == fromList [(5,"a"), (3,"b")] & O(n*log n) . Build a map from a list of key/0value pairs with a combining function. See also +. e fromListWith (++) [(5,"a"), (5,"b"), (3,"b"), (3,"a"), (5,"a")] == fromList [(3, "ab"), (5, "aba")]  fromListWith (++) [] == empty ' O(n*log n) . Build a map from a list of key/0value pairs with a combining function. See also ,. & let f k a1 a2 = (show k) ++ a1 ++ a2 h fromListWithKey f [(5,"a"), (5,"b"), (3,"b"), (3,"a"), (5,"a")] == fromList [(3, "3ab"), (5, "5a5ba")]  fromListWithKey f [] == empty (O(n). Convert to a list of key/ value pairs. < toList (fromList [(5,"a"), (3,"b")]) == [(3,"b"), (5,"a")]  toList empty == [] )O(n) . Convert to an ascending list. ? toAscList (fromList [(5,"a"), (3,"b")]) == [(3,"b"), (5,"a")] *O(n)5. Build a map from an ascending list in linear time.  :The precondition (input list is ascending) is not checked. J fromAscList [(3,"b"), (5,"a")] == fromList [(3, "b"), (5, "a")] J fromAscList [(3,"b"), (5,"a"), (5,"b")] == fromList [(3, "b"), (5, "b")] 9 valid (fromAscList [(3,"b"), (5,"a"), (5,"b")]) == True : valid (fromAscList [(5,"a"), (3,"b"), (5,"b")]) == False +O(n)^. Build a map from an ascending list in linear time with a combining function for equal keys.  :The precondition (input list is ascending) is not checked. T fromAscListWith (++) [(3,"b"), (5,"a"), (5,"b")] == fromList [(3, "b"), (5, "ba")] B valid (fromAscListWith (++) [(3,"b"), (5,"a"), (5,"b")]) == True C valid (fromAscListWith (++) [(5,"a"), (3,"b"), (5,"b")]) == False ,O(n);. Build a map from an ascending list in linear time with a $ combining function for equal keys.  :The precondition (input list is ascending) is not checked. - let f k a1 a2 = (show k) ++ ":" ++ a1 ++ a2 b fromAscListWithKey f [(3,"b"), (5,"a"), (5,"b"), (5,"b")] == fromList [(3, "b"), (5, "5:b5:ba")] K valid (fromAscListWithKey f [(3,"b"), (5,"a"), (5,"b"), (5,"b")]) == True L valid (fromAscListWithKey f [(5,"a"), (3,"b"), (5,"b"), (5,"b")]) == False -O(n)J. Build a map from an ascending list of distinct elements in linear time.   The precondition is not checked. I fromDistinctAscList [(3,"b"), (5,"a")] == fromList [(3, "b"), (5, "a")] A valid (fromDistinctAscList [(3,"b"), (5,"a")]) == True B valid (fromDistinctAscList [(3,"b"), (5,"a"), (5,"b")]) == False .O(n)0. Filter all values that satisfy the predicate. A filter (> "a") (fromList [(5,"a"), (3,"b")]) == singleton 3 "b" 7 filter (> "x") (fromList [(5,"a"), (3,"b")]) == empty 7 filter (< "a") (fromList [(5,"a"), (3,"b")]) == empty /O(n). Filter all keys/#values that satisfy the predicate. P filterWithKey (\k _ -> k > 4) (fromList [(5,"a"), (3,"b")]) == singleton 5 "a" 0O(n)8. Partition the map according to a predicate. The first F map contains all elements that satisfy the predicate, the second all , elements that fail the predicate. See also split. W partition (> "a") (fromList [(5,"a"), (3,"b")]) == (singleton 3 "b", singleton 5 "a") [ partition (< "x") (fromList [(5,"a"), (3,"b")]) == (fromList [(3, "b"), (5, "a")], empty) [ partition (> "x") (fromList [(5,"a"), (3,"b")]) == (empty, fromList [(3, "b"), (5, "a")]) 1O(n)8. Partition the map according to a predicate. The first F map contains all elements that satisfy the predicate, the second all , elements that fail the predicate. See also split. g partitionWithKey (\ k _ -> k > 3) (fromList [(5,"a"), (3,"b")]) == (singleton 5 "a", singleton 3 "b") k partitionWithKey (\ k _ -> k < 7) (fromList [(5,"a"), (3,"b")]) == (fromList [(3, "b"), (5, "a")], empty) k partitionWithKey (\ k _ -> k > 7) (fromList [(5,"a"), (3,"b")]) == (empty, fromList [(3, "b"), (5, "a")]) 2O(n). Map values and collect the  results. 6 let f x = if x == "a" then Just "new a" else Nothing A mapMaybe f (fromList [(5,"a"), (3,"b")]) == singleton 5 "new a" 3O(n) . Map keys/values and collect the  results. D let f k _ = if k < 5 then Just ("key : " ++ (show k)) else Nothing J mapMaybeWithKey f (fromList [(5,"a"), (3,"b")]) == singleton 3 "key : 3" 4O(n). Map values and separate the   and   results. / let f a = if a < "c" then Left a else Right a = mapEither f (fromList [(5,"a"), (3,"b"), (1,"x"), (7,"z")]) C == (fromList [(3,"b"), (5,"a")], fromList [(1,"x"), (7,"z")])  L mapEither (\ a -> Right a) (fromList [(5,"a"), (3,"b"), (1,"x"), (7,"z")]) ? == (empty, fromList [(5,"a"), (3,"b"), (1,"x"), (7,"z")]) 5O(n) . Map keys/values and separate the   and   results. < let f k a = if k < 5 then Left (k * 2) else Right (a ++ a) D mapEitherWithKey f (fromList [(5,"a"), (3,"b"), (1,"x"), (7,"z")]) A == (fromList [(1,2), (3,6)], fromList [(5,"aa"), (7,"zz")])  T mapEitherWithKey (\_ a -> Right a) (fromList [(5,"a"), (3,"b"), (1,"x"), (7,"z")]) ? == (empty, fromList [(1,"x"), (3,"b"), (5,"a"), (7,"z")]) 6O(log n)$. The minimal key of the map. Calls  is the map is empty. 2 findMin (fromList [(5,"a"), (3,"b")]) == (3,"b") R findMin empty Error: empty map has no minimal element 7O(log n)$. The maximal key of the map. Calls  is the map is empty. 2 findMax (fromList [(5,"a"), (3,"b")]) == (5,"a") R findMax empty Error: empty map has no maximal element 8O(log n)D. Delete the minimal key. Returns an empty map if the map is empty. Q deleteMin (fromList [(5,"a"), (3,"b"), (7,"c")]) == fromList [(5,"a"), (7,"c")]  deleteMin empty == empty 9O(log n)'. Delete and find the minimal element. b deleteFindMin (fromList [(5,"a"), (3,"b"), (10,"c")]) == ((3,"b"), fromList[(5,"a"), (10,"c")]) | deleteFindMin empty == (Error: can not return the minimal element of an empty map,empty) :  !"#$%&'()*+,-./0123456789:  !"#$(%&')*+,-./0123456789:  !"#$%&'()*+,-./0123456789   !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKKLLMNOPQQRRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~  b acompact-map-2008.11.9Data.CompactMapData.CompactMap.FetchData.CompactMap.TypesData.CompactMap.BufferData.CompactMap.IndexbasePrelude Data.Maybe Data.List Data.Tuple Data.EitherMap!nullsizemember notMemberlookupfindWithDefaultempty singletoninsert insertWith insertWithKeyinsertLookupWithKeydeleteadjust adjustWithKeyupdate updateWithKeyupdateLookupWithKeyalterunion unionWith unionWithKeyunions unionsWithmap mapWithKeymapKeys mapKeysWithmapKeysMonotonicfold foldWithKeyelemskeyskeysSetassocsfromList fromListWithfromListWithKeytoList toAscList fromAscListfromAscListWithfromAscListWithKeyfromDistinctAscListfilter filterWithKey partitionpartitionWithKeymapMaybemapMaybeWithKey mapEithermapEitherWithKeyfindMinfindMax deleteMin deleteFindMin getElementextractElementextractElementIntextractElementBSIdxInt IndexItemIndex indexStart indexBuffer DataCursor KeyCursor FastMutIntBuffer bufferData bufferOld bufferPos bufferSize newFastMutIntreadFastMutIntwriteFastMutInt extractFieldputField newBuffer withBytes touchBuffer DirectionStopRightLeftTagpeekKeyCursorDatapeekKeyCursorKeypokeKeyCursorData newKeyCursornewBinaryKeyCursorpushNewDataCursorpeekDataCursorNextpeekDataCursorTagpeekDataCursorDatapokeDataCursorNext newDataCursorintToPtrptrToInt extractTop extractSizeextractElemIdx extractLeft extractRightputTopputSizeputLeftputRightwalkTree lookupNearest lookupLargest putByteStringintSizeptrSizeinsertBS insertWithBS insertKeyinsertLargestKeyinsertLargestKeyCursor lookupKey lookupList fetchAllElts indexItemSize insertPrimlistKeyPointersgetKeyFromPointergetDataFromPointernewIndex touchIndex balanceTreegetSizebalancerotateLrotateRsingleLsingleRdoubleLdoubleRdeltaratioGHC.ErrerrorJustNothingGHC.BaseconstGHC.Listfoldlfoldruncurry