Copyright | (c) Daan Leijen 2002 (c) Andriy Palamarchuk 2008 (c) wren romano 2016 |
---|---|
License | BSD-style |
Maintainer | libraries@haskell.org |
Portability | portable |
Safe Haskell | Trustworthy |
Language | Haskell2010 |
WARNING
This module is considered internal.
The Package Versioning Policy does not apply.
The contents of this module may change in any way whatsoever and without any warning between minor versions of this package.
Authors importing this module are expected to track development closely.
Description
This defines the data structures and core (hidden) manipulations on representations.
Since: ghc-0.5.9
Synopsis
- data Word64Map a
- type Key = Word64
- (!) :: Word64Map a -> Key -> a
- (!?) :: Word64Map a -> Key -> Maybe a
- (\\) :: Word64Map a -> Word64Map b -> Word64Map a
- null :: Word64Map a -> Bool
- size :: Word64Map a -> Int
- member :: Key -> Word64Map a -> Bool
- notMember :: Key -> Word64Map a -> Bool
- lookup :: Key -> Word64Map a -> Maybe a
- findWithDefault :: a -> Key -> Word64Map a -> a
- lookupLT :: Key -> Word64Map a -> Maybe (Key, a)
- lookupGT :: Key -> Word64Map a -> Maybe (Key, a)
- lookupLE :: Key -> Word64Map a -> Maybe (Key, a)
- lookupGE :: Key -> Word64Map a -> Maybe (Key, a)
- disjoint :: Word64Map a -> Word64Map b -> Bool
- empty :: Word64Map a
- singleton :: Key -> a -> Word64Map a
- insert :: Key -> a -> Word64Map a -> Word64Map a
- insertWith :: (a -> a -> a) -> Key -> a -> Word64Map a -> Word64Map a
- insertWithKey :: (Key -> a -> a -> a) -> Key -> a -> Word64Map a -> Word64Map a
- insertLookupWithKey :: (Key -> a -> a -> a) -> Key -> a -> Word64Map a -> (Maybe a, Word64Map a)
- delete :: Key -> Word64Map a -> Word64Map a
- adjust :: (a -> a) -> Key -> Word64Map a -> Word64Map a
- adjustWithKey :: (Key -> a -> a) -> Key -> Word64Map a -> Word64Map a
- update :: (a -> Maybe a) -> Key -> Word64Map a -> Word64Map a
- updateWithKey :: (Key -> a -> Maybe a) -> Key -> Word64Map a -> Word64Map a
- updateLookupWithKey :: (Key -> a -> Maybe a) -> Key -> Word64Map a -> (Maybe a, Word64Map a)
- alter :: (Maybe a -> Maybe a) -> Key -> Word64Map a -> Word64Map a
- alterF :: Functor f => (Maybe a -> f (Maybe a)) -> Key -> Word64Map a -> f (Word64Map a)
- union :: Word64Map a -> Word64Map a -> Word64Map a
- unionWith :: (a -> a -> a) -> Word64Map a -> Word64Map a -> Word64Map a
- unionWithKey :: (Key -> a -> a -> a) -> Word64Map a -> Word64Map a -> Word64Map a
- unions :: Foldable f => f (Word64Map a) -> Word64Map a
- unionsWith :: Foldable f => (a -> a -> a) -> f (Word64Map a) -> Word64Map a
- difference :: Word64Map a -> Word64Map b -> Word64Map a
- differenceWith :: (a -> b -> Maybe a) -> Word64Map a -> Word64Map b -> Word64Map a
- differenceWithKey :: (Key -> a -> b -> Maybe a) -> Word64Map a -> Word64Map b -> Word64Map a
- intersection :: Word64Map a -> Word64Map b -> Word64Map a
- intersectionWith :: (a -> b -> c) -> Word64Map a -> Word64Map b -> Word64Map c
- intersectionWithKey :: (Key -> a -> b -> c) -> Word64Map a -> Word64Map b -> Word64Map c
- compose :: Word64Map c -> Word64Map Word64 -> Word64Map c
- type SimpleWhenMissing = WhenMissing Identity
- type SimpleWhenMatched = WhenMatched Identity
- runWhenMatched :: WhenMatched f x y z -> Key -> x -> y -> f (Maybe z)
- runWhenMissing :: WhenMissing f x y -> Key -> x -> f (Maybe y)
- merge :: SimpleWhenMissing a c -> SimpleWhenMissing b c -> SimpleWhenMatched a b c -> Word64Map a -> Word64Map b -> Word64Map c
- zipWithMaybeMatched :: forall (f :: Type -> Type) x y z. Applicative f => (Key -> x -> y -> Maybe z) -> WhenMatched f x y z
- zipWithMatched :: forall (f :: Type -> Type) x y z. Applicative f => (Key -> x -> y -> z) -> WhenMatched f x y z
- mapMaybeMissing :: forall (f :: Type -> Type) x y. Applicative f => (Key -> x -> Maybe y) -> WhenMissing f x y
- dropMissing :: forall (f :: Type -> Type) x y. Applicative f => WhenMissing f x y
- preserveMissing :: forall (f :: Type -> Type) x. Applicative f => WhenMissing f x x
- mapMissing :: forall (f :: Type -> Type) x y. Applicative f => (Key -> x -> y) -> WhenMissing f x y
- filterMissing :: forall (f :: Type -> Type) x. Applicative f => (Key -> x -> Bool) -> WhenMissing f x x
- data WhenMissing (f :: Type -> Type) x y = WhenMissing {
- missingSubtree :: Word64Map x -> f (Word64Map y)
- missingKey :: Key -> x -> f (Maybe y)
- newtype WhenMatched (f :: Type -> Type) x y z = WhenMatched {
- matchedKey :: Key -> x -> y -> f (Maybe z)
- mergeA :: Applicative f => WhenMissing f a c -> WhenMissing f b c -> WhenMatched f a b c -> Word64Map a -> Word64Map b -> f (Word64Map c)
- zipWithMaybeAMatched :: (Key -> x -> y -> f (Maybe z)) -> WhenMatched f x y z
- zipWithAMatched :: Applicative f => (Key -> x -> y -> f z) -> WhenMatched f x y z
- traverseMaybeMissing :: Applicative f => (Key -> x -> f (Maybe y)) -> WhenMissing f x y
- traverseMissing :: Applicative f => (Key -> x -> f y) -> WhenMissing f x y
- filterAMissing :: Applicative f => (Key -> x -> f Bool) -> WhenMissing f x x
- mergeWithKey :: (Key -> a -> b -> Maybe c) -> (Word64Map a -> Word64Map c) -> (Word64Map b -> Word64Map c) -> Word64Map a -> Word64Map b -> Word64Map c
- mergeWithKey' :: (Prefix -> Mask -> Word64Map c -> Word64Map c -> Word64Map c) -> (Word64Map a -> Word64Map b -> Word64Map c) -> (Word64Map a -> Word64Map c) -> (Word64Map b -> Word64Map c) -> Word64Map a -> Word64Map b -> Word64Map c
- map :: (a -> b) -> Word64Map a -> Word64Map b
- mapWithKey :: (Key -> a -> b) -> Word64Map a -> Word64Map b
- traverseWithKey :: Applicative t => (Key -> a -> t b) -> Word64Map a -> t (Word64Map b)
- traverseMaybeWithKey :: Applicative f => (Key -> a -> f (Maybe b)) -> Word64Map a -> f (Word64Map b)
- mapAccum :: (a -> b -> (a, c)) -> a -> Word64Map b -> (a, Word64Map c)
- mapAccumWithKey :: (a -> Key -> b -> (a, c)) -> a -> Word64Map b -> (a, Word64Map c)
- mapAccumRWithKey :: (a -> Key -> b -> (a, c)) -> a -> Word64Map b -> (a, Word64Map c)
- mapKeys :: (Key -> Key) -> Word64Map a -> Word64Map a
- mapKeysWith :: (a -> a -> a) -> (Key -> Key) -> Word64Map a -> Word64Map a
- mapKeysMonotonic :: (Key -> Key) -> Word64Map a -> Word64Map a
- foldr :: (a -> b -> b) -> b -> Word64Map a -> b
- foldl :: (a -> b -> a) -> a -> Word64Map b -> a
- foldrWithKey :: (Key -> a -> b -> b) -> b -> Word64Map a -> b
- foldlWithKey :: (a -> Key -> b -> a) -> a -> Word64Map b -> a
- foldMapWithKey :: Monoid m => (Key -> a -> m) -> Word64Map a -> m
- foldr' :: (a -> b -> b) -> b -> Word64Map a -> b
- foldl' :: (a -> b -> a) -> a -> Word64Map b -> a
- foldrWithKey' :: (Key -> a -> b -> b) -> b -> Word64Map a -> b
- foldlWithKey' :: (a -> Key -> b -> a) -> a -> Word64Map b -> a
- elems :: Word64Map a -> [a]
- keys :: Word64Map a -> [Key]
- assocs :: Word64Map a -> [(Key, a)]
- keysSet :: Word64Map a -> Word64Set
- fromSet :: (Key -> a) -> Word64Set -> Word64Map a
- toList :: Word64Map a -> [(Key, a)]
- fromList :: [(Key, a)] -> Word64Map a
- fromListWith :: (a -> a -> a) -> [(Key, a)] -> Word64Map a
- fromListWithKey :: (Key -> a -> a -> a) -> [(Key, a)] -> Word64Map a
- toAscList :: Word64Map a -> [(Key, a)]
- toDescList :: Word64Map a -> [(Key, a)]
- fromAscList :: [(Key, a)] -> Word64Map a
- fromAscListWith :: (a -> a -> a) -> [(Key, a)] -> Word64Map a
- fromAscListWithKey :: (Key -> a -> a -> a) -> [(Key, a)] -> Word64Map a
- fromDistinctAscList :: [(Key, a)] -> Word64Map a
- filter :: (a -> Bool) -> Word64Map a -> Word64Map a
- filterWithKey :: (Key -> a -> Bool) -> Word64Map a -> Word64Map a
- restrictKeys :: Word64Map a -> Word64Set -> Word64Map a
- withoutKeys :: Word64Map a -> Word64Set -> Word64Map a
- partition :: (a -> Bool) -> Word64Map a -> (Word64Map a, Word64Map a)
- partitionWithKey :: (Key -> a -> Bool) -> Word64Map a -> (Word64Map a, Word64Map a)
- takeWhileAntitone :: (Key -> Bool) -> Word64Map a -> Word64Map a
- dropWhileAntitone :: (Key -> Bool) -> Word64Map a -> Word64Map a
- spanAntitone :: (Key -> Bool) -> Word64Map a -> (Word64Map a, Word64Map a)
- mapMaybe :: (a -> Maybe b) -> Word64Map a -> Word64Map b
- mapMaybeWithKey :: (Key -> a -> Maybe b) -> Word64Map a -> Word64Map b
- mapEither :: (a -> Either b c) -> Word64Map a -> (Word64Map b, Word64Map c)
- mapEitherWithKey :: (Key -> a -> Either b c) -> Word64Map a -> (Word64Map b, Word64Map c)
- split :: Key -> Word64Map a -> (Word64Map a, Word64Map a)
- splitLookup :: Key -> Word64Map a -> (Word64Map a, Maybe a, Word64Map a)
- splitRoot :: Word64Map a -> [Word64Map a]
- isSubmapOf :: Eq a => Word64Map a -> Word64Map a -> Bool
- isSubmapOfBy :: (a -> b -> Bool) -> Word64Map a -> Word64Map b -> Bool
- isProperSubmapOf :: Eq a => Word64Map a -> Word64Map a -> Bool
- isProperSubmapOfBy :: (a -> b -> Bool) -> Word64Map a -> Word64Map b -> Bool
- lookupMin :: Word64Map a -> Maybe (Key, a)
- lookupMax :: Word64Map a -> Maybe (Key, a)
- findMin :: Word64Map a -> (Key, a)
- findMax :: Word64Map a -> (Key, a)
- deleteMin :: Word64Map a -> Word64Map a
- deleteMax :: Word64Map a -> Word64Map a
- deleteFindMin :: Word64Map a -> ((Key, a), Word64Map a)
- deleteFindMax :: Word64Map a -> ((Key, a), Word64Map a)
- updateMin :: (a -> Maybe a) -> Word64Map a -> Word64Map a
- updateMax :: (a -> Maybe a) -> Word64Map a -> Word64Map a
- updateMinWithKey :: (Key -> a -> Maybe a) -> Word64Map a -> Word64Map a
- updateMaxWithKey :: (Key -> a -> Maybe a) -> Word64Map a -> Word64Map a
- minView :: Word64Map a -> Maybe (a, Word64Map a)
- maxView :: Word64Map a -> Maybe (a, Word64Map a)
- minViewWithKey :: Word64Map a -> Maybe ((Key, a), Word64Map a)
- maxViewWithKey :: Word64Map a -> Maybe ((Key, a), Word64Map a)
- showTree :: Show a => Word64Map a -> String
- showTreeWith :: Show a => Bool -> Bool -> Word64Map a -> String
- type Mask = Word64
- type Prefix = Word64
- type Nat = Word64
- natFromInt :: Key -> Nat
- intFromNat :: Nat -> Key
- link :: Prefix -> Word64Map a -> Prefix -> Word64Map a -> Word64Map a
- linkWithMask :: Mask -> Prefix -> Word64Map a -> Word64Map a -> Word64Map a
- bin :: Prefix -> Mask -> Word64Map a -> Word64Map a -> Word64Map a
- binCheckLeft :: Prefix -> Mask -> Word64Map a -> Word64Map a -> Word64Map a
- binCheckRight :: Prefix -> Mask -> Word64Map a -> Word64Map a -> Word64Map a
- zero :: Key -> Mask -> Bool
- nomatch :: Key -> Prefix -> Mask -> Bool
- match :: Key -> Prefix -> Mask -> Bool
- mask :: Key -> Mask -> Prefix
- maskW :: Nat -> Nat -> Prefix
- shorter :: Mask -> Mask -> Bool
- branchMask :: Prefix -> Prefix -> Mask
- highestBitMask :: Word64 -> Word64
- mapWhenMissing :: forall (f :: Type -> Type) a b x. (Applicative f, Monad f) => (a -> b) -> WhenMissing f x a -> WhenMissing f x b
- mapWhenMatched :: forall (f :: Type -> Type) a b x y. Functor f => (a -> b) -> WhenMatched f x y a -> WhenMatched f x y b
- lmapWhenMissing :: forall b a (f :: Type -> Type) x. (b -> a) -> WhenMissing f a x -> WhenMissing f b x
- contramapFirstWhenMatched :: forall b a (f :: Type -> Type) y z. (b -> a) -> WhenMatched f a y z -> WhenMatched f b y z
- contramapSecondWhenMatched :: forall b a (f :: Type -> Type) x z. (b -> a) -> WhenMatched f x a z -> WhenMatched f x b z
- mapGentlyWhenMissing :: forall (f :: Type -> Type) a b x. Functor f => (a -> b) -> WhenMissing f x a -> WhenMissing f x b
- mapGentlyWhenMatched :: forall (f :: Type -> Type) a b x y. Functor f => (a -> b) -> WhenMatched f x y a -> WhenMatched f x y b
Map type
A map of integers to values a
.
Instances
Operators
(!) :: Word64Map 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'
(!?) :: Word64Map 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: ghc-0.5.11
Query
null :: Word64Map a -> Bool Source #
\(O(1)\). Is the map empty?
Data.Word64Map.null (empty) == True Data.Word64Map.null (singleton 1 'a') == False
size :: Word64Map 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
member :: Key -> Word64Map 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 :: Key -> Word64Map 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
lookup :: Key -> Word64Map a -> Maybe a Source #
\(O(\min(n,W))\). Lookup the value at a key in the map. See also lookup
.
findWithDefault :: a -> Key -> Word64Map a -> a Source #
\(O(\min(n,W))\). The expression (
returns the value at key findWithDefault
def k map)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'
lookupLT :: Key -> Word64Map a -> Maybe (Key, a) Source #
\(O(\min(n,W))\). 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 :: Key -> Word64Map a -> Maybe (Key, a) Source #
\(O(\min(n,W))\). 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 :: Key -> Word64Map a -> Maybe (Key, a) Source #
\(O(\min(n,W))\). 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 :: Key -> Word64Map a -> Maybe (Key, a) Source #
\(O(\min(n,W))\). 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
disjoint :: Word64Map a -> Word64Map 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: ghc-0.6.2.1
Construction
singleton :: Key -> a -> Word64Map a Source #
\(O(1)\). A map of one element.
singleton 1 'a' == fromList [(1, 'a')] size (singleton 1 'a') == 1
Insertion
insert :: Key -> a -> Word64Map a -> Word64Map 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 :: (a -> a -> a) -> Key -> a -> Word64Map a -> Word64Map a Source #
\(O(\min(n,W))\). Insert with a combining function.
will insert the pair (key, value) into insertWith
f key value mpmp
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 :: (Key -> a -> a -> a) -> Key -> a -> Word64Map a -> Word64Map a Source #
\(O(\min(n,W))\). Insert with a combining function.
will insert the pair (key, value) into insertWithKey
f key value mpmp
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 :: (Key -> a -> a -> a) -> Key -> a -> Word64Map a -> (Maybe a, Word64Map a) Source #
\(O(\min(n,W))\). The expression (
)
is a pair where the first element is equal to (insertLookupWithKey
f k x map
)
and the second element equal to (lookup
k map
).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")])
Delete/Update
delete :: Key -> Word64Map a -> Word64Map 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 :: (a -> a) -> Key -> Word64Map a -> Word64Map 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 :: (Key -> a -> a) -> Key -> Word64Map a -> Word64Map 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 :: (a -> Maybe a) -> Key -> Word64Map a -> Word64Map a Source #
\(O(\min(n,W))\). The expression (
) updates the value update
f k mapx
at k
(if it is in the map). If (f x
) is Nothing
, the element is
deleted. If it is (
), the key Just
yk
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 :: (Key -> a -> Maybe a) -> Key -> Word64Map a -> Word64Map a Source #
\(O(\min(n,W))\). The expression (
) updates the value update
f k mapx
at k
(if it is in the map). If (f k x
) is Nothing
, the element is
deleted. If it is (
), the key Just
yk
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 :: (Key -> a -> Maybe a) -> Key -> Word64Map a -> (Maybe a, Word64Map 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")
alterF :: Functor f => (Maybe a -> f (Maybe a)) -> Key -> Word64Map a -> f (Word64Map a) Source #
\(O(\min(n,W))\). The expression (
) alters the value alterF
f k mapx
at
k
, or absence thereof. alterF
can be used to inspect, insert, delete,
or update a value in an Word64Map
. In short :
.lookup
k $ alterF
f k m = f
(lookup
k m)
Example:
interactiveAlter :: Int -> Word64Map String -> IO (Word64Map 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 :: 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 :: 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: ghc-0.5.8
Combine
Union
unionWith :: (a -> a -> a) -> Word64Map a -> Word64Map a -> Word64Map 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 :: (Key -> a -> a -> a) -> Word64Map a -> Word64Map a -> Word64Map 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 :: Foldable f => f (Word64Map a) -> Word64Map 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 :: Foldable f => (a -> a -> a) -> f (Word64Map a) -> Word64Map 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")]
Difference
difference :: Word64Map a -> Word64Map b -> Word64Map 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"
differenceWith :: (a -> b -> Maybe a) -> Word64Map a -> Word64Map b -> Word64Map 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 :: (Key -> a -> b -> Maybe a) -> Word64Map a -> Word64Map b -> Word64Map 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 (
), the element is updated with a new value Just
yy
.
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"
Intersection
intersection :: Word64Map a -> Word64Map b -> Word64Map 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 :: (a -> b -> c) -> Word64Map a -> Word64Map b -> Word64Map 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 :: (Key -> a -> b -> c) -> Word64Map a -> Word64Map b -> Word64Map 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"
Compose
compose :: Word64Map c -> Word64Map Word64 -> Word64Map c Source #
Relate the keys of one map to the values of the other, by using the values of the former as keys for lookups in the latter.
Complexity: \( O(n * \min(m,W)) \), where \(m\) is the size of the first argument
compose (fromList [('a', "A"), ('b', "B")]) (fromList [(1,'a'),(2,'b'),(3,'z')]) = fromList [(1,"A"),(2,"B")]
(compose
bc ab!?
) = (bc!?
) <=< (ab!?
)
Note: Prior to v0.6.4, Data.Word64Map.Strict exposed a version of
compose
that forced the values of the output Word64Map
. This version does
not force these values.
Since: ghc-0.6.3.1
General combining function
type SimpleWhenMissing = WhenMissing Identity Source #
A tactic for dealing with keys present in one map but not the
other in merge
.
A tactic of type SimpleWhenMissing x z
is an abstract
representation of a function of type Key -> x -> Maybe z
.
Since: ghc-0.5.9
type SimpleWhenMatched = WhenMatched Identity Source #
A tactic for dealing with keys present in both maps in merge
.
A tactic of type SimpleWhenMatched x y z
is an abstract
representation of a function of type Key -> x -> y -> Maybe z
.
Since: ghc-0.5.9
runWhenMatched :: WhenMatched f x y z -> Key -> x -> y -> f (Maybe z) Source #
Along with zipWithMaybeAMatched, witnesses the isomorphism
between WhenMatched f x y z
and Key -> x -> y -> f (Maybe z)
.
Since: ghc-0.5.9
runWhenMissing :: WhenMissing f x y -> Key -> x -> f (Maybe y) Source #
Along with traverseMaybeMissing, witnesses the isomorphism
between WhenMissing f x y
and Key -> x -> f (Maybe y)
.
Since: ghc-0.5.9
:: SimpleWhenMissing a c | What to do with keys in |
-> SimpleWhenMissing b c | What to do with keys in |
-> SimpleWhenMatched a b c | What to do with keys in both |
-> Word64Map a | Map |
-> Word64Map b | Map |
-> Word64Map c |
Merge two maps.
merge
takes two WhenMissing
tactics, a WhenMatched
tactic
and two maps. It uses the tactics to merge the maps. Its behavior
is best understood via its fundamental tactics, mapMaybeMissing
and zipWithMaybeMatched
.
Consider
merge (mapMaybeMissing g1) (mapMaybeMissing g2) (zipWithMaybeMatched f) m1 m2
Take, for example,
m1 = [(0, 'a'), (1, 'b'), (3, 'c'), (4, 'd')] m2 = [(1, "one"), (2, "two"), (4, "three")]
merge
will first "align" these maps by key:
m1 = [(0, 'a'), (1, 'b'), (3, 'c'), (4, 'd')] m2 = [(1, "one"), (2, "two"), (4, "three")]
It will then pass the individual entries and pairs of entries
to g1
, g2
, or f
as appropriate:
maybes = [g1 0 'a', f 1 'b' "one", g2 2 "two", g1 3 'c', f 4 'd' "three"]
This produces a Maybe
for each key:
keys = 0 1 2 3 4 results = [Nothing, Just True, Just False, Nothing, Just True]
Finally, the Just
results are collected into a map:
return value = [(1, True), (2, False), (4, True)]
The other tactics below are optimizations or simplifications of
mapMaybeMissing
for special cases. Most importantly,
dropMissing
drops all the keys.preserveMissing
leaves all the entries alone.
When merge
is given three arguments, it is inlined at the call
site. To prevent excessive inlining, you should typically use
merge
to define your custom combining functions.
Examples:
unionWithKey f = merge preserveMissing preserveMissing (zipWithMatched f)
intersectionWithKey f = merge dropMissing dropMissing (zipWithMatched f)
differenceWith f = merge diffPreserve diffDrop f
symmetricDifference = merge diffPreserve diffPreserve (\ _ _ _ -> Nothing)
mapEachPiece f g h = merge (diffMapWithKey f) (diffMapWithKey g)
Since: ghc-0.5.9
WhenMatched
tactics
zipWithMaybeMatched :: forall (f :: Type -> Type) x y z. Applicative f => (Key -> x -> y -> Maybe z) -> WhenMatched f x y z Source #
When a key is found in both maps, apply a function to the key and values and maybe use the result in the merged map.
zipWithMaybeMatched :: (Key -> x -> y -> Maybe z) -> SimpleWhenMatched x y z
Since: ghc-0.5.9
zipWithMatched :: forall (f :: Type -> Type) x y z. Applicative f => (Key -> x -> y -> z) -> WhenMatched f x y z Source #
When a key is found in both maps, apply a function to the key and values and use the result in the merged map.
zipWithMatched :: (Key -> x -> y -> z) -> SimpleWhenMatched x y z
Since: ghc-0.5.9
WhenMissing
tactics
mapMaybeMissing :: forall (f :: Type -> Type) x y. Applicative f => (Key -> x -> Maybe y) -> WhenMissing f x y Source #
Map over the entries whose keys are missing from the other
map, optionally removing some. This is the most powerful
SimpleWhenMissing
tactic, but others are usually more efficient.
mapMaybeMissing :: (Key -> x -> Maybe y) -> SimpleWhenMissing x y
mapMaybeMissing f = traverseMaybeMissing (\k x -> pure (f k x))
but mapMaybeMissing
uses fewer unnecessary Applicative
operations.
Since: ghc-0.5.9
dropMissing :: forall (f :: Type -> Type) x y. Applicative f => WhenMissing f x y Source #
Drop all the entries whose keys are missing from the other map.
dropMissing :: SimpleWhenMissing x y
dropMissing = mapMaybeMissing (\_ _ -> Nothing)
but dropMissing
is much faster.
Since: ghc-0.5.9
preserveMissing :: forall (f :: Type -> Type) x. Applicative f => WhenMissing f x x Source #
Preserve, unchanged, the entries whose keys are missing from the other map.
preserveMissing :: SimpleWhenMissing x x
preserveMissing = Merge.Lazy.mapMaybeMissing (\_ x -> Just x)
but preserveMissing
is much faster.
Since: ghc-0.5.9
mapMissing :: forall (f :: Type -> Type) x y. Applicative f => (Key -> x -> y) -> WhenMissing f x y Source #
Map over the entries whose keys are missing from the other map.
mapMissing :: (k -> x -> y) -> SimpleWhenMissing x y
mapMissing f = mapMaybeMissing (\k x -> Just $ f k x)
but mapMissing
is somewhat faster.
Since: ghc-0.5.9
filterMissing :: forall (f :: Type -> Type) x. Applicative f => (Key -> x -> Bool) -> WhenMissing f x x Source #
Filter the entries whose keys are missing from the other map.
filterMissing :: (k -> x -> Bool) -> SimpleWhenMissing x x
filterMissing f = Merge.Lazy.mapMaybeMissing $ \k x -> guard (f k x) *> Just x
but this should be a little faster.
Since: ghc-0.5.9
Applicative general combining function
data WhenMissing (f :: Type -> Type) x y Source #
A tactic for dealing with keys present in one map but not the
other in merge
or mergeA
.
A tactic of type WhenMissing f k x z
is an abstract representation
of a function of type Key -> x -> f (Maybe z)
.
Since: ghc-0.5.9
WhenMissing | |
|
Instances
newtype WhenMatched (f :: Type -> Type) x y z Source #
A tactic for dealing with keys present in both maps in merge
or mergeA
.
A tactic of type WhenMatched f x y z
is an abstract representation
of a function of type Key -> x -> y -> f (Maybe z)
.
Since: ghc-0.5.9
WhenMatched | |
|
Instances
(Monad f, Applicative f) => Category (WhenMatched f x :: Type -> Type -> Type) Source # | Since: ghc-0.5.9 |
Defined in GHC.Data.Word64Map.Internal id :: WhenMatched f x a a Source # (.) :: WhenMatched f x b c -> WhenMatched f x a b -> WhenMatched f x a c Source # | |
(Monad f, Applicative f) => Applicative (WhenMatched f x y) Source # | Equivalent to Since: ghc-0.5.9 |
Defined in GHC.Data.Word64Map.Internal pure :: a -> WhenMatched f x y a Source # (<*>) :: WhenMatched f x y (a -> b) -> WhenMatched f x y a -> WhenMatched f x y b Source # liftA2 :: (a -> b -> c) -> WhenMatched f x y a -> WhenMatched f x y b -> WhenMatched f x y c Source # (*>) :: WhenMatched f x y a -> WhenMatched f x y b -> WhenMatched f x y b Source # (<*) :: WhenMatched f x y a -> WhenMatched f x y b -> WhenMatched f x y a Source # | |
Functor f => Functor (WhenMatched f x y) Source # | Since: ghc-0.5.9 |
Defined in GHC.Data.Word64Map.Internal fmap :: (a -> b) -> WhenMatched f x y a -> WhenMatched f x y b Source # (<$) :: a -> WhenMatched f x y b -> WhenMatched f x y a Source # | |
(Monad f, Applicative f) => Monad (WhenMatched f x y) Source # | Equivalent to Since: ghc-0.5.9 |
Defined in GHC.Data.Word64Map.Internal (>>=) :: WhenMatched f x y a -> (a -> WhenMatched f x y b) -> WhenMatched f x y b Source # (>>) :: WhenMatched f x y a -> WhenMatched f x y b -> WhenMatched f x y b Source # return :: a -> WhenMatched f x y a Source # |
:: Applicative f | |
=> WhenMissing f a c | What to do with keys in |
-> WhenMissing f b c | What to do with keys in |
-> WhenMatched f a b c | What to do with keys in both |
-> Word64Map a | Map |
-> Word64Map b | Map |
-> f (Word64Map c) |
An applicative version of merge
.
mergeA
takes two WhenMissing
tactics, a WhenMatched
tactic and two maps. It uses the tactics to merge the maps.
Its behavior is best understood via its fundamental tactics,
traverseMaybeMissing
and zipWithMaybeAMatched
.
Consider
mergeA (traverseMaybeMissing g1) (traverseMaybeMissing g2) (zipWithMaybeAMatched f) m1 m2
Take, for example,
m1 = [(0, 'a'), (1, 'b'), (3,'c'), (4, 'd')] m2 = [(1, "one"), (2, "two"), (4, "three")]
mergeA
will first "align" these maps by key:
m1 = [(0, 'a'), (1, 'b'), (3, 'c'), (4, 'd')] m2 = [(1, "one"), (2, "two"), (4, "three")]
It will then pass the individual entries and pairs of entries
to g1
, g2
, or f
as appropriate:
actions = [g1 0 'a', f 1 'b' "one", g2 2 "two", g1 3 'c', f 4 'd' "three"]
Next, it will perform the actions in the actions
list in order from
left to right.
keys = 0 1 2 3 4 results = [Nothing, Just True, Just False, Nothing, Just True]
Finally, the Just
results are collected into a map:
return value = [(1, True), (2, False), (4, True)]
The other tactics below are optimizations or simplifications of
traverseMaybeMissing
for special cases. Most importantly,
dropMissing
drops all the keys.preserveMissing
leaves all the entries alone.mapMaybeMissing
does not use theApplicative
context.
When mergeA
is given three arguments, it is inlined at the call
site. To prevent excessive inlining, you should generally only use
mergeA
to define custom combining functions.
Since: ghc-0.5.9
WhenMatched
tactics
zipWithMaybeAMatched :: (Key -> x -> y -> f (Maybe z)) -> WhenMatched f x y z Source #
When a key is found in both maps, apply a function to the key and values, perform the resulting action, and maybe use the result in the merged map.
This is the fundamental WhenMatched
tactic.
Since: ghc-0.5.9
zipWithAMatched :: Applicative f => (Key -> x -> y -> f z) -> WhenMatched f x y z Source #
When a key is found in both maps, apply a function to the key and values to produce an action and use its result in the merged map.
Since: ghc-0.5.9
WhenMissing
tactics
traverseMaybeMissing :: Applicative f => (Key -> x -> f (Maybe y)) -> WhenMissing f x y Source #
Traverse over the entries whose keys are missing from the other
map, optionally producing values to put in the result. This is
the most powerful WhenMissing
tactic, but others are usually
more efficient.
Since: ghc-0.5.9
traverseMissing :: Applicative f => (Key -> x -> f y) -> WhenMissing f x y Source #
Traverse over the entries whose keys are missing from the other map.
Since: ghc-0.5.9
filterAMissing :: Applicative f => (Key -> x -> f Bool) -> WhenMissing f x x Source #
Filter the entries whose keys are missing from the other map
using some Applicative
action.
filterAMissing f = Merge.Lazy.traverseMaybeMissing $ \k x -> (\b -> guard b *> Just x) <$> f k x
but this should be a little faster.
Since: ghc-0.5.9
Deprecated general combining function
mergeWithKey :: (Key -> a -> b -> Maybe c) -> (Word64Map a -> Word64Map c) -> (Word64Map b -> Word64Map c) -> Word64Map a -> Word64Map b -> Word64Map 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
, a function combining two
mergeWithKey
combine only1 only2Word64Map
s 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
, but for example const
empty
or
map
f
could be used for any filterWithKey
ff
.
mergeWithKey' :: (Prefix -> Mask -> Word64Map c -> Word64Map c -> Word64Map c) -> (Word64Map a -> Word64Map b -> Word64Map c) -> (Word64Map a -> Word64Map c) -> (Word64Map b -> Word64Map c) -> Word64Map a -> Word64Map b -> Word64Map c Source #
Traversal
Map
map :: (a -> b) -> Word64Map a -> Word64Map 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 :: (Key -> a -> b) -> Word64Map a -> Word64Map 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 :: Applicative t => (Key -> a -> t b) -> Word64Map a -> t (Word64Map b) Source #
\(O(n)\).
That is, behaves exactly like a regular traverseWithKey
f s == fromList
$ traverse
((k, v) -> (,) k $ f k v) (toList
m)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
traverseMaybeWithKey :: Applicative f => (Key -> a -> f (Maybe b)) -> Word64Map a -> f (Word64Map b) Source #
\(O(n)\). Traverse keys/values and collect the Just
results.
Since: ghc-0.6.4
mapAccum :: (a -> b -> (a, c)) -> a -> Word64Map b -> (a, Word64Map c) Source #
\(O(n)\). The function
threads an accumulating
argument through the map in ascending order of keys.mapAccum
let f a b = (a ++ b, b ++ "X") mapAccum f "Everything: " (fromList [(5,"a"), (3,"b")]) == ("Everything: ba", fromList [(3, "bX"), (5, "aX")])
mapAccumWithKey :: (a -> Key -> b -> (a, c)) -> a -> Word64Map b -> (a, Word64Map c) Source #
\(O(n)\). The function
threads an accumulating
argument through the map in ascending order of keys.mapAccumWithKey
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 :: (a -> Key -> b -> (a, c)) -> a -> Word64Map b -> (a, Word64Map c) Source #
\(O(n)\). The function
threads an accumulating
argument through the map in descending order of keys.mapAccumRWithKey
mapKeys :: (Key -> Key) -> Word64Map a -> Word64Map a Source #
\(O(n \min(n,W))\).
is the map obtained by applying mapKeys
f sf
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 :: (a -> a -> a) -> (Key -> Key) -> Word64Map a -> Word64Map a Source #
\(O(n \min(n,W))\).
is the map obtained by applying mapKeysWith
c f sf
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 :: (Key -> Key) -> Word64Map a -> Word64Map a Source #
\(O(n \min(n,W))\).
, but works only when mapKeysMonotonic
f s == mapKeys
f sf
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")]
Folds
foldrWithKey :: (Key -> a -> b -> b) -> b -> Word64Map 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 :: (a -> Key -> b -> a) -> a -> Word64Map 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 :: Monoid m => (Key -> a -> m) -> Word64Map 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: ghc-0.5.4
Strict folds
foldr' :: (a -> b -> b) -> b -> Word64Map 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' :: (a -> b -> a) -> a -> Word64Map 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' :: (Key -> a -> b -> b) -> b -> Word64Map 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' :: (a -> Key -> b -> a) -> a -> Word64Map 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.
Conversion
elems :: Word64Map 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 :: Word64Map 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 :: Word64Map 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 :: Word64Map a -> Word64Set Source #
\(O(n \min(n,W))\). The set of all keys of the map.
keysSet (fromList [(5,"a"), (3,"b")]) == Data.Word64Set.fromList [3,5] keysSet empty == Data.Word64Set.empty
fromSet :: (Key -> a) -> Word64Set -> Word64Map 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.Word64Set.fromList [3, 5]) == fromList [(5,"aaaaa"), (3,"aaa")] fromSet undefined Data.Word64Set.empty == empty
Lists
toList :: Word64Map 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 == []
fromList :: [(Key, a)] -> Word64Map 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 :: (a -> a -> a) -> [(Key, a)] -> Word64Map 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 :: (Key -> a -> a -> a) -> [(Key, a)] -> Word64Map 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
Ordered lists
toAscList :: Word64Map 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 :: Word64Map 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")]
fromAscList :: [(Key, a)] -> Word64Map 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 :: (a -> a -> a) -> [(Key, a)] -> Word64Map 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 :: (Key -> a -> a -> a) -> [(Key, a)] -> Word64Map 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 :: [(Key, a)] -> Word64Map 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")]
Filter
filter :: (a -> Bool) -> Word64Map a -> Word64Map 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 :: (Key -> a -> Bool) -> Word64Map a -> Word64Map 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 :: Word64Map a -> Word64Set -> Word64Map 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: ghc-0.5.8
withoutKeys :: Word64Map a -> Word64Set -> Word64Map 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: ghc-0.5.8
partition :: (a -> Bool) -> Word64Map a -> (Word64Map a, Word64Map 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 :: (Key -> a -> Bool) -> Word64Map a -> (Word64Map a, Word64Map 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")])
takeWhileAntitone :: (Key -> Bool) -> Word64Map a -> Word64Map a Source #
\(O(\min(n,W))\). Take while a predicate on the keys holds.
The user is responsible for ensuring that for all Int
s, j < k ==> p j >= p k
.
See note at spanAntitone
.
takeWhileAntitone p =fromDistinctAscList
.takeWhile
(p . fst) .toList
takeWhileAntitone p =filterWithKey
(\k _ -> p k)
Since: ghc-0.6.7
dropWhileAntitone :: (Key -> Bool) -> Word64Map a -> Word64Map a Source #
\(O(\min(n,W))\). Drop while a predicate on the keys holds.
The user is responsible for ensuring that for all Int
s, j < k ==> p j >= p k
.
See note at spanAntitone
.
dropWhileAntitone p =fromDistinctAscList
.dropWhile
(p . fst) .toList
dropWhileAntitone p =filterWithKey
(\k _ -> not (p k))
Since: ghc-0.6.7
spanAntitone :: (Key -> Bool) -> Word64Map a -> (Word64Map a, Word64Map a) Source #
\(O(\min(n,W))\). Divide a map at the point where a predicate on the keys stops holding.
The user is responsible for ensuring that for all Int
s, j < k ==> p j >= p k
.
spanAntitone p xs = (takeWhileAntitone
p xs,dropWhileAntitone
p xs) spanAntitone p xs =partitionWithKey
(\k _ -> p k) xs
Note: if p
is not actually antitone, then spanAntitone
will split the map
at some unspecified point.
Since: ghc-0.6.7
mapMaybe :: (a -> Maybe b) -> Word64Map a -> Word64Map 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 :: (Key -> a -> Maybe b) -> Word64Map a -> Word64Map 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 :: (a -> Either b c) -> Word64Map a -> (Word64Map b, Word64Map 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 :: (Key -> a -> Either b c) -> Word64Map a -> (Word64Map b, Word64Map 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 :: Key -> Word64Map a -> (Word64Map a, Word64Map a) Source #
\(O(\min(n,W))\). The expression (
) is a pair split
k map(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 :: Key -> Word64Map a -> (Word64Map a, Maybe a, Word64Map 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 :: Word64Map a -> [Word64Map 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..6::Int] ['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.
Submap
isSubmapOf :: Eq a => Word64Map a -> Word64Map a -> Bool Source #
\(O(n+m)\). Is this a submap?
Defined as (
).isSubmapOf
= isSubmapOfBy
(==)
isSubmapOfBy :: (a -> b -> Bool) -> Word64Map a -> Word64Map b -> Bool Source #
\(O(n+m)\).
The expression (
) returns isSubmapOfBy
f m1 m2True
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 :: Eq a => Word64Map a -> Word64Map a -> Bool Source #
\(O(n+m)\). Is this a proper submap? (ie. a submap but not equal).
Defined as (
).isProperSubmapOf
= isProperSubmapOfBy
(==)
isProperSubmapOfBy :: (a -> b -> Bool) -> Word64Map a -> Word64Map b -> Bool Source #
\(O(n+m)\). Is this a proper submap? (ie. a submap but not equal).
The expression (
) returns isProperSubmapOfBy
f m1 m2True
when
keys m1
and keys 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/Max
lookupMin :: Word64Map a -> Maybe (Key, a) Source #
\(O(\min(n,W))\). The minimal key of the map. Returns Nothing
if the map is empty.
lookupMax :: Word64Map a -> Maybe (Key, a) Source #
\(O(\min(n,W))\). The maximal key of the map. Returns Nothing
if the map is empty.
findMin :: Word64Map 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 :: Word64Map 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.
deleteFindMin :: Word64Map a -> ((Key, a), Word64Map 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 :: Word64Map a -> ((Key, a), Word64Map 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 :: (a -> Maybe a) -> Word64Map a -> Word64Map 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 :: (a -> Maybe a) -> Word64Map a -> Word64Map 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 :: (Key -> a -> Maybe a) -> Word64Map a -> Word64Map 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 :: (Key -> a -> Maybe a) -> Word64Map a -> Word64Map 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 :: Word64Map a -> Maybe (a, Word64Map 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 :: Word64Map a -> Maybe (a, Word64Map 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 :: Word64Map a -> Maybe ((Key, a), Word64Map 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 :: Word64Map a -> Maybe ((Key, a), Word64Map 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
Debugging
showTree :: Show a => Word64Map a -> String Source #
\(O(n \min(n,W))\). Show the tree that implements the map. The tree is shown in a compressed, hanging format.
showTreeWith :: Show a => Bool -> Bool -> Word64Map a -> String Source #
\(O(n \min(n,W))\). The expression (
) shows
the tree that implements the map. If showTreeWith
hang wide maphang
is
True
, a hanging tree is shown otherwise a rotated tree is shown. If
wide
is True
, an extra wide version is shown.
Internal types
Utility
natFromInt :: Key -> Nat Source #
intFromNat :: Nat -> Key Source #
zero :: Key -> Mask -> Bool Source #
Should this key follow the left subtree of a Bin
with switching
bit m
? N.B., the answer is only valid when match i p m
is true.
nomatch :: Key -> Prefix -> Mask -> Bool Source #
Does the key i
differ from the prefix p
before getting to
the switching bit m
?
match :: Key -> Prefix -> Mask -> Bool Source #
Does the key i
match the prefix p
(up to but not including
bit m
)?
mask :: Key -> Mask -> Prefix Source #
The prefix of key i
up to (but not including) the switching
bit m
.
maskW :: Nat -> Nat -> Prefix Source #
The prefix of key i
up to (but not including) the switching
bit m
.
branchMask :: Prefix -> Prefix -> Mask Source #
The first switching bit where the two prefixes disagree.
highestBitMask :: Word64 -> Word64 Source #
Return a word where only the highest bit is set.
Used by Word64Map.Merge.Lazy and Word64Map.Merge.Strict
mapWhenMissing :: forall (f :: Type -> Type) a b x. (Applicative f, Monad f) => (a -> b) -> WhenMissing f x a -> WhenMissing f x b Source #
Map covariantly over a
.WhenMissing
f x
Since: ghc-0.5.9
mapWhenMatched :: forall (f :: Type -> Type) a b x y. Functor f => (a -> b) -> WhenMatched f x y a -> WhenMatched f x y b Source #
Map covariantly over a
.WhenMatched
f x y
Since: ghc-0.5.9
lmapWhenMissing :: forall b a (f :: Type -> Type) x. (b -> a) -> WhenMissing f a x -> WhenMissing f b x Source #
Map contravariantly over a
.WhenMissing
f _ x
Since: ghc-0.5.9
contramapFirstWhenMatched :: forall b a (f :: Type -> Type) y z. (b -> a) -> WhenMatched f a y z -> WhenMatched f b y z Source #
Map contravariantly over a
.WhenMatched
f _ y z
Since: ghc-0.5.9
contramapSecondWhenMatched :: forall b a (f :: Type -> Type) x z. (b -> a) -> WhenMatched f x a z -> WhenMatched f x b z Source #
Map contravariantly over a
.WhenMatched
f x _ z
Since: ghc-0.5.9
mapGentlyWhenMissing :: forall (f :: Type -> Type) a b x. Functor f => (a -> b) -> WhenMissing f x a -> WhenMissing f x b Source #
Map covariantly over a
, using only a
'Functor f' constraint.WhenMissing
f x
mapGentlyWhenMatched :: forall (f :: Type -> Type) a b x y. Functor f => (a -> b) -> WhenMatched f x y a -> WhenMatched f x y b Source #
Map covariantly over a
, using only a
'Functor f' constraint.WhenMatched
f k x