Data.IntMap.Lazy



Copyright
(c) Daan Leijen 2002(c) Andriy Palamarchuk 2008


License
BSD-style


Maintainer
wyattscott@example.org


Portability
portable


Safe Haskell
Safe


Language
Haskell98



Contents

Map type

Construction
From Unordered Lists
From Ascending Lists


Insertion
Deletion/Update

Query
Lookup
Size



Combine
Union
Difference
Intersection
Disjoint
Universal combining function



TraversalMap


FoldsStrict folds


Conversion
Lists
Ordered lists


Filter
Submap
Min/Max
Debugging



Description
Finite Int Maps (lazy interface)
The IntMap v type represents a finite map (sometimes called a dictionary) from keys of type Int to values of type v.
The functions in Data.IntMap.Strict are careful to force values before installing them in an IntMap. This is usually more efficient in cases where laziness is not essential. The functions in this module do not do so.
For a walkthrough of the most commonly used functions see the maps introduction.
This module is intended to be imported qualified, to avoid name clashes with Prelude functions:
import Data.IntMap.Lazy (IntMap)
import qualified Data.IntMap.Lazy as IntMap
Note that the implementation is generally left-biased. Functions that take two maps as arguments and combine them, such as union and intersection, prefer the values in the first argument to those in the second.
Detailed performance information
The amortized running time is given for each operation, with n referring to the number of entries in the map and W referring to the number of bits in an Int (32 or 64).
Benchmarks comparing Data.IntMap.Lazy with other dictionary implementations can be found at https://github.com/haskell-perf/dictionaries.
Implementation
The implementation is based on big-endian patricia trees. This data structure performs especially well on binary operations like union and intersection. Additionally, 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.


Map typedata IntMap a Source 
A map of integers to values a.

Instances
Instances details


Functor IntMap 
 

Instance detailsDefined in Data.IntMap.Internal 
Methods
fmap 8b7c:f320:99b9:690f:4595:cd17:293a:c069 (a -> b) -> IntMap a -> IntMap b Source 
(<$) 8b7c:f320:99b9:690f:4595:cd17:293a:c069 a -> IntMap b -> IntMap a Source 



Foldable IntMap 
Folds in order of increasing key.

Instance detailsDefined in Data.IntMap.Internal 
Methods
fold 8b7c:f320:99b9:690f:4595:cd17:293a:c069 Monoid m => IntMap m -> m Source 
foldMap 8b7c:f320:99b9:690f:4595:cd17:293a:c069 Monoid m => (a -> m) -> IntMap a -> m Source 
foldMap' 8b7c:f320:99b9:690f:4595:cd17:293a:c069 Monoid m => (a -> m) -> IntMap a -> m Source 
foldr 8b7c:f320:99b9:690f:4595:cd17:293a:c069 (a -> b -> b) -> b -> IntMap a -> b Source 
foldr' 8b7c:f320:99b9:690f:4595:cd17:293a:c069 (a -> b -> b) -> b -> IntMap a -> b Source 
foldl 8b7c:f320:99b9:690f:4595:cd17:293a:c069 (b -> a -> b) -> b -> IntMap a -> b Source 
foldl' 8b7c:f320:99b9:690f:4595:cd17:293a:c069 (b -> a -> b) -> b -> IntMap a -> b Source 
foldr1 8b7c:f320:99b9:690f:4595:cd17:293a:c069 (a -> a -> a) -> IntMap a -> a Source 
foldl1 8b7c:f320:99b9:690f:4595:cd17:293a:c069 (a -> a -> a) -> IntMap a -> a Source 
toList 8b7c:f320:99b9:690f:4595:cd17:293a:c069 IntMap a -> [a] Source 
null 8b7c:f320:99b9:690f:4595:cd17:293a:c069 IntMap a -> Bool Source 
length 8b7c:f320:99b9:690f:4595:cd17:293a:c069 IntMap a -> Int Source 
elem 8b7c:f320:99b9:690f:4595:cd17:293a:c069 Eq a => a -> IntMap a -> Bool Source 
maximum 8b7c:f320:99b9:690f:4595:cd17:293a:c069 Ord a => IntMap a -> a Source 
minimum 8b7c:f320:99b9:690f:4595:cd17:293a:c069 Ord a => IntMap a -> a Source 
sum 8b7c:f320:99b9:690f:4595:cd17:293a:c069 Num a => IntMap a -> a Source 
product 8b7c:f320:99b9:690f:4595:cd17:293a:c069 Num a => IntMap a -> a Source 



Traversable IntMap 
Traverses in order of increasing key.

Instance detailsDefined in Data.IntMap.Internal 
Methods
traverse 8b7c:f320:99b9:690f:4595:cd17:293a:c069 Applicative f => (a -> f b) -> IntMap a -> f (IntMap b) Source 
sequenceA 8b7c:f320:99b9:690f:4595:cd17:293a:c069 Applicative f => IntMap (f a) -> f (IntMap a) Source 
mapM 8b7c:f320:99b9:690f:4595:cd17:293a:c069 Monad m => (a -> m b) -> IntMap a -> m (IntMap b) Source 
sequence 8b7c:f320:99b9:690f:4595:cd17:293a:c069 Monad m => IntMap (m a) -> m (IntMap a) Source 



Eq1 IntMap 
Since: containers-0.5.9

Instance detailsDefined in Data.IntMap.Internal 
Methods
liftEq 8b7c:f320:99b9:690f:4595:cd17:293a:c069 (a -> b -> Bool) -> IntMap a -> IntMap b -> Bool Source 



Ord1 IntMap 
Since: containers-0.5.9

Instance detailsDefined in Data.IntMap.Internal 
Methods
liftCompare 8b7c:f320:99b9:690f:4595:cd17:293a:c069 (a -> b -> Ordering) -> IntMap a -> IntMap b -> Ordering Source 



Read1 IntMap 
Since: containers-0.5.9

Instance detailsDefined in Data.IntMap.Internal 
Methods
liftReadsPrec 8b7c:f320:99b9:690f:4595:cd17:293a:c069 (Int -> ReadS a) -> ReadS [a] -> Int -> ReadS (IntMap a) Source 
liftReadList 8b7c:f320:99b9:690f:4595:cd17:293a:c069 (Int -> ReadS a) -> ReadS [a] -> ReadS [IntMap a] Source 
liftReadPrec 8b7c:f320:99b9:690f:4595:cd17:293a:c069 ReadPrec a -> ReadPrec [a] -> ReadPrec (IntMap a) Source 
liftReadListPrec 8b7c:f320:99b9:690f:4595:cd17:293a:c069 ReadPrec a -> ReadPrec [a] -> ReadPrec [IntMap a] Source 



Show1 IntMap 
Since: containers-0.5.9

Instance detailsDefined in Data.IntMap.Internal 
Methods
liftShowsPrec 8b7c:f320:99b9:690f:4595:cd17:293a:c069 (Int -> a -> ShowS) -> ([a] -> ShowS) -> Int -> IntMap a -> ShowS Source 
liftShowList 8b7c:f320:99b9:690f:4595:cd17:293a:c069 (Int -> a -> ShowS) -> ([a] -> ShowS) -> [IntMap a] -> ShowS Source 



IsList (IntMap a) 
Since: containers-937.896.6674

Instance detailsDefined in Data.IntMap.Internal 
Associated Types
type Item (IntMap a) Source 
 
Methods
fromList 8b7c:f320:99b9:690f:4595:cd17:293a:c069 [Item (IntMap a)] -> IntMap a Source 
fromListN 8b7c:f320:99b9:690f:4595:cd17:293a:c069 Int -> [Item (IntMap a)] -> IntMap a Source 
toList 8b7c:f320:99b9:690f:4595:cd17:293a:c069 IntMap a -> [Item (IntMap a)] Source 



Eq a => Eq (IntMap a) 
 

Instance detailsDefined in Data.IntMap.Internal 
Methods
(==) 8b7c:f320:99b9:690f:4595:cd17:293a:c069 IntMap a -> IntMap a -> Bool 
(/=) 8b7c:f320:99b9:690f:4595:cd17:293a:c069 IntMap a -> IntMap a -> Bool 



Data a => Data (IntMap a) 
 

Instance detailsDefined in Data.IntMap.Internal 
Methods
gfoldl 8b7c:f320:99b9:690f:4595:cd17:293a:c069 (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> IntMap a -> c (IntMap a) Source 
gunfold 8b7c:f320:99b9:690f:4595:cd17:293a:c069 (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (IntMap a) Source 
toConstr 8b7c:f320:99b9:690f:4595:cd17:293a:c069 IntMap a -> Constr Source 
dataTypeOf 8b7c:f320:99b9:690f:4595:cd17:293a:c069 IntMap a -> DataType Source 
dataCast1 8b7c:f320:99b9:690f:4595:cd17:293a:c069 Typeable t => (forall d. Data d => c (t d)) -> Maybe (c (IntMap a)) Source 
dataCast2 8b7c:f320:99b9:690f:4595:cd17:293a:c069 Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (IntMap a)) Source 
gmapT 8b7c:f320:99b9:690f:4595:cd17:293a:c069 (forall b. Data b => b -> b) -> IntMap a -> IntMap a Source 
gmapQl 8b7c:f320:99b9:690f:4595:cd17:293a:c069 (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> IntMap a -> r Source 
gmapQr 8b7c:f320:99b9:690f:4595:cd17:293a:c069 forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> IntMap a -> r Source 
gmapQ 8b7c:f320:99b9:690f:4595:cd17:293a:c069 (forall d. Data d => d -> u) -> IntMap a -> [u] Source 
gmapQi 8b7c:f320:99b9:690f:4595:cd17:293a:c069 Int -> (forall d. Data d => d -> u) -> IntMap a -> u Source 
gmapM 8b7c:f320:99b9:690f:4595:cd17:293a:c069 Monad m => (forall d. Data d => d -> m d) -> IntMap a -> m (IntMap a) Source 
gmapMp 8b7c:f320:99b9:690f:4595:cd17:293a:c069 MonadPlus m => (forall d. Data d => d -> m d) -> IntMap a -> m (IntMap a) Source 
gmapMo 8b7c:f320:99b9:690f:4595:cd17:293a:c069 MonadPlus m => (forall d. Data d => d -> m d) -> IntMap a -> m (IntMap a) Source 



Ord a => Ord (IntMap a) 
 

Instance detailsDefined in Data.IntMap.Internal 
Methods
compare 8b7c:f320:99b9:690f:4595:cd17:293a:c069 IntMap a -> IntMap a -> Ordering 
(<) 8b7c:f320:99b9:690f:4595:cd17:293a:c069 IntMap a -> IntMap a -> Bool 
(<=) 8b7c:f320:99b9:690f:4595:cd17:293a:c069 IntMap a -> IntMap a -> Bool 
(>) 8b7c:f320:99b9:690f:4595:cd17:293a:c069 IntMap a -> IntMap a -> Bool 
(>=) 8b7c:f320:99b9:690f:4595:cd17:293a:c069 IntMap a -> IntMap a -> Bool 
max 8b7c:f320:99b9:690f:4595:cd17:293a:c069 IntMap a -> IntMap a -> IntMap a 
min 8b7c:f320:99b9:690f:4595:cd17:293a:c069 IntMap a -> IntMap a -> IntMap a 



Read e => Read (IntMap e) 
 

Instance detailsDefined in Data.IntMap.Internal 
Methods
readsPrec 8b7c:f320:99b9:690f:4595:cd17:293a:c069 Int -> ReadS (IntMap e) Source 
readList 8b7c:f320:99b9:690f:4595:cd17:293a:c069 ReadS [IntMap e] Source 
readPrec 8b7c:f320:99b9:690f:4595:cd17:293a:c069 ReadPrec (IntMap e) Source 
readListPrec 8b7c:f320:99b9:690f:4595:cd17:293a:c069 ReadPrec [IntMap e] Source 



Show a => Show (IntMap a) 
 

Instance detailsDefined in Data.IntMap.Internal 
Methods
showsPrec 8b7c:f320:99b9:690f:4595:cd17:293a:c069 Int -> IntMap a -> ShowS Source 
show 8b7c:f320:99b9:690f:4595:cd17:293a:c069 IntMap a -> String Source 
showList 8b7c:f320:99b9:690f:4595:cd17:293a:c069 [IntMap a] -> ShowS Source 



Semigroup (IntMap a) 
Since: containers-0.5.7

Instance detailsDefined in Data.IntMap.Internal 
Methods
(<>) 8b7c:f320:99b9:690f:4595:cd17:293a:c069 IntMap a -> IntMap a -> IntMap a Source 
sconcat 8b7c:f320:99b9:690f:4595:cd17:293a:c069 NonEmpty (IntMap a) -> IntMap a Source 
stimes 8b7c:f320:99b9:690f:4595:cd17:293a:c069 Integral b => b -> IntMap a -> IntMap a Source 



Monoid (IntMap a) 
 

Instance detailsDefined in Data.IntMap.Internal 
Methods
mempty 8b7c:f320:99b9:690f:4595:cd17:293a:c069 IntMap a Source 
mappend 8b7c:f320:99b9:690f:4595:cd17:293a:c069 IntMap a -> IntMap a -> IntMap a Source 
mconcat 8b7c:f320:99b9:690f:4595:cd17:293a:c069 [IntMap a] -> IntMap a Source 



NFData a => NFData (IntMap a) 
 

Instance detailsDefined in Data.IntMap.Internal 
Methods
rnf 8b7c:f320:99b9:690f:4595:cd17:293a:c069 IntMap a -> () Source 



 type Item (IntMap a) 
 

Instance detailsDefined in Data.IntMap.Internal type Item (IntMap a) = (Key, a)


type Key = Int Source 
Constructionempty 8b7c:f320:99b9:690f:4595:cd17:293a:c069 IntMap a Source 
O(1). The empty map.
empty      == fromList []
size empty == 0
singleton 8b7c:f320:99b9:690f:4595:cd17:293a:c069 Key -> a -> IntMap a Source 
O(1). A map of one element.
singleton 1 'a'        == fromList [(1, 'a')]
size (singleton 1 'a') == 1
fromSet 8b7c:f320:99b9:690f:4595:cd17:293a:c069 (Key -> a) -> IntSet -> IntMap a Source 
O(n). Build a map from a set of keys and a function which for each key computes its value.
fromSet (\k -> replicate k 'a') (Data.IntSet.fromList [3, 5]) == fromList [(5,"aaaaa"), (3,"aaa")]
fromSet undefined Data.IntSet.empty == empty
From Unordered ListsfromList 8b7c:f320:99b9:690f:4595:cd17:293a:c069 [(Key, a)] -> IntMap a Source 
O(n*min(n,W)). Create a map from a list of key/value pairs.
fromList [] == empty
fromList [(5,"a"), (3,"b"), (5, "c")] == fromList [(5,"c"), (3,"b")]
fromList [(5,"c"), (3,"b"), (5, "a")] == fromList [(5,"a"), (3,"b")]
fromListWith 8b7c:f320:99b9:690f:4595:cd17:293a:c069 (a -> a -> a) -> [(Key, a)] -> IntMap a Source 
O(n*min(n,W)). Create a map from a list of key/value pairs with a combining function. See also fromAscListWith.
fromListWith (++) [(5,"a"), (5,"b"), (3,"b"), (3,"a"), (5,"c")] == fromList [(3, "ab"), (5, "cba")]
fromListWith (++) [] == empty
fromListWithKey 8b7c:f320:99b9:690f:4595:cd17:293a:c069 (Key -> a -> a -> a) -> [(Key, a)] -> IntMap a Source 
O(n*min(n,W)). Build a map from a list of key/value pairs with a combining function. See also fromAscListWithKey'.
let f key new_value old_value = (show key) ++ ":" ++ new_value ++ "|" ++ old_value
fromListWithKey f [(5,"a"), (5,"b"), (3,"b"), (3,"a"), (5,"c")] == fromList [(3, "3:a|b"), (5, "5:c|5:b|a")]
fromListWithKey f [] == empty
From Ascending ListsfromAscList 8b7c:f320:99b9:690f:4595:cd17:293a:c069 [(Key, a)] -> IntMap a Source 
O(n). Build a map from a list of key/value pairs where the keys are in ascending order.
fromAscList [(3,"b"), (5,"a")]          == fromList [(3, "b"), (5, "a")]
fromAscList [(3,"b"), (5,"a"), (5,"b")] == fromList [(3, "b"), (5, "b")]
fromAscListWith 8b7c:f320:99b9:690f:4595:cd17:293a:c069 (a -> a -> a) -> [(Key, a)] -> IntMap a Source 
O(n). Build a map from a list of key/value pairs where the keys are in ascending order, with a combining function on equal keys. The precondition (input list is ascending) is not checked.
fromAscListWith (++) [(3,"b"), (5,"a"), (5,"b")] == fromList [(3, "b"), (5, "ba")]
fromAscListWithKey 8b7c:f320:99b9:690f:4595:cd17:293a:c069 (Key -> a -> a -> a) -> [(Key, a)] -> IntMap a Source 
O(n). Build a map from a list of key/value pairs where the keys are in ascending order, with a combining function on equal keys. The precondition (input list is ascending) is not checked.
let f key new_value old_value = (show key) ++ ":" ++ new_value ++ "|" ++ old_value
fromAscListWithKey f [(3,"b"), (5,"a"), (5,"b")] == fromList [(3, "b"), (5, "5:b|a")]
fromDistinctAscList 8b7c:f320:99b9:690f:4595:cd17:293a:c069 forall a. [(Key, a)] -> IntMap a Source 
O(n). Build a map from a list of key/value pairs where the keys are in ascending order and all distinct. The precondition (input list is strictly ascending) is not checked.
fromDistinctAscList [(3,"b"), (5,"a")] == fromList [(3, "b"), (5, "a")]
Insertioninsert 8b7c:f320:99b9:690f:4595:cd17:293a:c069 Key -> a -> IntMap a -> IntMap a Source 
O(min(n,W)). Insert a new key/value pair in the map. If the key is already present in the map, the associated value is replaced with the supplied value, i.e. insert is equivalent to insertWith const.
insert 5 'x' (fromList [(5,'a'), (3,'b')]) == fromList [(3, 'b'), (5, 'x')]
insert 7 'x' (fromList [(5,'a'), (3,'b')]) == fromList [(3, 'b'), (5, 'a'), (7, 'x')]
insert 5 'x' empty                         == singleton 5 'x'
insertWith 8b7c:f320:99b9:690f:4595:cd17:293a:c069 (a -> a -> a) -> Key -> a -> IntMap a -> IntMap a Source 
O(min(n,W)). Insert with a combining function. insertWith 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 f new_value old_value.
insertWith (++) 5 "xxx" (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "xxxa")]
insertWith (++) 7 "xxx" (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "a"), (7, "xxx")]
insertWith (++) 5 "xxx" empty                         == singleton 5 "xxx"
insertWithKey 8b7c:f320:99b9:690f:4595:cd17:293a:c069 (Key -> a -> a -> a) -> Key -> a -> IntMap a -> IntMap a Source 
O(min(n,W)). Insert with a combining function. insertWithKey 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 f key new_value old_value.
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")]
insertWithKey f 7 "xxx" (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "a"), (7, "xxx")]
insertWithKey f 5 "xxx" empty                         == singleton 5 "xxx"
insertLookupWithKey 8b7c:f320:99b9:690f:4595:cd17:293a:c069 (Key -> a -> a -> a) -> Key -> a -> IntMap a -> (Maybe a, IntMap a) Source 
O(min(n,W)). The expression (insertLookupWithKey f k x map) is a pair where the first element is equal to (lookup k map) and the second element equal to (insertWithKey f k x map).
let f key new_value old_value = (show key) ++ ":" ++ new_value ++ "|" ++ old_value
insertLookupWithKey f 5 "xxx" (fromList [(5,"a"), (3,"b")]) == (Just "a", fromList [(3, "b"), (5, "5:xxx|a")])
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:
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")])
insertLookup 7 "x" (fromList [(5,"a"), (3,"b")]) == (Nothing,  fromList [(3, "b"), (5, "a"), (7, "x")])
Deletion/Updatedelete 8b7c:f320:99b9:690f:4595:cd17:293a:c069 Key -> IntMap a -> IntMap a Source 
O(min(n,W)). Delete a key and its value from the map. When the key is not a member of the map, the original map is returned.
delete 5 (fromList [(5,"a"), (3,"b")]) == singleton 3 "b"
delete 7 (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "a")]
delete 5 empty                         == empty
adjust 8b7c:f320:99b9:690f:4595:cd17:293a:c069 (a -> a) -> Key -> IntMap a -> IntMap a Source 
O(min(n,W)). Adjust a value at a specific key. When the key is not a member of the map, the original map is returned.
adjust ("new " ++) 5 (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "new a")]
adjust ("new " ++) 7 (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "a")]
adjust ("new " ++) 7 empty                         == empty
adjustWithKey 8b7c:f320:99b9:690f:4595:cd17:293a:c069 (Key -> a -> a) -> Key -> IntMap a -> IntMap a Source 
O(min(n,W)). Adjust a value at a specific key. When the key is not a member of the map, the original map is returned.
let f key x = (show key) ++ ":new " ++ x
adjustWithKey f 5 (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "5:new a")]
adjustWithKey f 7 (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "a")]
adjustWithKey f 7 empty                         == empty
update 8b7c:f320:99b9:690f:4595:cd17:293a:c069 (a -> Maybe a) -> Key -> IntMap a -> IntMap a Source 
O(min(n,W)). The expression (update f k map) updates the value x at k (if it is in the map). If (f x) is Nothing, the element is deleted. If it is (Just y), the key k is bound to the new value y.
let f x = if x == "a" then Just "new a" else Nothing
update f 5 (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "new a")]
update f 7 (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "a")]
update f 3 (fromList [(5,"a"), (3,"b")]) == singleton 5 "a"
updateWithKey 8b7c:f320:99b9:690f:4595:cd17:293a:c069 (Key -> a -> Maybe a) -> Key -> IntMap a -> IntMap a Source 
O(min(n,W)). The expression (update f k map) updates the value x at k (if it is in the map). If (f k x) is Nothing, the element is deleted. If it is (Just y), the key k is bound to the new value y.
let f k x = if x == "a" then Just ((show k) ++ ":new a") else Nothing
updateWithKey f 5 (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "5:new a")]
updateWithKey f 7 (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "a")]
updateWithKey f 3 (fromList [(5,"a"), (3,"b")]) == singleton 5 "a"
updateLookupWithKey 8b7c:f320:99b9:690f:4595:cd17:293a:c069 (Key -> a -> Maybe a) -> Key -> IntMap a -> (Maybe a, IntMap a) Source 
O(min(n,W)). Lookup and update. The function returns original value, if it is updated. This is different behavior than updateLookupWithKey. Returns the original key value if the map entry is deleted.
let f k x = if x == "a" then Just ((show k) ++ ":new a") else Nothing
updateLookupWithKey f 5 (fromList [(5,"a"), (3,"b")]) == (Just "a", fromList [(3, "b"), (5, "5:new a")])
updateLookupWithKey f 7 (fromList [(5,"a"), (3,"b")]) == (Nothing,  fromList [(3, "b"), (5, "a")])
updateLookupWithKey f 3 (fromList [(5,"a"), (3,"b")]) == (Just "b", singleton 5 "a")
alter 8b7c:f320:99b9:690f:4595:cd17:293a:c069 (Maybe a -> Maybe a) -> Key -> IntMap a -> IntMap a Source 
O(min(n,W)). The expression (alter f k map) alters the value x at k, or absence thereof. alter can be used to insert, delete, or update a value in an IntMap. In short : lookup k (alter f k m) = f (lookup k m).
alterF 8b7c:f320:99b9:690f:4595:cd17:293a:c069 Functor f => (Maybe a -> f (Maybe a)) -> Key -> IntMap a -> f (IntMap a) Source 
O(log n). The expression (alterF f k map) alters the value x at k, or absence thereof. alterF can be used to inspect, insert, delete, or update a value in an IntMap. In short : lookup k $ alterF f k m = f
 (lookup k m).
Example:
interactiveAlter 8b7c:f320:99b9:690f:4595:cd17:293a:c069 Int -> IntMap String -> IO (IntMap String)
interactiveAlter k m = alterF f k m where
  f Nothing = do
     putStrLn $ show k ++
         " was not found in the map. Would you like to add it?"
     getUserResponse1 8b7c:f320:99b9:690f:4595:cd17:293a:c069 IO (Maybe String)
  f (Just old) = do
     putStrLn $ "The key is currently bound to " ++ show old ++
         ". Would you like to change or delete it?"
     getUserResponse2 8b7c:f320:99b9:690f:4595:cd17:293a:c069 IO (Maybe String)

alterF is the most general operation for working with an individual key that may or may not be in a given map.
Note: alterF is a flipped version of the at combinator from Control.Lens.At.
Since: containers-0.5.8
QueryLookuplookup 8b7c:f320:99b9:690f:4595:cd17:293a:c069 Key -> IntMap a -> Maybe a Source 
O(min(n,W)). Lookup the value at a key in the map. See also lookup.
(!?) 8b7c:f320:99b9:690f:4595:cd17:293a:c069 IntMap a -> Key -> Maybe a infixl 9 Source 
O(min(n,W)). Find the value at a key. Returns Nothing when the element can not be found.
fromList [(5,'a'), (3,'b')] !? 1 == Nothing
fromList [(5,'a'), (3,'b')] !? 5 == Just 'a'
Since: containers-0.5.11
(!) 8b7c:f320:99b9:690f:4595:cd17:293a:c069 IntMap a -> Key -> a Source 
O(min(n,W)). Find the value at a key. Calls error when the element can not be found.
fromList [(5,'a'), (3,'b')] ! 1    Error: element not in the map
fromList [(5,'a'), (3,'b')] ! 5 == 'a'
findWithDefault 8b7c:f320:99b9:690f:4595:cd17:293a:c069 a -> Key -> IntMap a -> a Source 
O(min(n,W)). The expression (findWithDefault def k map) returns the value at key k or returns def when the key is not an element of the map.
findWithDefault 'x' 1 (fromList [(5,'a'), (3,'b')]) == 'x'
findWithDefault 'x' 5 (fromList [(5,'a'), (3,'b')]) == 'a'
member 8b7c:f320:99b9:690f:4595:cd17:293a:c069 Key -> IntMap a -> Bool Source 
O(min(n,W)). Is the key a member of the map?
member 5 (fromList [(5,'a'), (3,'b')]) == True
member 1 (fromList [(5,'a'), (3,'b')]) == False
notMember 8b7c:f320:99b9:690f:4595:cd17:293a:c069 Key -> IntMap a -> Bool Source 
O(min(n,W)). Is the key not a member of the map?
notMember 5 (fromList [(5,'a'), (3,'b')]) == False
notMember 1 (fromList [(5,'a'), (3,'b')]) == True
lookupLT 8b7c:f320:99b9:690f:4595:cd17:293a:c069 Key -> IntMap a -> Maybe (Key, a) Source 
O(log n). Find largest key smaller than the given one and return the corresponding (key, value) pair.
lookupLT 3 (fromList [(3,'a'), (5,'b')]) == Nothing
lookupLT 4 (fromList [(3,'a'), (5,'b')]) == Just (3, 'a')
lookupGT 8b7c:f320:99b9:690f:4595:cd17:293a:c069 Key -> IntMap a -> Maybe (Key, a) Source 
O(log n). Find smallest key greater than the given one and return the corresponding (key, value) pair.
lookupGT 4 (fromList [(3,'a'), (5,'b')]) == Just (5, 'b')
lookupGT 5 (fromList [(3,'a'), (5,'b')]) == Nothing
lookupLE 8b7c:f320:99b9:690f:4595:cd17:293a:c069 Key -> IntMap a -> Maybe (Key, a) Source 
O(log n). Find largest key smaller or equal to the given one and return the corresponding (key, value) pair.
lookupLE 2 (fromList [(3,'a'), (5,'b')]) == Nothing
lookupLE 4 (fromList [(3,'a'), (5,'b')]) == Just (3, 'a')
lookupLE 5 (fromList [(3,'a'), (5,'b')]) == Just (5, 'b')
lookupGE 8b7c:f320:99b9:690f:4595:cd17:293a:c069 Key -> IntMap a -> Maybe (Key, a) Source 
O(log n). Find smallest key greater or equal to the given one and return the corresponding (key, value) pair.
lookupGE 3 (fromList [(3,'a'), (5,'b')]) == Just (3, 'a')
lookupGE 4 (fromList [(3,'a'), (5,'b')]) == Just (5, 'b')
lookupGE 6 (fromList [(3,'a'), (5,'b')]) == Nothing
Sizenull 8b7c:f320:99b9:690f:4595:cd17:293a:c069 IntMap a -> Bool Source 
O(1). Is the map empty?
Data.IntMap.null (empty)           == True
Data.IntMap.null (singleton 1 'a') == False
size 8b7c:f320:99b9:690f:4595:cd17:293a:c069 IntMap a -> Int Source 
O(n). Number of elements in the map.
size empty                                   == 0
size (singleton 1 'a')                       == 1
size (fromList([(1,'a'), (2,'c'), (3,'b')])) == 3
CombineUnionunion 8b7c:f320:99b9:690f:4595:cd17:293a:c069 IntMap a -> IntMap a -> IntMap a Source 
O(n+m). The (left-biased) union of two maps. It prefers the first map when duplicate keys are encountered, i.e. (union == unionWith const).
union (fromList [(5, "a"), (3, "b")]) (fromList [(5, "A"), (7, "C")]) == fromList [(3, "b"), (5, "a"), (7, "C")]
unionWith 8b7c:f320:99b9:690f:4595:cd17:293a:c069 (a -> a -> a) -> IntMap a -> IntMap a -> IntMap a Source 
O(n+m). The union with a combining function.
unionWith (++) (fromList [(5, "a"), (3, "b")]) (fromList [(5, "A"), (7, "C")]) == fromList [(3, "b"), (5, "aA"), (7, "C")]
unionWithKey 8b7c:f320:99b9:690f:4595:cd17:293a:c069 (Key -> a -> a -> a) -> IntMap a -> IntMap a -> IntMap a Source 
O(n+m). The union with a combining function.
let f key left_value right_value = (show key) ++ ":" ++ left_value ++ "|" ++ right_value
unionWithKey f (fromList [(5, "a"), (3, "b")]) (fromList [(5, "A"), (7, "C")]) == fromList [(3, "b"), (5, "5:a|A"), (7, "C")]
unions 8b7c:f320:99b9:690f:4595:cd17:293a:c069 Foldable f => f (IntMap a) -> IntMap a Source 
The union of a list of maps.
unions [(fromList [(5, "a"), (3, "b")]), (fromList [(5, "A"), (7, "C")]), (fromList [(5, "A3"), (3, "B3")])]
    == fromList [(3, "b"), (5, "a"), (7, "C")]
unions [(fromList [(5, "A3"), (3, "B3")]), (fromList [(5, "A"), (7, "C")]), (fromList [(5, "a"), (3, "b")])]
    == fromList [(3, "B3"), (5, "A3"), (7, "C")]
unionsWith 8b7c:f320:99b9:690f:4595:cd17:293a:c069 Foldable f => (a -> a -> a) -> f (IntMap a) -> IntMap a Source 
The union of a list of maps, with a combining operation.
unionsWith (++) [(fromList [(5, "a"), (3, "b")]), (fromList [(5, "A"), (7, "C")]), (fromList [(5, "A3"), (3, "B3")])]
    == fromList [(3, "bB3"), (5, "aAA3"), (7, "C")]
Differencedifference 8b7c:f320:99b9:690f:4595:cd17:293a:c069 IntMap a -> IntMap b -> IntMap a Source 
O(n+m). Difference between two maps (based on keys).
difference (fromList [(5, "a"), (3, "b")]) (fromList [(5, "A"), (7, "C")]) == singleton 3 "b"
(\\) 8b7c:f320:99b9:690f:4595:cd17:293a:c069 IntMap a -> IntMap b -> IntMap a infixl 9 Source 
Same as difference.
differenceWith 8b7c:f320:99b9:690f:4595:cd17:293a:c069 (a -> b -> Maybe a) -> IntMap a -> IntMap b -> IntMap a Source 
O(n+m). Difference with a combining function.
let f al ar = if al == "b" then Just (al ++ ":" ++ ar) else Nothing
differenceWith f (fromList [(5, "a"), (3, "b")]) (fromList [(5, "A"), (3, "B"), (7, "C")])
    == singleton 3 "b:B"
differenceWithKey 8b7c:f320:99b9:690f:4595:cd17:293a:c069 (Key -> a -> b -> Maybe a) -> IntMap a -> IntMap b -> IntMap a Source 
O(n+m). Difference with a combining function. When two equal keys are encountered, the combining function is applied to the key and both values. If it returns Nothing, the element is discarded (proper set difference). If it returns (Just y), the element is updated with a new value y.
let f k al ar = if al == "b" then Just ((show k) ++ ":" ++ al ++ "|" ++ ar) else Nothing
differenceWithKey f (fromList [(5, "a"), (3, "b")]) (fromList [(5, "A"), (3, "B"), (10, "C")])
    == singleton 3 "3:b|B"
Intersectionintersection 8b7c:f320:99b9:690f:4595:cd17:293a:c069 IntMap a -> IntMap b -> IntMap a Source 
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"
intersectionWith 8b7c:f320:99b9:690f:4595:cd17:293a:c069 (a -> b -> c) -> IntMap a -> IntMap b -> IntMap c Source 
O(n+m). The intersection with a combining function.
intersectionWith (++) (fromList [(5, "a"), (3, "b")]) (fromList [(5, "A"), (7, "C")]) == singleton 5 "aA"
intersectionWithKey 8b7c:f320:99b9:690f:4595:cd17:293a:c069 (Key -> a -> b -> c) -> IntMap a -> IntMap b -> IntMap c Source 
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"
Disjointdisjoint 8b7c:f320:99b9:690f:4595:cd17:293a:c069 IntMap a -> IntMap b -> Bool Source 
O(n+m). Check whether the key sets of two maps are disjoint (i.e. their intersection is empty).
disjoint (fromList [(2,'a')]) (fromList [(1,()), (3,())])   == True
disjoint (fromList [(2,'a')]) (fromList [(1,'a'), (2,'b')]) == False
disjoint (fromList [])        (fromList [])                 == True
disjoint a b == null (intersection a b)
Since: containers-937.896.6674
Universal combining functionmergeWithKey 8b7c:f320:99b9:690f:4595:cd17:293a:c069 (Key -> a -> b -> Maybe c) -> (IntMap a -> IntMap c) -> (IntMap b -> IntMap c) -> IntMap a -> IntMap b -> IntMap c Source 
O(n+m). A high-performance universal combining function. Using mergeWithKey, all combining functions can be defined without any loss of efficiency (with exception of union, difference and intersection, where sharing of some nodes is lost with mergeWithKey).
Please make sure you know what is going on when using mergeWithKey, otherwise you can be surprised by unexpected code growth or even corruption of the data structure.
When mergeWithKey is given three arguments, it is inlined to the call site. You should therefore use mergeWithKey only to define your custom combining functions. For example, you could define unionWithKey, differenceWithKey and intersectionWithKey as
myUnionWithKey f m1 m2 = mergeWithKey (\k x1 x2 -> Just (f k x1 x2)) id id m1 m2
myDifferenceWithKey f m1 m2 = mergeWithKey f id (const empty) m1 m2
myIntersectionWithKey f m1 m2 = mergeWithKey (\k x1 x2 -> Just (f k x1 x2)) (const empty) (const empty) m1 m2
When calling mergeWithKey combine only1 only2, a function combining two IntMaps is created, such that

if a key is present in both maps, it is passed with both corresponding values to the combine function. Depending on the result, the key is either present in the result with specified value, or is left out;
a nonempty subtree present only in the first map is passed to only1 and the output is added to the result;
a nonempty subtree present only in the second map is passed to only2 and the output is added to the result.

The only1 and only2 methods must return a map with a subset (possibly empty) of the keys of the given map. The values can be modified arbitrarily. Most common variants of only1 and only2 are id and const empty, but for example map f or filterWithKey f could be used for any f.
TraversalMapmap 8b7c:f320:99b9:690f:4595:cd17:293a:c069 (a -> b) -> IntMap a -> IntMap b Source 
O(n). Map a function over all values in the map.
map (++ "x") (fromList [(5,"a"), (3,"b")]) == fromList [(3, "bx"), (5, "ax")]
mapWithKey 8b7c:f320:99b9:690f:4595:cd17:293a:c069 (Key -> a -> b) -> IntMap a -> IntMap b Source 
O(n). Map a function over all values in the map.
let f key x = (show key) ++ ":" ++ x
mapWithKey f (fromList [(5,"a"), (3,"b")]) == fromList [(3, "3:b"), (5, "5:a")]
traverseWithKey 8b7c:f320:99b9:690f:4595:cd17:293a:c069 Applicative t => (Key -> a -> t b) -> IntMap a -> t (IntMap b) Source 
O(n). traverseWithKey f s == fromList $ traverse ((k, v) -> (,) k $ f k v) (toList m) That is, behaves exactly like a regular traverse except that the traversing function also has access to the key associated with a value.
traverseWithKey (\k v -> if odd k then Just (succ v) else Nothing) (fromList [(1, 'a'), (5, 'e')]) == Just (fromList [(1, 'b'), (5, 'f')])
traverseWithKey (\k v -> if odd k then Just (succ v) else Nothing) (fromList [(2, 'c')])           == Nothing
mapAccum 8b7c:f320:99b9:690f:4595:cd17:293a:c069 (a -> b -> (a, c)) -> a -> IntMap b -> (a, IntMap c) Source 
O(n). The function mapAccum threads an accumulating argument through the map in ascending order of keys.
let f a b = (a ++ b, b ++ "X")
mapAccum f "Everything: " (fromList [(5,"a"), (3,"b")]) == ("Everything: ba", fromList [(3, "bX"), (5, "aX")])
mapAccumWithKey 8b7c:f320:99b9:690f:4595:cd17:293a:c069 (a -> Key -> b -> (a, c)) -> a -> IntMap b -> (a, IntMap c) Source 
O(n). The function mapAccumWithKey threads an accumulating argument through the map in ascending order of keys.
let f a k b = (a ++ " " ++ (show k) ++ "-" ++ b, b ++ "X")
mapAccumWithKey f "Everything:" (fromList [(5,"a"), (3,"b")]) == ("Everything: 3-b 5-a", fromList [(3, "bX"), (5, "aX")])
mapAccumRWithKey 8b7c:f320:99b9:690f:4595:cd17:293a:c069 (a -> Key -> b -> (a, c)) -> a -> IntMap b -> (a, IntMap c) Source 
O(n). The function mapAccumR threads an accumulating argument through the map in descending order of keys.
mapKeys 8b7c:f320:99b9:690f:4595:cd17:293a:c069 (Key -> Key) -> IntMap a -> IntMap a Source 
O(n*min(n,W)). mapKeys 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 keys to the same new key. In this case the value at the greatest of the original keys is retained.
mapKeys (+ 1) (fromList [(5,"a"), (3,"b")])                        == fromList [(4, "b"), (6, "a")]
mapKeys (\ _ -> 1) (fromList [(1,"b"), (2,"a"), (3,"d"), (4,"c")]) == singleton 1 "c"
mapKeys (\ _ -> 3) (fromList [(1,"b"), (2,"a"), (3,"d"), (4,"c")]) == singleton 3 "c"
mapKeysWith 8b7c:f320:99b9:690f:4595:cd17:293a:c069 (a -> a -> a) -> (Key -> Key) -> IntMap a -> IntMap a Source 
O(n*min(n,W)). mapKeysWith 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 keys to the same new key. In this case the associated values will be combined using c.
mapKeysWith (++) (\ _ -> 1) (fromList [(1,"b"), (2,"a"), (3,"d"), (4,"c")]) == singleton 1 "cdab"
mapKeysWith (++) (\ _ -> 3) (fromList [(1,"b"), (2,"a"), (3,"d"), (4,"c")]) == singleton 3 "cdab"
mapKeysMonotonic 8b7c:f320:99b9:690f:4595:cd17:293a:c069 (Key -> Key) -> IntMap a -> IntMap a Source 
O(n*min(n,W)). mapKeysMonotonic f s == mapKeys 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 f maps distinct original keys to distinct resulting keys. This function has slightly better performance than mapKeys.
mapKeysMonotonic (\ k -> k * 2) (fromList [(5,"a"), (3,"b")]) == fromList [(6, "b"), (10, "a")]
Foldsfoldr 8b7c:f320:99b9:690f:4595:cd17:293a:c069 (a -> b -> b) -> b -> IntMap a -> b Source 
O(n). Fold the values in the map using the given right-associative binary operator, such that foldr f z == foldr f z . elems.
For example,
elems map = foldr (:) [] map
let f a len = len + (length a)
foldr f 0 (fromList [(5,"a"), (3,"bbb")]) == 4
foldl 8b7c:f320:99b9:690f:4595:cd17:293a:c069 (a -> b -> a) -> a -> IntMap b -> a Source 
O(n). Fold the values in the map using the given left-associative binary operator, such that foldl f z == foldl f z . elems.
For example,
elems = reverse . foldl (flip (:)) []
let f len a = len + (length a)
foldl f 0 (fromList [(5,"a"), (3,"bbb")]) == 4
foldrWithKey 8b7c:f320:99b9:690f:4595:cd17:293a:c069 (Key -> a -> b -> b) -> b -> IntMap a -> b Source 
O(n). Fold the keys and values in the map using the given right-associative binary operator, such that foldrWithKey f z == foldr (uncurry f) z . toAscList.
For example,
keys map = foldrWithKey (\k x ks -> k:ks) [] map
let f k a result = result ++ "(" ++ (show k) ++ ":" ++ a ++ ")"
foldrWithKey f "Map: " (fromList [(5,"a"), (3,"b")]) == "Map: (5:a)(3:b)"
foldlWithKey 8b7c:f320:99b9:690f:4595:cd17:293a:c069 (a -> Key -> b -> a) -> a -> IntMap b -> a Source 
O(n). Fold the keys and values in the map using the given left-associative binary operator, such that foldlWithKey f z == foldl (\z' (kx, x) -> f z' kx x) z . toAscList.
For example,
keys = reverse . foldlWithKey (\ks k x -> k:ks) []
let f result k a = result ++ "(" ++ (show k) ++ ":" ++ a ++ ")"
foldlWithKey f "Map: " (fromList [(5,"a"), (3,"b")]) == "Map: (3:b)(5:a)"
foldMapWithKey 8b7c:f320:99b9:690f:4595:cd17:293a:c069 Monoid m => (Key -> a -> m) -> IntMap a -> m Source 
O(n). Fold the keys and values in the map using the given monoid, such that
foldMapWithKey f = fold . mapWithKey f
This can be an asymptotically faster than foldrWithKey or foldlWithKey for some monoids.
Since: containers-0.5.4
Strict foldsfoldr' 8b7c:f320:99b9:690f:4595:cd17:293a:c069 (a -> b -> b) -> b -> IntMap a -> b Source 
O(n). A strict version of foldr. Each application of the operator is evaluated before using the result in the next application. This function is strict in the starting value.
foldl' 8b7c:f320:99b9:690f:4595:cd17:293a:c069 (a -> b -> a) -> a -> IntMap b -> a Source 
O(n). A strict version of foldl. Each application of the operator is evaluated before using the result in the next application. This function is strict in the starting value.
foldrWithKey' 8b7c:f320:99b9:690f:4595:cd17:293a:c069 (Key -> a -> b -> b) -> b -> IntMap a -> b Source 
O(n). A strict version of foldrWithKey. Each application of the operator is evaluated before using the result in the next application. This function is strict in the starting value.
foldlWithKey' 8b7c:f320:99b9:690f:4595:cd17:293a:c069 (a -> Key -> b -> a) -> a -> IntMap b -> a Source 
O(n). A strict version of foldlWithKey. Each application of the operator is evaluated before using the result in the next application. This function is strict in the starting value.
Conversionelems 8b7c:f320:99b9:690f:4595:cd17:293a:c069 IntMap a -> [a] Source 
O(n). Return all elements of the map in the ascending order of their keys. Subject to list fusion.
elems (fromList [(5,"a"), (3,"b")]) == ["b","a"]
elems empty == []
keys 8b7c:f320:99b9:690f:4595:cd17:293a:c069 IntMap a -> [Key] Source 
O(n). Return all keys of the map in ascending order. Subject to list fusion.
keys (fromList [(5,"a"), (3,"b")]) == [3,5]
keys empty == []
assocs 8b7c:f320:99b9:690f:4595:cd17:293a:c069 IntMap a -> [(Key, a)] Source 
O(n). An alias for toAscList. Returns all key/value pairs in the map in ascending key order. Subject to list fusion.
assocs (fromList [(5,"a"), (3,"b")]) == [(3,"b"), (5,"a")]
assocs empty == []
keysSet 8b7c:f320:99b9:690f:4595:cd17:293a:c069 IntMap a -> IntSet Source 
O(n*min(n,W)). The set of all keys of the map.
keysSet (fromList [(5,"a"), (3,"b")]) == Data.IntSet.fromList [3,5]
keysSet empty == Data.IntSet.empty
ListstoList 8b7c:f320:99b9:690f:4595:cd17:293a:c069 IntMap a -> [(Key, a)] Source 
O(n). Convert the map to a list of key/value pairs. Subject to list fusion.
toList (fromList [(5,"a"), (3,"b")]) == [(3,"b"), (5,"a")]
toList empty == []
Ordered liststoAscList 8b7c:f320:99b9:690f:4595:cd17:293a:c069 IntMap a -> [(Key, a)] Source 
O(n). Convert the map to a list of key/value pairs where the keys are in ascending order. Subject to list fusion.
toAscList (fromList [(5,"a"), (3,"b")]) == [(3,"b"), (5,"a")]
toDescList 8b7c:f320:99b9:690f:4595:cd17:293a:c069 IntMap a -> [(Key, a)] Source 
O(n). Convert the map to a list of key/value pairs where the keys are in descending order. Subject to list fusion.
toDescList (fromList [(5,"a"), (3,"b")]) == [(5,"a"), (3,"b")]
Filterfilter 8b7c:f320:99b9:690f:4595:cd17:293a:c069 (a -> Bool) -> IntMap a -> IntMap a Source 
O(n). Filter all values that satisfy some predicate.
filter (> "a") (fromList [(5,"a"), (3,"b")]) == singleton 3 "b"
filter (> "x") (fromList [(5,"a"), (3,"b")]) == empty
filter (< "a") (fromList [(5,"a"), (3,"b")]) == empty
filterWithKey 8b7c:f320:99b9:690f:4595:cd17:293a:c069 (Key -> a -> Bool) -> IntMap a -> IntMap a Source 
O(n). Filter all keys/values that satisfy some predicate.
filterWithKey (\k _ -> k > 4) (fromList [(5,"a"), (3,"b")]) == singleton 5 "a"
restrictKeys 8b7c:f320:99b9:690f:4595:cd17:293a:c069 IntMap a -> IntSet -> IntMap a Source 
O(n+m). The restriction of a map to the keys in a set.
m `restrictKeys` s = filterWithKey (k _ -> k `member` s) m

Since: containers-0.5.8
withoutKeys 8b7c:f320:99b9:690f:4595:cd17:293a:c069 IntMap a -> IntSet -> IntMap a Source 
O(n+m). Remove all the keys in a given set from a map.
m `withoutKeys` s = filterWithKey (k _ -> k `notMember` s) m

Since: containers-0.5.8
partition 8b7c:f320:99b9:690f:4595:cd17:293a:c069 (a -> Bool) -> IntMap a -> (IntMap a, IntMap a) Source 
O(n). Partition the map according to some predicate. The first map contains all elements that satisfy the predicate, the second all elements that fail the predicate. See also split.
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")])
partitionWithKey 8b7c:f320:99b9:690f:4595:cd17:293a:c069 (Key -> a -> Bool) -> IntMap a -> (IntMap a, IntMap a) Source 
O(n). Partition the map according to some predicate. The first map contains all elements that satisfy the predicate, the second all elements that fail the predicate. See also split.
partitionWithKey (\ k _ -> k > 3) (fromList [(5,"a"), (3,"b")]) == (singleton 5 "a", singleton 3 "b")
partitionWithKey (\ k _ -> k < 7) (fromList [(5,"a"), (3,"b")]) == (fromList [(3, "b"), (5, "a")], empty)
partitionWithKey (\ k _ -> k > 7) (fromList [(5,"a"), (3,"b")]) == (empty, fromList [(3, "b"), (5, "a")])
mapMaybe 8b7c:f320:99b9:690f:4595:cd17:293a:c069 (a -> Maybe b) -> IntMap a -> IntMap b Source 
O(n). Map values and collect the Just results.
let f x = if x == "a" then Just "new a" else Nothing
mapMaybe f (fromList [(5,"a"), (3,"b")]) == singleton 5 "new a"
mapMaybeWithKey 8b7c:f320:99b9:690f:4595:cd17:293a:c069 (Key -> a -> Maybe b) -> IntMap a -> IntMap b Source 
O(n). Map keys/values and collect the Just results.
let f k _ = if k < 5 then Just ("key : " ++ (show k)) else Nothing
mapMaybeWithKey f (fromList [(5,"a"), (3,"b")]) == singleton 3 "key : 3"
mapEither 8b7c:f320:99b9:690f:4595:cd17:293a:c069 (a -> Either b c) -> IntMap a -> (IntMap b, IntMap c) Source 
O(n). Map values and separate the Left and Right results.
let f a = if a < "c" then Left a else Right a
mapEither f (fromList [(5,"a"), (3,"b"), (1,"x"), (7,"z")])
    == (fromList [(3,"b"), (5,"a")], fromList [(1,"x"), (7,"z")])

mapEither (\ a -> Right a) (fromList [(5,"a"), (3,"b"), (1,"x"), (7,"z")])
    == (empty, fromList [(5,"a"), (3,"b"), (1,"x"), (7,"z")])
mapEitherWithKey 8b7c:f320:99b9:690f:4595:cd17:293a:c069 (Key -> a -> Either b c) -> IntMap a -> (IntMap b, IntMap c) Source 
O(n). Map keys/values and separate the Left and Right results.
let f k a = if k < 5 then Left (k * 2) else Right (a ++ a)
mapEitherWithKey f (fromList [(5,"a"), (3,"b"), (1,"x"), (7,"z")])
    == (fromList [(1,2), (3,6)], fromList [(5,"aa"), (7,"zz")])

mapEitherWithKey (\_ a -> Right a) (fromList [(5,"a"), (3,"b"), (1,"x"), (7,"z")])
    == (empty, fromList [(1,"x"), (3,"b"), (5,"a"), (7,"z")])
split 8b7c:f320:99b9:690f:4595:cd17:293a:c069 Key -> IntMap a -> (IntMap a, IntMap a) Source 
O(min(n,W)). The expression (split k map) is a pair (map1,map2) where all keys in map1 are lower than k and all keys in map2 larger than k. Any key equal to k is found in neither map1 nor map2.
split 2 (fromList [(5,"a"), (3,"b")]) == (empty, fromList [(3,"b"), (5,"a")])
split 3 (fromList [(5,"a"), (3,"b")]) == (empty, singleton 5 "a")
split 4 (fromList [(5,"a"), (3,"b")]) == (singleton 3 "b", singleton 5 "a")
split 5 (fromList [(5,"a"), (3,"b")]) == (singleton 3 "b", empty)
split 6 (fromList [(5,"a"), (3,"b")]) == (fromList [(3,"b"), (5,"a")], empty)
splitLookup 8b7c:f320:99b9:690f:4595:cd17:293a:c069 Key -> IntMap a -> (IntMap a, Maybe a, IntMap a) Source 
O(min(n,W)). Performs a split but also returns whether the pivot key was found in the original map.
splitLookup 2 (fromList [(5,"a"), (3,"b")]) == (empty, Nothing, fromList [(3,"b"), (5,"a")])
splitLookup 3 (fromList [(5,"a"), (3,"b")]) == (empty, Just "b", singleton 5 "a")
splitLookup 4 (fromList [(5,"a"), (3,"b")]) == (singleton 3 "b", Nothing, singleton 5 "a")
splitLookup 5 (fromList [(5,"a"), (3,"b")]) == (singleton 3 "b", Just "a", empty)
splitLookup 6 (fromList [(5,"a"), (3,"b")]) == (fromList [(3,"b"), (5,"a")], Nothing, empty)
splitRoot 8b7c:f320:99b9:690f:4595:cd17:293a:c069 IntMap a -> [IntMap a] Source 
O(1). Decompose a map into pieces based on the structure of the underlying tree. This function is useful for consuming a map in parallel.
No guarantee is made as to the sizes of the pieces; an internal, but deterministic process determines this. However, it is guaranteed that the pieces returned will be in ascending order (all elements in the first submap less than all elements in the second, and so on).
Examples:
splitRoot (fromList (zip [1..8b7c:f320:99b9:690f:4595:cd17:293a:c069Int] ['a'..])) ==
  [fromList [(1,'a'),(2,'b'),(3,'c')],fromList [(4,'d'),(5,'e'),(6,'f')]]
splitRoot empty == []
Note that the current implementation does not return more than two submaps, but you should not depend on this behaviour because it can change in the future without notice.
SubmapisSubmapOf 8b7c:f320:99b9:690f:4595:cd17:293a:c069 Eq a => IntMap a -> IntMap a -> Bool Source 
O(n+m). Is this a submap? Defined as (isSubmapOf = isSubmapOfBy (==)).
isSubmapOfBy 8b7c:f320:99b9:690f:4595:cd17:293a:c069 (a -> b -> Bool) -> IntMap a -> IntMap b -> Bool Source 
O(n+m). The expression (isSubmapOfBy f m1 m2) returns True if all keys in m1 are in m2, and when f returns True when applied to their respective values. For example, the following expressions are all True:
isSubmapOfBy (==) (fromList [(1,1)]) (fromList [(1,1),(2,2)])
isSubmapOfBy (<=) (fromList [(1,1)]) (fromList [(1,1),(2,2)])
isSubmapOfBy (==) (fromList [(1,1),(2,2)]) (fromList [(1,1),(2,2)])
But the following are all False:
isSubmapOfBy (==) (fromList [(1,2)]) (fromList [(1,1),(2,2)])
isSubmapOfBy (<) (fromList [(1,1)]) (fromList [(1,1),(2,2)])
isSubmapOfBy (==) (fromList [(1,1),(2,2)]) (fromList [(1,1)])
isProperSubmapOf 8b7c:f320:99b9:690f:4595:cd17:293a:c069 Eq a => IntMap a -> IntMap a -> Bool Source 
O(n+m). Is this a proper submap? (ie. a submap but not equal). Defined as (isProperSubmapOf = isProperSubmapOfBy (==)).
isProperSubmapOfBy 8b7c:f320:99b9:690f:4595:cd17:293a:c069 (a -> b -> Bool) -> IntMap a -> IntMap b -> Bool Source 
O(n+m). Is this a proper submap? (ie. a submap but not equal). The expression (isProperSubmapOfBy f m1 m2) returns True when m1 and m2 are not equal, all keys in m1 are in m2, and when f returns True when applied to their respective values. For example, the following expressions are all True:
isProperSubmapOfBy (==) (fromList [(1,1)]) (fromList [(1,1),(2,2)])
isProperSubmapOfBy (<=) (fromList [(1,1)]) (fromList [(1,1),(2,2)])
But the following are all False:
isProperSubmapOfBy (==) (fromList [(1,1),(2,2)]) (fromList [(1,1),(2,2)])
isProperSubmapOfBy (==) (fromList [(1,1),(2,2)]) (fromList [(1,1)])
isProperSubmapOfBy (<)  (fromList [(1,1)])       (fromList [(1,1),(2,2)])
Min/MaxlookupMin 8b7c:f320:99b9:690f:4595:cd17:293a:c069 IntMap a -> Maybe (Key, a) Source 
O(min(n,W)). The minimal key of the map. Returns Nothing if the map is empty.
lookupMax 8b7c:f320:99b9:690f:4595:cd17:293a:c069 IntMap a -> Maybe (Key, a) Source 
O(min(n,W)). The maximal key of the map. Returns Nothing if the map is empty.
findMin 8b7c:f320:99b9:690f:4595:cd17:293a:c069 IntMap a -> (Key, a) Source 
O(min(n,W)). The minimal key of the map. Calls error if the map is empty. Use minViewWithKey if the map may be empty.
findMax 8b7c:f320:99b9:690f:4595:cd17:293a:c069 IntMap a -> (Key, a) Source 
O(min(n,W)). The maximal key of the map. Calls error if the map is empty. Use maxViewWithKey if the map may be empty.
deleteMin 8b7c:f320:99b9:690f:4595:cd17:293a:c069 IntMap a -> IntMap a Source 
O(min(n,W)). Delete the minimal key. Returns an empty map if the map is empty.
Note that this is a change of behaviour for consistency with Map – versions prior to 0.5 threw an error if the IntMap was already empty.
deleteMax 8b7c:f320:99b9:690f:4595:cd17:293a:c069 IntMap a -> IntMap a Source 
O(min(n,W)). Delete the maximal key. Returns an empty map if the map is empty.
Note that this is a change of behaviour for consistency with Map – versions prior to 0.5 threw an error if the IntMap was already empty.
deleteFindMin 8b7c:f320:99b9:690f:4595:cd17:293a:c069 IntMap a -> ((Key, a), IntMap a) Source 
O(min(n,W)). Delete and find the minimal element. This function throws an error if the map is empty. Use minViewWithKey if the map may be empty.
deleteFindMax 8b7c:f320:99b9:690f:4595:cd17:293a:c069 IntMap a -> ((Key, a), IntMap a) Source 
O(min(n,W)). Delete and find the maximal element. This function throws an error if the map is empty. Use maxViewWithKey if the map may be empty.
updateMin 8b7c:f320:99b9:690f:4595:cd17:293a:c069 (a -> Maybe a) -> IntMap a -> IntMap a Source 
O(min(n,W)). Update the value at the minimal key.
updateMin (\ a -> Just ("X" ++ a)) (fromList [(5,"a"), (3,"b")]) == fromList [(3, "Xb"), (5, "a")]
updateMin (\ _ -> Nothing)         (fromList [(5,"a"), (3,"b")]) == singleton 5 "a"
updateMax 8b7c:f320:99b9:690f:4595:cd17:293a:c069 (a -> Maybe a) -> IntMap a -> IntMap a Source 
O(min(n,W)). Update the value at the maximal key.
updateMax (\ a -> Just ("X" ++ a)) (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "Xa")]
updateMax (\ _ -> Nothing)         (fromList [(5,"a"), (3,"b")]) == singleton 3 "b"
updateMinWithKey 8b7c:f320:99b9:690f:4595:cd17:293a:c069 (Key -> a -> Maybe a) -> IntMap a -> IntMap a Source 
O(min(n,W)). Update the value at the minimal key.
updateMinWithKey (\ k a -> Just ((show k) ++ ":" ++ a)) (fromList [(5,"a"), (3,"b")]) == fromList [(3,"3:b"), (5,"a")]
updateMinWithKey (\ _ _ -> Nothing)                     (fromList [(5,"a"), (3,"b")]) == singleton 5 "a"
updateMaxWithKey 8b7c:f320:99b9:690f:4595:cd17:293a:c069 (Key -> a -> Maybe a) -> IntMap a -> IntMap a Source 
O(min(n,W)). Update the value at the maximal key.
updateMaxWithKey (\ k a -> Just ((show k) ++ ":" ++ a)) (fromList [(5,"a"), (3,"b")]) == fromList [(3,"b"), (5,"5:a")]
updateMaxWithKey (\ _ _ -> Nothing)                     (fromList [(5,"a"), (3,"b")]) == singleton 3 "b"
minView 8b7c:f320:99b9:690f:4595:cd17:293a:c069 IntMap a -> Maybe (a, IntMap a) Source 
O(min(n,W)). Retrieves the minimal key of the map, and the map stripped of that element, or Nothing if passed an empty map.
maxView 8b7c:f320:99b9:690f:4595:cd17:293a:c069 IntMap a -> Maybe (a, IntMap a) Source 
O(min(n,W)). Retrieves the maximal key of the map, and the map stripped of that element, or Nothing if passed an empty map.
minViewWithKey 8b7c:f320:99b9:690f:4595:cd17:293a:c069 IntMap a -> Maybe ((Key, a), IntMap a) Source 
O(min(n,W)). Retrieves the minimal (key,value) pair of the map, and the map stripped of that element, or Nothing if passed an empty map.
minViewWithKey (fromList [(5,"a"), (3,"b")]) == Just ((3,"b"), singleton 5 "a")
minViewWithKey empty == Nothing
maxViewWithKey 8b7c:f320:99b9:690f:4595:cd17:293a:c069 IntMap a -> Maybe ((Key, a), IntMap a) Source 
O(min(n,W)). Retrieves the maximal (key,value) pair of the map, and the map stripped of that element, or Nothing if passed an empty map.
maxViewWithKey (fromList [(5,"a"), (3,"b")]) == Just ((5,"a"), singleton 3 "b")
maxViewWithKey empty == Nothing
DebuggingshowTree 8b7c:f320:99b9:690f:4595:cd17:293a:c069 Whoops "Data.IntMap.showTree has moved to Data.IntMap.Internal.Debug.showTree" => IntMap a -> String Source 
showTree has moved to showTree
showTreeWith 8b7c:f320:99b9:690f:4595:cd17:293a:c069 Whoops "Data.IntMap.showTreeWith has moved to Data.IntMap.Internal.Debug.showTreeWith" => Bool -> Bool -> IntMap a -> String Source 
showTreeWith has moved to showTreeWith


    
{'path': 'public/docs/haskell~8/libraries/containers-0.6.2.1/data-intmap-lazy.html', 'source': 'DevDocs.IO'}