{-# LANGUAGE CPP #-}
{-# LANGUAGE MagicHash #-}
{-# LANGUAGE TypeFamilies #-}
{-# OPTIONS_HADDOCK not-home #-}
{-# OPTIONS_GHC -fno-warn-incomplete-uni-patterns #-}
module GHC.Data.Word64Map.Internal (
Word64Map(..), Key
, (!), (!?), (\\)
, null
, size
, member
, notMember
, lookup
, findWithDefault
, lookupLT
, lookupGT
, lookupLE
, lookupGE
, disjoint
, empty
, singleton
, insert
, insertWith
, insertWithKey
, insertLookupWithKey
, delete
, adjust
, adjustWithKey
, update
, updateWithKey
, updateLookupWithKey
, alter
, alterF
, union
, unionWith
, unionWithKey
, unions
, unionsWith
, difference
, differenceWith
, differenceWithKey
, intersection
, intersectionWith
, intersectionWithKey
, compose
, SimpleWhenMissing
, SimpleWhenMatched
, runWhenMatched
, runWhenMissing
, merge
, zipWithMaybeMatched
, zipWithMatched
, mapMaybeMissing
, dropMissing
, preserveMissing
, mapMissing
, filterMissing
, WhenMissing (..)
, WhenMatched (..)
, mergeA
, zipWithMaybeAMatched
, zipWithAMatched
, traverseMaybeMissing
, traverseMissing
, filterAMissing
, mergeWithKey
, mergeWithKey'
, map
, mapWithKey
, traverseWithKey
, traverseMaybeWithKey
, mapAccum
, mapAccumWithKey
, mapAccumRWithKey
, mapKeys
, mapKeysWith
, mapKeysMonotonic
, foldr
, foldl
, foldrWithKey
, foldlWithKey
, foldMapWithKey
, foldr'
, foldl'
, foldrWithKey'
, foldlWithKey'
, elems
, keys
, assocs
, keysSet
, fromSet
, toList
, fromList
, fromListWith
, fromListWithKey
, toAscList
, toDescList
, fromAscList
, fromAscListWith
, fromAscListWithKey
, fromDistinctAscList
, filter
, filterWithKey
, restrictKeys
, withoutKeys
, partition
, partitionWithKey
, takeWhileAntitone
, dropWhileAntitone
, spanAntitone
, mapMaybe
, mapMaybeWithKey
, mapEither
, mapEitherWithKey
, split
, splitLookup
, splitRoot
, isSubmapOf, isSubmapOfBy
, isProperSubmapOf, isProperSubmapOfBy
, lookupMin
, lookupMax
, findMin
, findMax
, deleteMin
, deleteMax
, deleteFindMin
, deleteFindMax
, updateMin
, updateMax
, updateMinWithKey
, updateMaxWithKey
, minView
, maxView
, minViewWithKey
, maxViewWithKey
, showTree
, showTreeWith
, Mask, Prefix, Nat
, natFromInt
, intFromNat
, link
, linkWithMask
, bin
, binCheckLeft
, binCheckRight
, zero
, nomatch
, match
, mask
, maskW
, shorter
, branchMask
, highestBitMask
, mapWhenMissing
, mapWhenMatched
, lmapWhenMissing
, contramapFirstWhenMatched
, contramapSecondWhenMatched
, mapGentlyWhenMissing
, mapGentlyWhenMatched
) where
import GHC.Prelude.Basic hiding
(lookup, filter, foldr, foldl, foldl', null, map)
import Data.Functor.Identity (Identity (..))
import Data.Semigroup (Semigroup(stimes,(<>)),stimesIdempotentMonoid)
import Data.Functor.Classes
import Control.DeepSeq (NFData(rnf))
import qualified Data.Foldable as Foldable
import Data.Maybe (fromMaybe)
import GHC.Data.Word64Set.Internal (Key)
import qualified GHC.Data.Word64Set.Internal as Word64Set
import GHC.Utils.Containers.Internal.BitUtil
import GHC.Utils.Containers.Internal.StrictPair
#ifdef __GLASGOW_HASKELL__
import Data.Coerce
import Data.Data (Data(..), Constr, mkConstr, constrIndex, Fixity(Prefix),
DataType, mkDataType, gcast1)
import GHC.Exts (build)
import qualified GHC.Exts as GHCExts
import Text.Read
#endif
import qualified Control.Category as Category
import Data.Word
type Nat = Word64
natFromInt :: Key -> Nat
natFromInt :: Word64 -> Word64
natFromInt = Word64 -> Word64
forall a. a -> a
id
{-# INLINE natFromInt #-}
intFromNat :: Nat -> Key
intFromNat :: Word64 -> Word64
intFromNat = Word64 -> Word64
forall a. a -> a
id
{-# INLINE intFromNat #-}
data Word64Map a = Bin {-# UNPACK #-} !Prefix
{-# UNPACK #-} !Mask
!(Word64Map a)
!(Word64Map a)
| Tip {-# UNPACK #-} !Key a
| Nil
type Prefix = Word64
type Mask = Word64
type Word64SetPrefix = Word64
type Word64SetBitMap = Word64
bitmapOf :: Word64 -> Word64SetBitMap
bitmapOf :: Word64 -> Word64
bitmapOf Word64
x = Word64 -> Int -> Word64
shiftLL Word64
1 (Word64 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Word64
x Word64 -> Word64 -> Word64
forall a. Bits a => a -> a -> a
.&. Word64
Word64Set.suffixBitMask))
{-# INLINE bitmapOf #-}
(!) :: Word64Map a -> Key -> a
! :: forall a. Word64Map a -> Word64 -> a
(!) Word64Map a
m Word64
k = Word64 -> Word64Map a -> a
forall a. Word64 -> Word64Map a -> a
find Word64
k Word64Map a
m
(!?) :: Word64Map a -> Key -> Maybe a
!? :: forall a. Word64Map a -> Word64 -> Maybe a
(!?) Word64Map a
m Word64
k = Word64 -> Word64Map a -> Maybe a
forall a. Word64 -> Word64Map a -> Maybe a
lookup Word64
k Word64Map a
m
(\\) :: Word64Map a -> Word64Map b -> Word64Map a
Word64Map a
m1 \\ :: forall a b. Word64Map a -> Word64Map b -> Word64Map a
\\ Word64Map b
m2 = Word64Map a -> Word64Map b -> Word64Map a
forall a b. Word64Map a -> Word64Map b -> Word64Map a
difference Word64Map a
m1 Word64Map b
m2
infixl 9 !?,\\
instance Monoid (Word64Map a) where
mempty :: Word64Map a
mempty = Word64Map a
forall a. Word64Map a
empty
mconcat :: [Word64Map a] -> Word64Map a
mconcat = [Word64Map a] -> Word64Map a
forall (f :: * -> *) a.
Foldable f =>
f (Word64Map a) -> Word64Map a
unions
mappend :: Word64Map a -> Word64Map a -> Word64Map a
mappend = Word64Map a -> Word64Map a -> Word64Map a
forall a. Semigroup a => a -> a -> a
(<>)
instance Semigroup (Word64Map a) where
<> :: Word64Map a -> Word64Map a -> Word64Map a
(<>) = Word64Map a -> Word64Map a -> Word64Map a
forall a. Word64Map a -> Word64Map a -> Word64Map a
union
stimes :: forall b. Integral b => b -> Word64Map a -> Word64Map a
stimes = b -> Word64Map a -> Word64Map a
forall b a. (Integral b, Monoid a) => b -> a -> a
stimesIdempotentMonoid
instance Foldable.Foldable Word64Map where
fold :: forall m. Monoid m => Word64Map m -> m
fold = Word64Map m -> m
forall m. Monoid m => Word64Map m -> m
go
where go :: Word64Map t -> t
go Word64Map t
Nil = t
forall a. Monoid a => a
mempty
go (Tip Word64
_ t
v) = t
v
go (Bin Word64
_ Word64
m Word64Map t
l Word64Map t
r)
| Word64
m Word64 -> Word64 -> Bool
forall a. Ord a => a -> a -> Bool
< Word64
0 = Word64Map t -> t
go Word64Map t
r t -> t -> t
forall a. Monoid a => a -> a -> a
`mappend` Word64Map t -> t
go Word64Map t
l
| Bool
otherwise = Word64Map t -> t
go Word64Map t
l t -> t -> t
forall a. Monoid a => a -> a -> a
`mappend` Word64Map t -> t
go Word64Map t
r
{-# INLINABLE fold #-}
foldr :: forall a b. (a -> b -> b) -> b -> Word64Map a -> b
foldr = (a -> b -> b) -> b -> Word64Map a -> b
forall a b. (a -> b -> b) -> b -> Word64Map a -> b
foldr
{-# INLINE foldr #-}
foldl :: forall b a. (b -> a -> b) -> b -> Word64Map a -> b
foldl = (b -> a -> b) -> b -> Word64Map a -> b
forall b a. (b -> a -> b) -> b -> Word64Map a -> b
foldl
{-# INLINE foldl #-}
foldMap :: forall m a. Monoid m => (a -> m) -> Word64Map a -> m
foldMap a -> m
f Word64Map a
t = Word64Map a -> m
go Word64Map a
t
where go :: Word64Map a -> m
go Word64Map a
Nil = m
forall a. Monoid a => a
mempty
go (Tip Word64
_ a
v) = a -> m
f a
v
go (Bin Word64
_ Word64
m Word64Map a
l Word64Map a
r)
| Word64
m Word64 -> Word64 -> Bool
forall a. Ord a => a -> a -> Bool
< Word64
0 = Word64Map a -> m
go Word64Map a
r m -> m -> m
forall a. Monoid a => a -> a -> a
`mappend` Word64Map a -> m
go Word64Map a
l
| Bool
otherwise = Word64Map a -> m
go Word64Map a
l m -> m -> m
forall a. Monoid a => a -> a -> a
`mappend` Word64Map a -> m
go Word64Map a
r
{-# INLINE foldMap #-}
foldl' :: forall b a. (b -> a -> b) -> b -> Word64Map a -> b
foldl' = (b -> a -> b) -> b -> Word64Map a -> b
forall b a. (b -> a -> b) -> b -> Word64Map a -> b
foldl'
{-# INLINE foldl' #-}
foldr' :: forall a b. (a -> b -> b) -> b -> Word64Map a -> b
foldr' = (a -> b -> b) -> b -> Word64Map a -> b
forall a b. (a -> b -> b) -> b -> Word64Map a -> b
foldr'
{-# INLINE foldr' #-}
length :: forall a. Word64Map a -> Int
length = Word64Map a -> Int
forall a. Word64Map a -> Int
size
{-# INLINE length #-}
null :: forall a. Word64Map a -> Bool
null = Word64Map a -> Bool
forall a. Word64Map a -> Bool
null
{-# INLINE null #-}
toList :: forall a. Word64Map a -> [a]
toList = Word64Map a -> [a]
forall a. Word64Map a -> [a]
elems
{-# INLINE toList #-}
elem :: forall a. Eq a => a -> Word64Map a -> Bool
elem = a -> Word64Map a -> Bool
forall a. Eq a => a -> Word64Map a -> Bool
go
where go :: t -> Word64Map t -> Bool
go !t
_ Word64Map t
Nil = Bool
False
go t
x (Tip Word64
_ t
y) = t
x t -> t -> Bool
forall a. Eq a => a -> a -> Bool
== t
y
go t
x (Bin Word64
_ Word64
_ Word64Map t
l Word64Map t
r) = t -> Word64Map t -> Bool
go t
x Word64Map t
l Bool -> Bool -> Bool
|| t -> Word64Map t -> Bool
go t
x Word64Map t
r
{-# INLINABLE elem #-}
maximum :: forall a. Ord a => Word64Map a -> a
maximum = Word64Map a -> a
forall a. Ord a => Word64Map a -> a
start
where start :: Word64Map t -> t
start Word64Map t
Nil = [Char] -> t
forall a. HasCallStack => [Char] -> a
error [Char]
"Data.Foldable.maximum (for Data.Word64Map): empty map"
start (Tip Word64
_ t
y) = t
y
start (Bin Word64
_ Word64
m Word64Map t
l Word64Map t
r)
| Word64
m Word64 -> Word64 -> Bool
forall a. Ord a => a -> a -> Bool
< Word64
0 = t -> Word64Map t -> t
forall {t}. Ord t => t -> Word64Map t -> t
go (Word64Map t -> t
start Word64Map t
r) Word64Map t
l
| Bool
otherwise = t -> Word64Map t -> t
forall {t}. Ord t => t -> Word64Map t -> t
go (Word64Map t -> t
start Word64Map t
l) Word64Map t
r
go :: t -> Word64Map t -> t
go !t
m Word64Map t
Nil = t
m
go t
m (Tip Word64
_ t
y) = t -> t -> t
forall a. Ord a => a -> a -> a
max t
m t
y
go t
m (Bin Word64
_ Word64
_ Word64Map t
l Word64Map t
r) = t -> Word64Map t -> t
go (t -> Word64Map t -> t
go t
m Word64Map t
l) Word64Map t
r
{-# INLINABLE maximum #-}
minimum :: forall a. Ord a => Word64Map a -> a
minimum = Word64Map a -> a
forall a. Ord a => Word64Map a -> a
start
where start :: Word64Map t -> t
start Word64Map t
Nil = [Char] -> t
forall a. HasCallStack => [Char] -> a
error [Char]
"Data.Foldable.minimum (for Data.Word64Map): empty map"
start (Tip Word64
_ t
y) = t
y
start (Bin Word64
_ Word64
m Word64Map t
l Word64Map t
r)
| Word64
m Word64 -> Word64 -> Bool
forall a. Ord a => a -> a -> Bool
< Word64
0 = t -> Word64Map t -> t
forall {t}. Ord t => t -> Word64Map t -> t
go (Word64Map t -> t
start Word64Map t
r) Word64Map t
l
| Bool
otherwise = t -> Word64Map t -> t
forall {t}. Ord t => t -> Word64Map t -> t
go (Word64Map t -> t
start Word64Map t
l) Word64Map t
r
go :: t -> Word64Map t -> t
go !t
m Word64Map t
Nil = t
m
go t
m (Tip Word64
_ t
y) = t -> t -> t
forall a. Ord a => a -> a -> a
min t
m t
y
go t
m (Bin Word64
_ Word64
_ Word64Map t
l Word64Map t
r) = t -> Word64Map t -> t
go (t -> Word64Map t -> t
go t
m Word64Map t
l) Word64Map t
r
{-# INLINABLE minimum #-}
sum :: forall a. Num a => Word64Map a -> a
sum = (a -> a -> a) -> a -> Word64Map a -> a
forall b a. (b -> a -> b) -> b -> Word64Map a -> b
foldl' a -> a -> a
forall a. Num a => a -> a -> a
(+) a
0
{-# INLINABLE sum #-}
product :: forall a. Num a => Word64Map a -> a
product = (a -> a -> a) -> a -> Word64Map a -> a
forall b a. (b -> a -> b) -> b -> Word64Map a -> b
foldl' a -> a -> a
forall a. Num a => a -> a -> a
(*) a
1
{-# INLINABLE product #-}
instance Traversable Word64Map where
traverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Word64Map a -> f (Word64Map b)
traverse a -> f b
f = (Word64 -> a -> f b) -> Word64Map a -> f (Word64Map b)
forall (t :: * -> *) a b.
Applicative t =>
(Word64 -> a -> t b) -> Word64Map a -> t (Word64Map b)
traverseWithKey (\Word64
_ -> a -> f b
f)
{-# INLINE traverse #-}
instance NFData a => NFData (Word64Map a) where
rnf :: Word64Map a -> ()
rnf Word64Map a
Nil = ()
rnf (Tip Word64
_ a
v) = a -> ()
forall a. NFData a => a -> ()
rnf a
v
rnf (Bin Word64
_ Word64
_ Word64Map a
l Word64Map a
r) = Word64Map a -> ()
forall a. NFData a => a -> ()
rnf Word64Map a
l () -> () -> ()
forall a b. a -> b -> b
`seq` Word64Map a -> ()
forall a. NFData a => a -> ()
rnf Word64Map a
r
#if __GLASGOW_HASKELL__
instance Data a => Data (Word64Map a) where
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Word64Map a -> c (Word64Map a)
gfoldl forall d b. Data d => c (d -> b) -> d -> c b
f forall g. g -> c g
z Word64Map a
im = ([(Word64, a)] -> Word64Map a) -> c ([(Word64, a)] -> Word64Map a)
forall g. g -> c g
z [(Word64, a)] -> Word64Map a
forall a. [(Word64, a)] -> Word64Map a
fromList c ([(Word64, a)] -> Word64Map a)
-> [(Word64, a)] -> c (Word64Map a)
forall d b. Data d => c (d -> b) -> d -> c b
`f` (Word64Map a -> [(Word64, a)]
forall a. Word64Map a -> [(Word64, a)]
toList Word64Map a
im)
toConstr :: Word64Map a -> Constr
toConstr Word64Map a
_ = Constr
fromListConstr
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (Word64Map a)
gunfold forall b r. Data b => c (b -> r) -> c r
k forall r. r -> c r
z Constr
c = case Constr -> Int
constrIndex Constr
c of
Int
1 -> c ([(Word64, a)] -> Word64Map a) -> c (Word64Map a)
forall b r. Data b => c (b -> r) -> c r
k (([(Word64, a)] -> Word64Map a) -> c ([(Word64, a)] -> Word64Map a)
forall r. r -> c r
z [(Word64, a)] -> Word64Map a
forall a. [(Word64, a)] -> Word64Map a
fromList)
Int
_ -> [Char] -> c (Word64Map a)
forall a. HasCallStack => [Char] -> a
error [Char]
"gunfold"
dataTypeOf :: Word64Map a -> DataType
dataTypeOf Word64Map a
_ = DataType
intMapDataType
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c (Word64Map a))
dataCast1 forall d. Data d => c (t d)
f = c (t a) -> Maybe (c (Word64Map a))
forall {k1} {k2} (c :: k1 -> *) (t :: k2 -> k1) (t' :: k2 -> k1)
(a :: k2).
(Typeable t, Typeable t') =>
c (t a) -> Maybe (c (t' a))
gcast1 c (t a)
forall d. Data d => c (t d)
f
fromListConstr :: Constr
fromListConstr :: Constr
fromListConstr = DataType -> [Char] -> [[Char]] -> Fixity -> Constr
mkConstr DataType
intMapDataType [Char]
"fromList" [] Fixity
Prefix
intMapDataType :: DataType
intMapDataType :: DataType
intMapDataType = [Char] -> [Constr] -> DataType
mkDataType [Char]
"Data.Word64Map.Internal.Word64Map" [Constr
fromListConstr]
#endif
null :: Word64Map a -> Bool
null :: forall a. Word64Map a -> Bool
null Word64Map a
Nil = Bool
True
null Word64Map a
_ = Bool
False
{-# INLINE null #-}
size :: Word64Map a -> Int
size :: forall a. Word64Map a -> Int
size = Int -> Word64Map a -> Int
forall {t} {a}. Num t => t -> Word64Map a -> t
go Int
0
where
go :: t -> Word64Map a -> t
go !t
acc (Bin Word64
_ Word64
_ Word64Map a
l Word64Map a
r) = t -> Word64Map a -> t
go (t -> Word64Map a -> t
go t
acc Word64Map a
l) Word64Map a
r
go t
acc (Tip Word64
_ a
_) = t
1 t -> t -> t
forall a. Num a => a -> a -> a
+ t
acc
go t
acc Word64Map a
Nil = t
acc
member :: Key -> Word64Map a -> Bool
member :: forall a. Word64 -> Word64Map a -> Bool
member !Word64
k = Word64Map a -> Bool
go
where
go :: Word64Map a -> Bool
go (Bin Word64
p Word64
m Word64Map a
l Word64Map a
r) | Word64 -> Word64 -> Word64 -> Bool
nomatch Word64
k Word64
p Word64
m = Bool
False
| Word64 -> Word64 -> Bool
zero Word64
k Word64
m = Word64Map a -> Bool
go Word64Map a
l
| Bool
otherwise = Word64Map a -> Bool
go Word64Map a
r
go (Tip Word64
kx a
_) = Word64
k Word64 -> Word64 -> Bool
forall a. Eq a => a -> a -> Bool
== Word64
kx
go Word64Map a
Nil = Bool
False
notMember :: Key -> Word64Map a -> Bool
notMember :: forall a. Word64 -> Word64Map a -> Bool
notMember Word64
k Word64Map a
m = Bool -> Bool
not (Bool -> Bool) -> Bool -> Bool
forall a b. (a -> b) -> a -> b
$ Word64 -> Word64Map a -> Bool
forall a. Word64 -> Word64Map a -> Bool
member Word64
k Word64Map a
m
lookup :: Key -> Word64Map a -> Maybe a
lookup :: forall a. Word64 -> Word64Map a -> Maybe a
lookup !Word64
k = Word64Map a -> Maybe a
go
where
go :: Word64Map a -> Maybe a
go (Bin Word64
_p Word64
m Word64Map a
l Word64Map a
r) | Word64 -> Word64 -> Bool
zero Word64
k Word64
m = Word64Map a -> Maybe a
go Word64Map a
l
| Bool
otherwise = Word64Map a -> Maybe a
go Word64Map a
r
go (Tip Word64
kx a
x) | Word64
k Word64 -> Word64 -> Bool
forall a. Eq a => a -> a -> Bool
== Word64
kx = a -> Maybe a
forall a. a -> Maybe a
Just a
x
| Bool
otherwise = Maybe a
forall a. Maybe a
Nothing
go Word64Map a
Nil = Maybe a
forall a. Maybe a
Nothing
find :: Key -> Word64Map a -> a
find :: forall a. Word64 -> Word64Map a -> a
find !Word64
k = Word64Map a -> a
go
where
go :: Word64Map a -> a
go (Bin Word64
_p Word64
m Word64Map a
l Word64Map a
r) | Word64 -> Word64 -> Bool
zero Word64
k Word64
m = Word64Map a -> a
go Word64Map a
l
| Bool
otherwise = Word64Map a -> a
go Word64Map a
r
go (Tip Word64
kx a
x) | Word64
k Word64 -> Word64 -> Bool
forall a. Eq a => a -> a -> Bool
== Word64
kx = a
x
| Bool
otherwise = a
not_found
go Word64Map a
Nil = a
not_found
not_found :: a
not_found = [Char] -> a
forall a. HasCallStack => [Char] -> a
error ([Char]
"Word64Map.!: key " [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ Word64 -> [Char]
forall a. Show a => a -> [Char]
show Word64
k [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ [Char]
" is not an element of the map")
findWithDefault :: a -> Key -> Word64Map a -> a
findWithDefault :: forall a. a -> Word64 -> Word64Map a -> a
findWithDefault a
def !Word64
k = Word64Map a -> a
go
where
go :: Word64Map a -> a
go (Bin Word64
p Word64
m Word64Map a
l Word64Map a
r) | Word64 -> Word64 -> Word64 -> Bool
nomatch Word64
k Word64
p Word64
m = a
def
| Word64 -> Word64 -> Bool
zero Word64
k Word64
m = Word64Map a -> a
go Word64Map a
l
| Bool
otherwise = Word64Map a -> a
go Word64Map a
r
go (Tip Word64
kx a
x) | Word64
k Word64 -> Word64 -> Bool
forall a. Eq a => a -> a -> Bool
== Word64
kx = a
x
| Bool
otherwise = a
def
go Word64Map a
Nil = a
def
lookupLT :: Key -> Word64Map a -> Maybe (Key, a)
lookupLT :: forall a. Word64 -> Word64Map a -> Maybe (Word64, a)
lookupLT !Word64
k Word64Map a
t = case Word64Map a
t of
Bin Word64
_ Word64
m Word64Map a
l Word64Map a
r | Word64
m Word64 -> Word64 -> Bool
forall a. Ord a => a -> a -> Bool
< Word64
0 -> if Word64
k Word64 -> Word64 -> Bool
forall a. Ord a => a -> a -> Bool
>= Word64
0 then Word64Map a -> Word64Map a -> Maybe (Word64, a)
go Word64Map a
r Word64Map a
l else Word64Map a -> Word64Map a -> Maybe (Word64, a)
go Word64Map a
forall a. Word64Map a
Nil Word64Map a
r
Word64Map a
_ -> Word64Map a -> Word64Map a -> Maybe (Word64, a)
go Word64Map a
forall a. Word64Map a
Nil Word64Map a
t
where
go :: Word64Map a -> Word64Map a -> Maybe (Word64, a)
go Word64Map a
def (Bin Word64
p Word64
m Word64Map a
l Word64Map a
r)
| Word64 -> Word64 -> Word64 -> Bool
nomatch Word64
k Word64
p Word64
m = if Word64
k Word64 -> Word64 -> Bool
forall a. Ord a => a -> a -> Bool
< Word64
p then Word64Map a -> Maybe (Word64, a)
forall a. Word64Map a -> Maybe (Word64, a)
unsafeFindMax Word64Map a
def else Word64Map a -> Maybe (Word64, a)
forall a. Word64Map a -> Maybe (Word64, a)
unsafeFindMax Word64Map a
r
| Word64 -> Word64 -> Bool
zero Word64
k Word64
m = Word64Map a -> Word64Map a -> Maybe (Word64, a)
go Word64Map a
def Word64Map a
l
| Bool
otherwise = Word64Map a -> Word64Map a -> Maybe (Word64, a)
go Word64Map a
l Word64Map a
r
go Word64Map a
def (Tip Word64
ky a
y)
| Word64
k Word64 -> Word64 -> Bool
forall a. Ord a => a -> a -> Bool
<= Word64
ky = Word64Map a -> Maybe (Word64, a)
forall a. Word64Map a -> Maybe (Word64, a)
unsafeFindMax Word64Map a
def
| Bool
otherwise = (Word64, a) -> Maybe (Word64, a)
forall a. a -> Maybe a
Just (Word64
ky, a
y)
go Word64Map a
def Word64Map a
Nil = Word64Map a -> Maybe (Word64, a)
forall a. Word64Map a -> Maybe (Word64, a)
unsafeFindMax Word64Map a
def
lookupGT :: Key -> Word64Map a -> Maybe (Key, a)
lookupGT :: forall a. Word64 -> Word64Map a -> Maybe (Word64, a)
lookupGT !Word64
k Word64Map a
t = case Word64Map a
t of
Bin Word64
_ Word64
m Word64Map a
l Word64Map a
r | Word64
m Word64 -> Word64 -> Bool
forall a. Ord a => a -> a -> Bool
< Word64
0 -> if Word64
k Word64 -> Word64 -> Bool
forall a. Ord a => a -> a -> Bool
>= Word64
0 then Word64Map a -> Word64Map a -> Maybe (Word64, a)
go Word64Map a
forall a. Word64Map a
Nil Word64Map a
l else Word64Map a -> Word64Map a -> Maybe (Word64, a)
go Word64Map a
l Word64Map a
r
Word64Map a
_ -> Word64Map a -> Word64Map a -> Maybe (Word64, a)
go Word64Map a
forall a. Word64Map a
Nil Word64Map a
t
where
go :: Word64Map a -> Word64Map a -> Maybe (Word64, a)
go Word64Map a
def (Bin Word64
p Word64
m Word64Map a
l Word64Map a
r)
| Word64 -> Word64 -> Word64 -> Bool
nomatch Word64
k Word64
p Word64
m = if Word64
k Word64 -> Word64 -> Bool
forall a. Ord a => a -> a -> Bool
< Word64
p then Word64Map a -> Maybe (Word64, a)
forall a. Word64Map a -> Maybe (Word64, a)
unsafeFindMin Word64Map a
l else Word64Map a -> Maybe (Word64, a)
forall a. Word64Map a -> Maybe (Word64, a)
unsafeFindMin Word64Map a
def
| Word64 -> Word64 -> Bool
zero Word64
k Word64
m = Word64Map a -> Word64Map a -> Maybe (Word64, a)
go Word64Map a
r Word64Map a
l
| Bool
otherwise = Word64Map a -> Word64Map a -> Maybe (Word64, a)
go Word64Map a
def Word64Map a
r
go Word64Map a
def (Tip Word64
ky a
y)
| Word64
k Word64 -> Word64 -> Bool
forall a. Ord a => a -> a -> Bool
>= Word64
ky = Word64Map a -> Maybe (Word64, a)
forall a. Word64Map a -> Maybe (Word64, a)
unsafeFindMin Word64Map a
def
| Bool
otherwise = (Word64, a) -> Maybe (Word64, a)
forall a. a -> Maybe a
Just (Word64
ky, a
y)
go Word64Map a
def Word64Map a
Nil = Word64Map a -> Maybe (Word64, a)
forall a. Word64Map a -> Maybe (Word64, a)
unsafeFindMin Word64Map a
def
lookupLE :: Key -> Word64Map a -> Maybe (Key, a)
lookupLE :: forall a. Word64 -> Word64Map a -> Maybe (Word64, a)
lookupLE !Word64
k Word64Map a
t = case Word64Map a
t of
Bin Word64
_ Word64
m Word64Map a
l Word64Map a
r | Word64
m Word64 -> Word64 -> Bool
forall a. Ord a => a -> a -> Bool
< Word64
0 -> if Word64
k Word64 -> Word64 -> Bool
forall a. Ord a => a -> a -> Bool
>= Word64
0 then Word64Map a -> Word64Map a -> Maybe (Word64, a)
go Word64Map a
r Word64Map a
l else Word64Map a -> Word64Map a -> Maybe (Word64, a)
go Word64Map a
forall a. Word64Map a
Nil Word64Map a
r
Word64Map a
_ -> Word64Map a -> Word64Map a -> Maybe (Word64, a)
go Word64Map a
forall a. Word64Map a
Nil Word64Map a
t
where
go :: Word64Map a -> Word64Map a -> Maybe (Word64, a)
go Word64Map a
def (Bin Word64
p Word64
m Word64Map a
l Word64Map a
r)
| Word64 -> Word64 -> Word64 -> Bool
nomatch Word64
k Word64
p Word64
m = if Word64
k Word64 -> Word64 -> Bool
forall a. Ord a => a -> a -> Bool
< Word64
p then Word64Map a -> Maybe (Word64, a)
forall a. Word64Map a -> Maybe (Word64, a)
unsafeFindMax Word64Map a
def else Word64Map a -> Maybe (Word64, a)
forall a. Word64Map a -> Maybe (Word64, a)
unsafeFindMax Word64Map a
r
| Word64 -> Word64 -> Bool
zero Word64
k Word64
m = Word64Map a -> Word64Map a -> Maybe (Word64, a)
go Word64Map a
def Word64Map a
l
| Bool
otherwise = Word64Map a -> Word64Map a -> Maybe (Word64, a)
go Word64Map a
l Word64Map a
r
go Word64Map a
def (Tip Word64
ky a
y)
| Word64
k Word64 -> Word64 -> Bool
forall a. Ord a => a -> a -> Bool
< Word64
ky = Word64Map a -> Maybe (Word64, a)
forall a. Word64Map a -> Maybe (Word64, a)
unsafeFindMax Word64Map a
def
| Bool
otherwise = (Word64, a) -> Maybe (Word64, a)
forall a. a -> Maybe a
Just (Word64
ky, a
y)
go Word64Map a
def Word64Map a
Nil = Word64Map a -> Maybe (Word64, a)
forall a. Word64Map a -> Maybe (Word64, a)
unsafeFindMax Word64Map a
def
lookupGE :: Key -> Word64Map a -> Maybe (Key, a)
lookupGE :: forall a. Word64 -> Word64Map a -> Maybe (Word64, a)
lookupGE !Word64
k Word64Map a
t = case Word64Map a
t of
Bin Word64
_ Word64
m Word64Map a
l Word64Map a
r | Word64
m Word64 -> Word64 -> Bool
forall a. Ord a => a -> a -> Bool
< Word64
0 -> if Word64
k Word64 -> Word64 -> Bool
forall a. Ord a => a -> a -> Bool
>= Word64
0 then Word64Map a -> Word64Map a -> Maybe (Word64, a)
go Word64Map a
forall a. Word64Map a
Nil Word64Map a
l else Word64Map a -> Word64Map a -> Maybe (Word64, a)
go Word64Map a
l Word64Map a
r
Word64Map a
_ -> Word64Map a -> Word64Map a -> Maybe (Word64, a)
go Word64Map a
forall a. Word64Map a
Nil Word64Map a
t
where
go :: Word64Map a -> Word64Map a -> Maybe (Word64, a)
go Word64Map a
def (Bin Word64
p Word64
m Word64Map a
l Word64Map a
r)
| Word64 -> Word64 -> Word64 -> Bool
nomatch Word64
k Word64
p Word64
m = if Word64
k Word64 -> Word64 -> Bool
forall a. Ord a => a -> a -> Bool
< Word64
p then Word64Map a -> Maybe (Word64, a)
forall a. Word64Map a -> Maybe (Word64, a)
unsafeFindMin Word64Map a
l else Word64Map a -> Maybe (Word64, a)
forall a. Word64Map a -> Maybe (Word64, a)
unsafeFindMin Word64Map a
def
| Word64 -> Word64 -> Bool
zero Word64
k Word64
m = Word64Map a -> Word64Map a -> Maybe (Word64, a)
go Word64Map a
r Word64Map a
l
| Bool
otherwise = Word64Map a -> Word64Map a -> Maybe (Word64, a)
go Word64Map a
def Word64Map a
r
go Word64Map a
def (Tip Word64
ky a
y)
| Word64
k Word64 -> Word64 -> Bool
forall a. Ord a => a -> a -> Bool
> Word64
ky = Word64Map a -> Maybe (Word64, a)
forall a. Word64Map a -> Maybe (Word64, a)
unsafeFindMin Word64Map a
def
| Bool
otherwise = (Word64, a) -> Maybe (Word64, a)
forall a. a -> Maybe a
Just (Word64
ky, a
y)
go Word64Map a
def Word64Map a
Nil = Word64Map a -> Maybe (Word64, a)
forall a. Word64Map a -> Maybe (Word64, a)
unsafeFindMin Word64Map a
def
unsafeFindMin :: Word64Map a -> Maybe (Key, a)
unsafeFindMin :: forall a. Word64Map a -> Maybe (Word64, a)
unsafeFindMin Word64Map a
Nil = Maybe (Word64, a)
forall a. Maybe a
Nothing
unsafeFindMin (Tip Word64
ky a
y) = (Word64, a) -> Maybe (Word64, a)
forall a. a -> Maybe a
Just (Word64
ky, a
y)
unsafeFindMin (Bin Word64
_ Word64
_ Word64Map a
l Word64Map a
_) = Word64Map a -> Maybe (Word64, a)
forall a. Word64Map a -> Maybe (Word64, a)
unsafeFindMin Word64Map a
l
unsafeFindMax :: Word64Map a -> Maybe (Key, a)
unsafeFindMax :: forall a. Word64Map a -> Maybe (Word64, a)
unsafeFindMax Word64Map a
Nil = Maybe (Word64, a)
forall a. Maybe a
Nothing
unsafeFindMax (Tip Word64
ky a
y) = (Word64, a) -> Maybe (Word64, a)
forall a. a -> Maybe a
Just (Word64
ky, a
y)
unsafeFindMax (Bin Word64
_ Word64
_ Word64Map a
_ Word64Map a
r) = Word64Map a -> Maybe (Word64, a)
forall a. Word64Map a -> Maybe (Word64, a)
unsafeFindMax Word64Map a
r
disjoint :: Word64Map a -> Word64Map b -> Bool
disjoint :: forall a b. Word64Map a -> Word64Map b -> Bool
disjoint Word64Map a
Nil Word64Map b
_ = Bool
True
disjoint Word64Map a
_ Word64Map b
Nil = Bool
True
disjoint (Tip Word64
kx a
_) Word64Map b
ys = Word64 -> Word64Map b -> Bool
forall a. Word64 -> Word64Map a -> Bool
notMember Word64
kx Word64Map b
ys
disjoint Word64Map a
xs (Tip Word64
ky b
_) = Word64 -> Word64Map a -> Bool
forall a. Word64 -> Word64Map a -> Bool
notMember Word64
ky Word64Map a
xs
disjoint t1 :: Word64Map a
t1@(Bin Word64
p1 Word64
m1 Word64Map a
l1 Word64Map a
r1) t2 :: Word64Map b
t2@(Bin Word64
p2 Word64
m2 Word64Map b
l2 Word64Map b
r2)
| Word64 -> Word64 -> Bool
shorter Word64
m1 Word64
m2 = Bool
disjoint1
| Word64 -> Word64 -> Bool
shorter Word64
m2 Word64
m1 = Bool
disjoint2
| Word64
p1 Word64 -> Word64 -> Bool
forall a. Eq a => a -> a -> Bool
== Word64
p2 = Word64Map a -> Word64Map b -> Bool
forall a b. Word64Map a -> Word64Map b -> Bool
disjoint Word64Map a
l1 Word64Map b
l2 Bool -> Bool -> Bool
&& Word64Map a -> Word64Map b -> Bool
forall a b. Word64Map a -> Word64Map b -> Bool
disjoint Word64Map a
r1 Word64Map b
r2
| Bool
otherwise = Bool
True
where
disjoint1 :: Bool
disjoint1 | Word64 -> Word64 -> Word64 -> Bool
nomatch Word64
p2 Word64
p1 Word64
m1 = Bool
True
| Word64 -> Word64 -> Bool
zero Word64
p2 Word64
m1 = Word64Map a -> Word64Map b -> Bool
forall a b. Word64Map a -> Word64Map b -> Bool
disjoint Word64Map a
l1 Word64Map b
t2
| Bool
otherwise = Word64Map a -> Word64Map b -> Bool
forall a b. Word64Map a -> Word64Map b -> Bool
disjoint Word64Map a
r1 Word64Map b
t2
disjoint2 :: Bool
disjoint2 | Word64 -> Word64 -> Word64 -> Bool
nomatch Word64
p1 Word64
p2 Word64
m2 = Bool
True
| Word64 -> Word64 -> Bool
zero Word64
p1 Word64
m2 = Word64Map a -> Word64Map b -> Bool
forall a b. Word64Map a -> Word64Map b -> Bool
disjoint Word64Map a
t1 Word64Map b
l2
| Bool
otherwise = Word64Map a -> Word64Map b -> Bool
forall a b. Word64Map a -> Word64Map b -> Bool
disjoint Word64Map a
t1 Word64Map b
r2
compose :: Word64Map c -> Word64Map Word64 -> Word64Map c
compose :: forall c. Word64Map c -> Word64Map Word64 -> Word64Map c
compose Word64Map c
bc !Word64Map Word64
ab
| Word64Map c -> Bool
forall a. Word64Map a -> Bool
null Word64Map c
bc = Word64Map c
forall a. Word64Map a
empty
| Bool
otherwise = (Word64 -> Maybe c) -> Word64Map Word64 -> Word64Map c
forall a b. (a -> Maybe b) -> Word64Map a -> Word64Map b
mapMaybe (Word64Map c
bc Word64Map c -> Word64 -> Maybe c
forall a. Word64Map a -> Word64 -> Maybe a
!?) Word64Map Word64
ab
empty :: Word64Map a
empty :: forall a. Word64Map a
empty
= Word64Map a
forall a. Word64Map a
Nil
{-# INLINE empty #-}
singleton :: Key -> a -> Word64Map a
singleton :: forall a. Word64 -> a -> Word64Map a
singleton Word64
k a
x
= Word64 -> a -> Word64Map a
forall a. Word64 -> a -> Word64Map a
Tip Word64
k a
x
{-# INLINE singleton #-}
insert :: Key -> a -> Word64Map a -> Word64Map a
insert :: forall a. Word64 -> a -> Word64Map a -> Word64Map a
insert !Word64
k a
x t :: Word64Map a
t@(Bin Word64
p Word64
m Word64Map a
l Word64Map a
r)
| Word64 -> Word64 -> Word64 -> Bool
nomatch Word64
k Word64
p Word64
m = Word64 -> Word64Map a -> Word64 -> Word64Map a -> Word64Map a
forall a.
Word64 -> Word64Map a -> Word64 -> Word64Map a -> Word64Map a
link Word64
k (Word64 -> a -> Word64Map a
forall a. Word64 -> a -> Word64Map a
Tip Word64
k a
x) Word64
p Word64Map a
t
| Word64 -> Word64 -> Bool
zero Word64
k Word64
m = Word64 -> Word64 -> Word64Map a -> Word64Map a -> Word64Map a
forall a.
Word64 -> Word64 -> Word64Map a -> Word64Map a -> Word64Map a
Bin Word64
p Word64
m (Word64 -> a -> Word64Map a -> Word64Map a
forall a. Word64 -> a -> Word64Map a -> Word64Map a
insert Word64
k a
x Word64Map a
l) Word64Map a
r
| Bool
otherwise = Word64 -> Word64 -> Word64Map a -> Word64Map a -> Word64Map a
forall a.
Word64 -> Word64 -> Word64Map a -> Word64Map a -> Word64Map a
Bin Word64
p Word64
m Word64Map a
l (Word64 -> a -> Word64Map a -> Word64Map a
forall a. Word64 -> a -> Word64Map a -> Word64Map a
insert Word64
k a
x Word64Map a
r)
insert Word64
k a
x t :: Word64Map a
t@(Tip Word64
ky a
_)
| Word64
kWord64 -> Word64 -> Bool
forall a. Eq a => a -> a -> Bool
==Word64
ky = Word64 -> a -> Word64Map a
forall a. Word64 -> a -> Word64Map a
Tip Word64
k a
x
| Bool
otherwise = Word64 -> Word64Map a -> Word64 -> Word64Map a -> Word64Map a
forall a.
Word64 -> Word64Map a -> Word64 -> Word64Map a -> Word64Map a
link Word64
k (Word64 -> a -> Word64Map a
forall a. Word64 -> a -> Word64Map a
Tip Word64
k a
x) Word64
ky Word64Map a
t
insert Word64
k a
x Word64Map a
Nil = Word64 -> a -> Word64Map a
forall a. Word64 -> a -> Word64Map a
Tip Word64
k a
x
insertWith :: (a -> a -> a) -> Key -> a -> Word64Map a -> Word64Map a
insertWith :: forall a.
(a -> a -> a) -> Word64 -> a -> Word64Map a -> Word64Map a
insertWith a -> a -> a
f Word64
k a
x Word64Map a
t
= (Word64 -> a -> a -> a)
-> Word64 -> a -> Word64Map a -> Word64Map a
forall a.
(Word64 -> a -> a -> a)
-> Word64 -> a -> Word64Map a -> Word64Map a
insertWithKey (\Word64
_ a
x' a
y' -> a -> a -> a
f a
x' a
y') Word64
k a
x Word64Map a
t
insertWithKey :: (Key -> a -> a -> a) -> Key -> a -> Word64Map a -> Word64Map a
insertWithKey :: forall a.
(Word64 -> a -> a -> a)
-> Word64 -> a -> Word64Map a -> Word64Map a
insertWithKey Word64 -> a -> a -> a
f !Word64
k a
x t :: Word64Map a
t@(Bin Word64
p Word64
m Word64Map a
l Word64Map a
r)
| Word64 -> Word64 -> Word64 -> Bool
nomatch Word64
k Word64
p Word64
m = Word64 -> Word64Map a -> Word64 -> Word64Map a -> Word64Map a
forall a.
Word64 -> Word64Map a -> Word64 -> Word64Map a -> Word64Map a
link Word64
k (Word64 -> a -> Word64Map a
forall a. Word64 -> a -> Word64Map a
Tip Word64
k a
x) Word64
p Word64Map a
t
| Word64 -> Word64 -> Bool
zero Word64
k Word64
m = Word64 -> Word64 -> Word64Map a -> Word64Map a -> Word64Map a
forall a.
Word64 -> Word64 -> Word64Map a -> Word64Map a -> Word64Map a
Bin Word64
p Word64
m ((Word64 -> a -> a -> a)
-> Word64 -> a -> Word64Map a -> Word64Map a
forall a.
(Word64 -> a -> a -> a)
-> Word64 -> a -> Word64Map a -> Word64Map a
insertWithKey Word64 -> a -> a -> a
f Word64
k a
x Word64Map a
l) Word64Map a
r
| Bool
otherwise = Word64 -> Word64 -> Word64Map a -> Word64Map a -> Word64Map a
forall a.
Word64 -> Word64 -> Word64Map a -> Word64Map a -> Word64Map a
Bin Word64
p Word64
m Word64Map a
l ((Word64 -> a -> a -> a)
-> Word64 -> a -> Word64Map a -> Word64Map a
forall a.
(Word64 -> a -> a -> a)
-> Word64 -> a -> Word64Map a -> Word64Map a
insertWithKey Word64 -> a -> a -> a
f Word64
k a
x Word64Map a
r)
insertWithKey Word64 -> a -> a -> a
f Word64
k a
x t :: Word64Map a
t@(Tip Word64
ky a
y)
| Word64
k Word64 -> Word64 -> Bool
forall a. Eq a => a -> a -> Bool
== Word64
ky = Word64 -> a -> Word64Map a
forall a. Word64 -> a -> Word64Map a
Tip Word64
k (Word64 -> a -> a -> a
f Word64
k a
x a
y)
| Bool
otherwise = Word64 -> Word64Map a -> Word64 -> Word64Map a -> Word64Map a
forall a.
Word64 -> Word64Map a -> Word64 -> Word64Map a -> Word64Map a
link Word64
k (Word64 -> a -> Word64Map a
forall a. Word64 -> a -> Word64Map a
Tip Word64
k a
x) Word64
ky Word64Map a
t
insertWithKey Word64 -> a -> a -> a
_ Word64
k a
x Word64Map a
Nil = Word64 -> a -> Word64Map a
forall a. Word64 -> a -> Word64Map a
Tip Word64
k a
x
insertLookupWithKey :: (Key -> a -> a -> a) -> Key -> a -> Word64Map a -> (Maybe a, Word64Map a)
insertLookupWithKey :: forall a.
(Word64 -> a -> a -> a)
-> Word64 -> a -> Word64Map a -> (Maybe a, Word64Map a)
insertLookupWithKey Word64 -> a -> a -> a
f !Word64
k a
x t :: Word64Map a
t@(Bin Word64
p Word64
m Word64Map a
l Word64Map a
r)
| Word64 -> Word64 -> Word64 -> Bool
nomatch Word64
k Word64
p Word64
m = (Maybe a
forall a. Maybe a
Nothing,Word64 -> Word64Map a -> Word64 -> Word64Map a -> Word64Map a
forall a.
Word64 -> Word64Map a -> Word64 -> Word64Map a -> Word64Map a
link Word64
k (Word64 -> a -> Word64Map a
forall a. Word64 -> a -> Word64Map a
Tip Word64
k a
x) Word64
p Word64Map a
t)
| Word64 -> Word64 -> Bool
zero Word64
k Word64
m = let (Maybe a
found,Word64Map a
l') = (Word64 -> a -> a -> a)
-> Word64 -> a -> Word64Map a -> (Maybe a, Word64Map a)
forall a.
(Word64 -> a -> a -> a)
-> Word64 -> a -> Word64Map a -> (Maybe a, Word64Map a)
insertLookupWithKey Word64 -> a -> a -> a
f Word64
k a
x Word64Map a
l
in (Maybe a
found,Word64 -> Word64 -> Word64Map a -> Word64Map a -> Word64Map a
forall a.
Word64 -> Word64 -> Word64Map a -> Word64Map a -> Word64Map a
Bin Word64
p Word64
m Word64Map a
l' Word64Map a
r)
| Bool
otherwise = let (Maybe a
found,Word64Map a
r') = (Word64 -> a -> a -> a)
-> Word64 -> a -> Word64Map a -> (Maybe a, Word64Map a)
forall a.
(Word64 -> a -> a -> a)
-> Word64 -> a -> Word64Map a -> (Maybe a, Word64Map a)
insertLookupWithKey Word64 -> a -> a -> a
f Word64
k a
x Word64Map a
r
in (Maybe a
found,Word64 -> Word64 -> Word64Map a -> Word64Map a -> Word64Map a
forall a.
Word64 -> Word64 -> Word64Map a -> Word64Map a -> Word64Map a
Bin Word64
p Word64
m Word64Map a
l Word64Map a
r')
insertLookupWithKey Word64 -> a -> a -> a
f Word64
k a
x t :: Word64Map a
t@(Tip Word64
ky a
y)
| Word64
k Word64 -> Word64 -> Bool
forall a. Eq a => a -> a -> Bool
== Word64
ky = (a -> Maybe a
forall a. a -> Maybe a
Just a
y,Word64 -> a -> Word64Map a
forall a. Word64 -> a -> Word64Map a
Tip Word64
k (Word64 -> a -> a -> a
f Word64
k a
x a
y))
| Bool
otherwise = (Maybe a
forall a. Maybe a
Nothing,Word64 -> Word64Map a -> Word64 -> Word64Map a -> Word64Map a
forall a.
Word64 -> Word64Map a -> Word64 -> Word64Map a -> Word64Map a
link Word64
k (Word64 -> a -> Word64Map a
forall a. Word64 -> a -> Word64Map a
Tip Word64
k a
x) Word64
ky Word64Map a
t)
insertLookupWithKey Word64 -> a -> a -> a
_ Word64
k a
x Word64Map a
Nil = (Maybe a
forall a. Maybe a
Nothing,Word64 -> a -> Word64Map a
forall a. Word64 -> a -> Word64Map a
Tip Word64
k a
x)
delete :: Key -> Word64Map a -> Word64Map a
delete :: forall a. Word64 -> Word64Map a -> Word64Map a
delete !Word64
k t :: Word64Map a
t@(Bin Word64
p Word64
m Word64Map a
l Word64Map a
r)
| Word64 -> Word64 -> Word64 -> Bool
nomatch Word64
k Word64
p Word64
m = Word64Map a
t
| Word64 -> Word64 -> Bool
zero Word64
k Word64
m = Word64 -> Word64 -> Word64Map a -> Word64Map a -> Word64Map a
forall a.
Word64 -> Word64 -> Word64Map a -> Word64Map a -> Word64Map a
binCheckLeft Word64
p Word64
m (Word64 -> Word64Map a -> Word64Map a
forall a. Word64 -> Word64Map a -> Word64Map a
delete Word64
k Word64Map a
l) Word64Map a
r
| Bool
otherwise = Word64 -> Word64 -> Word64Map a -> Word64Map a -> Word64Map a
forall a.
Word64 -> Word64 -> Word64Map a -> Word64Map a -> Word64Map a
binCheckRight Word64
p Word64
m Word64Map a
l (Word64 -> Word64Map a -> Word64Map a
forall a. Word64 -> Word64Map a -> Word64Map a
delete Word64
k Word64Map a
r)
delete Word64
k t :: Word64Map a
t@(Tip Word64
ky a
_)
| Word64
k Word64 -> Word64 -> Bool
forall a. Eq a => a -> a -> Bool
== Word64
ky = Word64Map a
forall a. Word64Map a
Nil
| Bool
otherwise = Word64Map a
t
delete Word64
_k Word64Map a
Nil = Word64Map a
forall a. Word64Map a
Nil
adjust :: (a -> a) -> Key -> Word64Map a -> Word64Map a
adjust :: forall a. (a -> a) -> Word64 -> Word64Map a -> Word64Map a
adjust a -> a
f Word64
k Word64Map a
m
= (Word64 -> a -> a) -> Word64 -> Word64Map a -> Word64Map a
forall a.
(Word64 -> a -> a) -> Word64 -> Word64Map a -> Word64Map a
adjustWithKey (\Word64
_ a
x -> a -> a
f a
x) Word64
k Word64Map a
m
adjustWithKey :: (Key -> a -> a) -> Key -> Word64Map a -> Word64Map a
adjustWithKey :: forall a.
(Word64 -> a -> a) -> Word64 -> Word64Map a -> Word64Map a
adjustWithKey Word64 -> a -> a
f !Word64
k (Bin Word64
p Word64
m Word64Map a
l Word64Map a
r)
| Word64 -> Word64 -> Bool
zero Word64
k Word64
m = Word64 -> Word64 -> Word64Map a -> Word64Map a -> Word64Map a
forall a.
Word64 -> Word64 -> Word64Map a -> Word64Map a -> Word64Map a
Bin Word64
p Word64
m ((Word64 -> a -> a) -> Word64 -> Word64Map a -> Word64Map a
forall a.
(Word64 -> a -> a) -> Word64 -> Word64Map a -> Word64Map a
adjustWithKey Word64 -> a -> a
f Word64
k Word64Map a
l) Word64Map a
r
| Bool
otherwise = Word64 -> Word64 -> Word64Map a -> Word64Map a -> Word64Map a
forall a.
Word64 -> Word64 -> Word64Map a -> Word64Map a -> Word64Map a
Bin Word64
p Word64
m Word64Map a
l ((Word64 -> a -> a) -> Word64 -> Word64Map a -> Word64Map a
forall a.
(Word64 -> a -> a) -> Word64 -> Word64Map a -> Word64Map a
adjustWithKey Word64 -> a -> a
f Word64
k Word64Map a
r)
adjustWithKey Word64 -> a -> a
f Word64
k t :: Word64Map a
t@(Tip Word64
ky a
y)
| Word64
k Word64 -> Word64 -> Bool
forall a. Eq a => a -> a -> Bool
== Word64
ky = Word64 -> a -> Word64Map a
forall a. Word64 -> a -> Word64Map a
Tip Word64
ky (Word64 -> a -> a
f Word64
k a
y)
| Bool
otherwise = Word64Map a
t
adjustWithKey Word64 -> a -> a
_ Word64
_ Word64Map a
Nil = Word64Map a
forall a. Word64Map a
Nil
update :: (a -> Maybe a) -> Key -> Word64Map a -> Word64Map a
update :: forall a. (a -> Maybe a) -> Word64 -> Word64Map a -> Word64Map a
update a -> Maybe a
f
= (Word64 -> a -> Maybe a) -> Word64 -> Word64Map a -> Word64Map a
forall a.
(Word64 -> a -> Maybe a) -> Word64 -> Word64Map a -> Word64Map a
updateWithKey (\Word64
_ a
x -> a -> Maybe a
f a
x)
updateWithKey :: (Key -> a -> Maybe a) -> Key -> Word64Map a -> Word64Map a
updateWithKey :: forall a.
(Word64 -> a -> Maybe a) -> Word64 -> Word64Map a -> Word64Map a
updateWithKey Word64 -> a -> Maybe a
f !Word64
k (Bin Word64
p Word64
m Word64Map a
l Word64Map a
r)
| Word64 -> Word64 -> Bool
zero Word64
k Word64
m = Word64 -> Word64 -> Word64Map a -> Word64Map a -> Word64Map a
forall a.
Word64 -> Word64 -> Word64Map a -> Word64Map a -> Word64Map a
binCheckLeft Word64
p Word64
m ((Word64 -> a -> Maybe a) -> Word64 -> Word64Map a -> Word64Map a
forall a.
(Word64 -> a -> Maybe a) -> Word64 -> Word64Map a -> Word64Map a
updateWithKey Word64 -> a -> Maybe a
f Word64
k Word64Map a
l) Word64Map a
r
| Bool
otherwise = Word64 -> Word64 -> Word64Map a -> Word64Map a -> Word64Map a
forall a.
Word64 -> Word64 -> Word64Map a -> Word64Map a -> Word64Map a
binCheckRight Word64
p Word64
m Word64Map a
l ((Word64 -> a -> Maybe a) -> Word64 -> Word64Map a -> Word64Map a
forall a.
(Word64 -> a -> Maybe a) -> Word64 -> Word64Map a -> Word64Map a
updateWithKey Word64 -> a -> Maybe a
f Word64
k Word64Map a
r)
updateWithKey Word64 -> a -> Maybe a
f Word64
k t :: Word64Map a
t@(Tip Word64
ky a
y)
| Word64
k Word64 -> Word64 -> Bool
forall a. Eq a => a -> a -> Bool
== Word64
ky = case (Word64 -> a -> Maybe a
f Word64
k a
y) of
Just a
y' -> Word64 -> a -> Word64Map a
forall a. Word64 -> a -> Word64Map a
Tip Word64
ky a
y'
Maybe a
Nothing -> Word64Map a
forall a. Word64Map a
Nil
| Bool
otherwise = Word64Map a
t
updateWithKey Word64 -> a -> Maybe a
_ Word64
_ Word64Map a
Nil = Word64Map a
forall a. Word64Map a
Nil
updateLookupWithKey :: (Key -> a -> Maybe a) -> Key -> Word64Map a -> (Maybe a,Word64Map a)
updateLookupWithKey :: forall a.
(Word64 -> a -> Maybe a)
-> Word64 -> Word64Map a -> (Maybe a, Word64Map a)
updateLookupWithKey Word64 -> a -> Maybe a
f !Word64
k (Bin Word64
p Word64
m Word64Map a
l Word64Map a
r)
| Word64 -> Word64 -> Bool
zero Word64
k Word64
m = let !(Maybe a
found,Word64Map a
l') = (Word64 -> a -> Maybe a)
-> Word64 -> Word64Map a -> (Maybe a, Word64Map a)
forall a.
(Word64 -> a -> Maybe a)
-> Word64 -> Word64Map a -> (Maybe a, Word64Map a)
updateLookupWithKey Word64 -> a -> Maybe a
f Word64
k Word64Map a
l
in (Maybe a
found,Word64 -> Word64 -> Word64Map a -> Word64Map a -> Word64Map a
forall a.
Word64 -> Word64 -> Word64Map a -> Word64Map a -> Word64Map a
binCheckLeft Word64
p Word64
m Word64Map a
l' Word64Map a
r)
| Bool
otherwise = let !(Maybe a
found,Word64Map a
r') = (Word64 -> a -> Maybe a)
-> Word64 -> Word64Map a -> (Maybe a, Word64Map a)
forall a.
(Word64 -> a -> Maybe a)
-> Word64 -> Word64Map a -> (Maybe a, Word64Map a)
updateLookupWithKey Word64 -> a -> Maybe a
f Word64
k Word64Map a
r
in (Maybe a
found,Word64 -> Word64 -> Word64Map a -> Word64Map a -> Word64Map a
forall a.
Word64 -> Word64 -> Word64Map a -> Word64Map a -> Word64Map a
binCheckRight Word64
p Word64
m Word64Map a
l Word64Map a
r')
updateLookupWithKey Word64 -> a -> Maybe a
f Word64
k t :: Word64Map a
t@(Tip Word64
ky a
y)
| Word64
kWord64 -> Word64 -> Bool
forall a. Eq a => a -> a -> Bool
==Word64
ky = case (Word64 -> a -> Maybe a
f Word64
k a
y) of
Just a
y' -> (a -> Maybe a
forall a. a -> Maybe a
Just a
y,Word64 -> a -> Word64Map a
forall a. Word64 -> a -> Word64Map a
Tip Word64
ky a
y')
Maybe a
Nothing -> (a -> Maybe a
forall a. a -> Maybe a
Just a
y,Word64Map a
forall a. Word64Map a
Nil)
| Bool
otherwise = (Maybe a
forall a. Maybe a
Nothing,Word64Map a
t)
updateLookupWithKey Word64 -> a -> Maybe a
_ Word64
_ Word64Map a
Nil = (Maybe a
forall a. Maybe a
Nothing,Word64Map a
forall a. Word64Map a
Nil)
alter :: (Maybe a -> Maybe a) -> Key -> Word64Map a -> Word64Map a
alter :: forall a.
(Maybe a -> Maybe a) -> Word64 -> Word64Map a -> Word64Map a
alter Maybe a -> Maybe a
f !Word64
k t :: Word64Map a
t@(Bin Word64
p Word64
m Word64Map a
l Word64Map a
r)
| Word64 -> Word64 -> Word64 -> Bool
nomatch Word64
k Word64
p Word64
m = case Maybe a -> Maybe a
f Maybe a
forall a. Maybe a
Nothing of
Maybe a
Nothing -> Word64Map a
t
Just a
x -> Word64 -> Word64Map a -> Word64 -> Word64Map a -> Word64Map a
forall a.
Word64 -> Word64Map a -> Word64 -> Word64Map a -> Word64Map a
link Word64
k (Word64 -> a -> Word64Map a
forall a. Word64 -> a -> Word64Map a
Tip Word64
k a
x) Word64
p Word64Map a
t
| Word64 -> Word64 -> Bool
zero Word64
k Word64
m = Word64 -> Word64 -> Word64Map a -> Word64Map a -> Word64Map a
forall a.
Word64 -> Word64 -> Word64Map a -> Word64Map a -> Word64Map a
binCheckLeft Word64
p Word64
m ((Maybe a -> Maybe a) -> Word64 -> Word64Map a -> Word64Map a
forall a.
(Maybe a -> Maybe a) -> Word64 -> Word64Map a -> Word64Map a
alter Maybe a -> Maybe a
f Word64
k Word64Map a
l) Word64Map a
r
| Bool
otherwise = Word64 -> Word64 -> Word64Map a -> Word64Map a -> Word64Map a
forall a.
Word64 -> Word64 -> Word64Map a -> Word64Map a -> Word64Map a
binCheckRight Word64
p Word64
m Word64Map a
l ((Maybe a -> Maybe a) -> Word64 -> Word64Map a -> Word64Map a
forall a.
(Maybe a -> Maybe a) -> Word64 -> Word64Map a -> Word64Map a
alter Maybe a -> Maybe a
f Word64
k Word64Map a
r)
alter Maybe a -> Maybe a
f Word64
k t :: Word64Map a
t@(Tip Word64
ky a
y)
| Word64
kWord64 -> Word64 -> Bool
forall a. Eq a => a -> a -> Bool
==Word64
ky = case Maybe a -> Maybe a
f (a -> Maybe a
forall a. a -> Maybe a
Just a
y) of
Just a
x -> Word64 -> a -> Word64Map a
forall a. Word64 -> a -> Word64Map a
Tip Word64
ky a
x
Maybe a
Nothing -> Word64Map a
forall a. Word64Map a
Nil
| Bool
otherwise = case Maybe a -> Maybe a
f Maybe a
forall a. Maybe a
Nothing of
Just a
x -> Word64 -> Word64Map a -> Word64 -> Word64Map a -> Word64Map a
forall a.
Word64 -> Word64Map a -> Word64 -> Word64Map a -> Word64Map a
link Word64
k (Word64 -> a -> Word64Map a
forall a. Word64 -> a -> Word64Map a
Tip Word64
k a
x) Word64
ky Word64Map a
t
Maybe a
Nothing -> Word64 -> a -> Word64Map a
forall a. Word64 -> a -> Word64Map a
Tip Word64
ky a
y
alter Maybe a -> Maybe a
f Word64
k Word64Map a
Nil = case Maybe a -> Maybe a
f Maybe a
forall a. Maybe a
Nothing of
Just a
x -> Word64 -> a -> Word64Map a
forall a. Word64 -> a -> Word64Map a
Tip Word64
k a
x
Maybe a
Nothing -> Word64Map a
forall a. Word64Map a
Nil
alterF :: Functor f
=> (Maybe a -> f (Maybe a)) -> Key -> Word64Map a -> f (Word64Map a)
alterF :: forall (f :: * -> *) a.
Functor f =>
(Maybe a -> f (Maybe a))
-> Word64 -> Word64Map a -> f (Word64Map a)
alterF Maybe a -> f (Maybe a)
f Word64
k Word64Map a
m = ((Maybe a -> Word64Map a) -> f (Maybe a) -> f (Word64Map a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe a -> f (Maybe a)
f Maybe a
mv) ((Maybe a -> Word64Map a) -> f (Word64Map a))
-> (Maybe a -> Word64Map a) -> f (Word64Map a)
forall a b. (a -> b) -> a -> b
$ \Maybe a
fres ->
case Maybe a
fres of
Maybe a
Nothing -> Word64Map a -> (a -> Word64Map a) -> Maybe a -> Word64Map a
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Word64Map a
m (Word64Map a -> a -> Word64Map a
forall a b. a -> b -> a
const (Word64 -> Word64Map a -> Word64Map a
forall a. Word64 -> Word64Map a -> Word64Map a
delete Word64
k Word64Map a
m)) Maybe a
mv
Just a
v' -> Word64 -> a -> Word64Map a -> Word64Map a
forall a. Word64 -> a -> Word64Map a -> Word64Map a
insert Word64
k a
v' Word64Map a
m
where mv :: Maybe a
mv = Word64 -> Word64Map a -> Maybe a
forall a. Word64 -> Word64Map a -> Maybe a
lookup Word64
k Word64Map a
m
unions :: Foldable f => f (Word64Map a) -> Word64Map a
unions :: forall (f :: * -> *) a.
Foldable f =>
f (Word64Map a) -> Word64Map a
unions f (Word64Map a)
xs
= (Word64Map a -> Word64Map a -> Word64Map a)
-> Word64Map a -> f (Word64Map a) -> Word64Map a
forall b a. (b -> a -> b) -> b -> f a -> b
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
Foldable.foldl' Word64Map a -> Word64Map a -> Word64Map a
forall a. Word64Map a -> Word64Map a -> Word64Map a
union Word64Map a
forall a. Word64Map a
empty f (Word64Map a)
xs
unionsWith :: Foldable f => (a->a->a) -> f (Word64Map a) -> Word64Map a
unionsWith :: forall (f :: * -> *) a.
Foldable f =>
(a -> a -> a) -> f (Word64Map a) -> Word64Map a
unionsWith a -> a -> a
f f (Word64Map a)
ts
= (Word64Map a -> Word64Map a -> Word64Map a)
-> Word64Map a -> f (Word64Map a) -> Word64Map a
forall b a. (b -> a -> b) -> b -> f a -> b
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
Foldable.foldl' ((a -> a -> a) -> Word64Map a -> Word64Map a -> Word64Map a
forall a.
(a -> a -> a) -> Word64Map a -> Word64Map a -> Word64Map a
unionWith a -> a -> a
f) Word64Map a
forall a. Word64Map a
empty f (Word64Map a)
ts
union :: Word64Map a -> Word64Map a -> Word64Map a
union :: forall a. Word64Map a -> Word64Map a -> Word64Map a
union Word64Map a
m1 Word64Map a
m2
= (Word64 -> Word64 -> Word64Map a -> Word64Map a -> Word64Map a)
-> (Word64Map a -> Word64Map a -> Word64Map a)
-> (Word64Map a -> Word64Map a)
-> (Word64Map a -> Word64Map a)
-> Word64Map a
-> Word64Map a
-> Word64Map a
forall c a b.
(Word64 -> Word64 -> 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
mergeWithKey' Word64 -> Word64 -> Word64Map a -> Word64Map a -> Word64Map a
forall a.
Word64 -> Word64 -> Word64Map a -> Word64Map a -> Word64Map a
Bin Word64Map a -> Word64Map a -> Word64Map a
forall a b. a -> b -> a
const Word64Map a -> Word64Map a
forall a. a -> a
id Word64Map a -> Word64Map a
forall a. a -> a
id Word64Map a
m1 Word64Map a
m2
unionWith :: (a -> a -> a) -> Word64Map a -> Word64Map a -> Word64Map a
unionWith :: forall a.
(a -> a -> a) -> Word64Map a -> Word64Map a -> Word64Map a
unionWith a -> a -> a
f Word64Map a
m1 Word64Map a
m2
= (Word64 -> a -> a -> a)
-> Word64Map a -> Word64Map a -> Word64Map a
forall a.
(Word64 -> a -> a -> a)
-> Word64Map a -> Word64Map a -> Word64Map a
unionWithKey (\Word64
_ a
x a
y -> a -> a -> a
f a
x a
y) Word64Map a
m1 Word64Map a
m2
unionWithKey :: (Key -> a -> a -> a) -> Word64Map a -> Word64Map a -> Word64Map a
unionWithKey :: forall a.
(Word64 -> a -> a -> a)
-> Word64Map a -> Word64Map a -> Word64Map a
unionWithKey Word64 -> a -> a -> a
f Word64Map a
m1 Word64Map a
m2
= (Word64 -> Word64 -> Word64Map a -> Word64Map a -> Word64Map a)
-> (Word64Map a -> Word64Map a -> Word64Map a)
-> (Word64Map a -> Word64Map a)
-> (Word64Map a -> Word64Map a)
-> Word64Map a
-> Word64Map a
-> Word64Map a
forall c a b.
(Word64 -> Word64 -> 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
mergeWithKey' Word64 -> Word64 -> Word64Map a -> Word64Map a -> Word64Map a
forall a.
Word64 -> Word64 -> Word64Map a -> Word64Map a -> Word64Map a
Bin (\(Tip Word64
k1 a
x1) (Tip Word64
_k2 a
x2) -> Word64 -> a -> Word64Map a
forall a. Word64 -> a -> Word64Map a
Tip Word64
k1 (Word64 -> a -> a -> a
f Word64
k1 a
x1 a
x2)) Word64Map a -> Word64Map a
forall a. a -> a
id Word64Map a -> Word64Map a
forall a. a -> a
id Word64Map a
m1 Word64Map a
m2
difference :: Word64Map a -> Word64Map b -> Word64Map a
difference :: forall a b. Word64Map a -> Word64Map b -> Word64Map a
difference Word64Map a
m1 Word64Map b
m2
= (Word64 -> a -> b -> Maybe a)
-> (Word64Map a -> Word64Map a)
-> (Word64Map b -> Word64Map a)
-> Word64Map a
-> Word64Map b
-> Word64Map a
forall a b c.
(Word64 -> a -> b -> Maybe c)
-> (Word64Map a -> Word64Map c)
-> (Word64Map b -> Word64Map c)
-> Word64Map a
-> Word64Map b
-> Word64Map c
mergeWithKey (\Word64
_ a
_ b
_ -> Maybe a
forall a. Maybe a
Nothing) Word64Map a -> Word64Map a
forall a. a -> a
id (Word64Map a -> Word64Map b -> Word64Map a
forall a b. a -> b -> a
const Word64Map a
forall a. Word64Map a
Nil) Word64Map a
m1 Word64Map b
m2
differenceWith :: (a -> b -> Maybe a) -> Word64Map a -> Word64Map b -> Word64Map a
differenceWith :: forall a b.
(a -> b -> Maybe a) -> Word64Map a -> Word64Map b -> Word64Map a
differenceWith a -> b -> Maybe a
f Word64Map a
m1 Word64Map b
m2
= (Word64 -> a -> b -> Maybe a)
-> Word64Map a -> Word64Map b -> Word64Map a
forall a b.
(Word64 -> a -> b -> Maybe a)
-> Word64Map a -> Word64Map b -> Word64Map a
differenceWithKey (\Word64
_ a
x b
y -> a -> b -> Maybe a
f a
x b
y) Word64Map a
m1 Word64Map b
m2
differenceWithKey :: (Key -> a -> b -> Maybe a) -> Word64Map a -> Word64Map b -> Word64Map a
differenceWithKey :: forall a b.
(Word64 -> a -> b -> Maybe a)
-> Word64Map a -> Word64Map b -> Word64Map a
differenceWithKey Word64 -> a -> b -> Maybe a
f Word64Map a
m1 Word64Map b
m2
= (Word64 -> a -> b -> Maybe a)
-> (Word64Map a -> Word64Map a)
-> (Word64Map b -> Word64Map a)
-> Word64Map a
-> Word64Map b
-> Word64Map a
forall a b c.
(Word64 -> a -> b -> Maybe c)
-> (Word64Map a -> Word64Map c)
-> (Word64Map b -> Word64Map c)
-> Word64Map a
-> Word64Map b
-> Word64Map c
mergeWithKey Word64 -> a -> b -> Maybe a
f Word64Map a -> Word64Map a
forall a. a -> a
id (Word64Map a -> Word64Map b -> Word64Map a
forall a b. a -> b -> a
const Word64Map a
forall a. Word64Map a
Nil) Word64Map a
m1 Word64Map b
m2
withoutKeys :: Word64Map a -> Word64Set.Word64Set -> Word64Map a
withoutKeys :: forall a. Word64Map a -> Word64Set -> Word64Map a
withoutKeys t1 :: Word64Map a
t1@(Bin Word64
p1 Word64
m1 Word64Map a
l1 Word64Map a
r1) t2 :: Word64Set
t2@(Word64Set.Bin Word64
p2 Word64
m2 Word64Set
l2 Word64Set
r2)
| Word64 -> Word64 -> Bool
shorter Word64
m1 Word64
m2 = Word64Map a
difference1
| Word64 -> Word64 -> Bool
shorter Word64
m2 Word64
m1 = Word64Map a
difference2
| Word64
p1 Word64 -> Word64 -> Bool
forall a. Eq a => a -> a -> Bool
== Word64
p2 = Word64 -> Word64 -> Word64Map a -> Word64Map a -> Word64Map a
forall a.
Word64 -> Word64 -> Word64Map a -> Word64Map a -> Word64Map a
bin Word64
p1 Word64
m1 (Word64Map a -> Word64Set -> Word64Map a
forall a. Word64Map a -> Word64Set -> Word64Map a
withoutKeys Word64Map a
l1 Word64Set
l2) (Word64Map a -> Word64Set -> Word64Map a
forall a. Word64Map a -> Word64Set -> Word64Map a
withoutKeys Word64Map a
r1 Word64Set
r2)
| Bool
otherwise = Word64Map a
t1
where
difference1 :: Word64Map a
difference1
| Word64 -> Word64 -> Word64 -> Bool
nomatch Word64
p2 Word64
p1 Word64
m1 = Word64Map a
t1
| Word64 -> Word64 -> Bool
zero Word64
p2 Word64
m1 = Word64 -> Word64 -> Word64Map a -> Word64Map a -> Word64Map a
forall a.
Word64 -> Word64 -> Word64Map a -> Word64Map a -> Word64Map a
binCheckLeft Word64
p1 Word64
m1 (Word64Map a -> Word64Set -> Word64Map a
forall a. Word64Map a -> Word64Set -> Word64Map a
withoutKeys Word64Map a
l1 Word64Set
t2) Word64Map a
r1
| Bool
otherwise = Word64 -> Word64 -> Word64Map a -> Word64Map a -> Word64Map a
forall a.
Word64 -> Word64 -> Word64Map a -> Word64Map a -> Word64Map a
binCheckRight Word64
p1 Word64
m1 Word64Map a
l1 (Word64Map a -> Word64Set -> Word64Map a
forall a. Word64Map a -> Word64Set -> Word64Map a
withoutKeys Word64Map a
r1 Word64Set
t2)
difference2 :: Word64Map a
difference2
| Word64 -> Word64 -> Word64 -> Bool
nomatch Word64
p1 Word64
p2 Word64
m2 = Word64Map a
t1
| Word64 -> Word64 -> Bool
zero Word64
p1 Word64
m2 = Word64Map a -> Word64Set -> Word64Map a
forall a. Word64Map a -> Word64Set -> Word64Map a
withoutKeys Word64Map a
t1 Word64Set
l2
| Bool
otherwise = Word64Map a -> Word64Set -> Word64Map a
forall a. Word64Map a -> Word64Set -> Word64Map a
withoutKeys Word64Map a
t1 Word64Set
r2
withoutKeys t1 :: Word64Map a
t1@(Bin Word64
p1 Word64
m1 Word64Map a
_ Word64Map a
_) (Word64Set.Tip Word64
p2 Word64
bm2) =
let minbit :: Word64
minbit = Word64 -> Word64
bitmapOf Word64
p1
lt_minbit :: Word64
lt_minbit = Word64
minbit Word64 -> Word64 -> Word64
forall a. Num a => a -> a -> a
- Word64
1
maxbit :: Word64
maxbit = Word64 -> Word64
bitmapOf (Word64
p1 Word64 -> Word64 -> Word64
forall a. Bits a => a -> a -> a
.|. (Word64
m1 Word64 -> Word64 -> Word64
forall a. Bits a => a -> a -> a
.|. (Word64
m1 Word64 -> Word64 -> Word64
forall a. Num a => a -> a -> a
- Word64
1)))
gt_maxbit :: Word64
gt_maxbit = (-Word64
maxbit) Word64 -> Word64 -> Word64
forall a. Bits a => a -> a -> a
`xor` Word64
maxbit
in Word64
-> Word64Map a -> (Word64Map a -> Word64Map a) -> Word64Map a
forall a.
Word64
-> Word64Map a -> (Word64Map a -> Word64Map a) -> Word64Map a
updatePrefix Word64
p2 Word64Map a
t1 ((Word64Map a -> Word64Map a) -> Word64Map a)
-> (Word64Map a -> Word64Map a) -> Word64Map a
forall a b. (a -> b) -> a -> b
$ Word64 -> Word64Map a -> Word64Map a
forall a. Word64 -> Word64Map a -> Word64Map a
withoutBM (Word64
bm2 Word64 -> Word64 -> Word64
forall a. Bits a => a -> a -> a
.|. Word64
lt_minbit Word64 -> Word64 -> Word64
forall a. Bits a => a -> a -> a
.|. Word64
gt_maxbit)
withoutKeys t1 :: Word64Map a
t1@(Bin Word64
_ Word64
_ Word64Map a
_ Word64Map a
_) Word64Set
Word64Set.Nil = Word64Map a
t1
withoutKeys t1 :: Word64Map a
t1@(Tip Word64
k1 a
_) Word64Set
t2
| Word64
k1 Word64 -> Word64Set -> Bool
`Word64Set.member` Word64Set
t2 = Word64Map a
forall a. Word64Map a
Nil
| Bool
otherwise = Word64Map a
t1
withoutKeys Word64Map a
Nil Word64Set
_ = Word64Map a
forall a. Word64Map a
Nil
updatePrefix
:: Word64SetPrefix -> Word64Map a -> (Word64Map a -> Word64Map a) -> Word64Map a
updatePrefix :: forall a.
Word64
-> Word64Map a -> (Word64Map a -> Word64Map a) -> Word64Map a
updatePrefix !Word64
kp t :: Word64Map a
t@(Bin Word64
p Word64
m Word64Map a
l Word64Map a
r) Word64Map a -> Word64Map a
f
| Word64
m Word64 -> Word64 -> Word64
forall a. Bits a => a -> a -> a
.&. Word64
Word64Set.suffixBitMask Word64 -> Word64 -> Bool
forall a. Eq a => a -> a -> Bool
/= Word64
0 =
if Word64
p Word64 -> Word64 -> Word64
forall a. Bits a => a -> a -> a
.&. Word64
Word64Set.prefixBitMask Word64 -> Word64 -> Bool
forall a. Eq a => a -> a -> Bool
== Word64
kp then Word64Map a -> Word64Map a
f Word64Map a
t else Word64Map a
t
| Word64 -> Word64 -> Word64 -> Bool
nomatch Word64
kp Word64
p Word64
m = Word64Map a
t
| Word64 -> Word64 -> Bool
zero Word64
kp Word64
m = Word64 -> Word64 -> Word64Map a -> Word64Map a -> Word64Map a
forall a.
Word64 -> Word64 -> Word64Map a -> Word64Map a -> Word64Map a
binCheckLeft Word64
p Word64
m (Word64
-> Word64Map a -> (Word64Map a -> Word64Map a) -> Word64Map a
forall a.
Word64
-> Word64Map a -> (Word64Map a -> Word64Map a) -> Word64Map a
updatePrefix Word64
kp Word64Map a
l Word64Map a -> Word64Map a
f) Word64Map a
r
| Bool
otherwise = Word64 -> Word64 -> Word64Map a -> Word64Map a -> Word64Map a
forall a.
Word64 -> Word64 -> Word64Map a -> Word64Map a -> Word64Map a
binCheckRight Word64
p Word64
m Word64Map a
l (Word64
-> Word64Map a -> (Word64Map a -> Word64Map a) -> Word64Map a
forall a.
Word64
-> Word64Map a -> (Word64Map a -> Word64Map a) -> Word64Map a
updatePrefix Word64
kp Word64Map a
r Word64Map a -> Word64Map a
f)
updatePrefix Word64
kp t :: Word64Map a
t@(Tip Word64
kx a
_) Word64Map a -> Word64Map a
f
| Word64
kx Word64 -> Word64 -> Word64
forall a. Bits a => a -> a -> a
.&. Word64
Word64Set.prefixBitMask Word64 -> Word64 -> Bool
forall a. Eq a => a -> a -> Bool
== Word64
kp = Word64Map a -> Word64Map a
f Word64Map a
t
| Bool
otherwise = Word64Map a
t
updatePrefix Word64
_ Word64Map a
Nil Word64Map a -> Word64Map a
_ = Word64Map a
forall a. Word64Map a
Nil
withoutBM :: Word64SetBitMap -> Word64Map a -> Word64Map a
withoutBM :: forall a. Word64 -> Word64Map a -> Word64Map a
withoutBM Word64
0 Word64Map a
t = Word64Map a
t
withoutBM Word64
bm (Bin Word64
p Word64
m Word64Map a
l Word64Map a
r) =
let leftBits :: Word64
leftBits = Word64 -> Word64
bitmapOf (Word64
p Word64 -> Word64 -> Word64
forall a. Bits a => a -> a -> a
.|. Word64
m) Word64 -> Word64 -> Word64
forall a. Num a => a -> a -> a
- Word64
1
bmL :: Word64
bmL = Word64
bm Word64 -> Word64 -> Word64
forall a. Bits a => a -> a -> a
.&. Word64
leftBits
bmR :: Word64
bmR = Word64
bm Word64 -> Word64 -> Word64
forall a. Bits a => a -> a -> a
`xor` Word64
bmL
in Word64 -> Word64 -> Word64Map a -> Word64Map a -> Word64Map a
forall a.
Word64 -> Word64 -> Word64Map a -> Word64Map a -> Word64Map a
bin Word64
p Word64
m (Word64 -> Word64Map a -> Word64Map a
forall a. Word64 -> Word64Map a -> Word64Map a
withoutBM Word64
bmL Word64Map a
l) (Word64 -> Word64Map a -> Word64Map a
forall a. Word64 -> Word64Map a -> Word64Map a
withoutBM Word64
bmR Word64Map a
r)
withoutBM Word64
bm t :: Word64Map a
t@(Tip Word64
k a
_)
| Word64
k Word64 -> Word64Set -> Bool
`Word64Set.member` Word64 -> Word64 -> Word64Set
Word64Set.Tip (Word64
k Word64 -> Word64 -> Word64
forall a. Bits a => a -> a -> a
.&. Word64
Word64Set.prefixBitMask) Word64
bm = Word64Map a
forall a. Word64Map a
Nil
| Bool
otherwise = Word64Map a
t
withoutBM Word64
_ Word64Map a
Nil = Word64Map a
forall a. Word64Map a
Nil
intersection :: Word64Map a -> Word64Map b -> Word64Map a
intersection :: forall a b. Word64Map a -> Word64Map b -> Word64Map a
intersection Word64Map a
m1 Word64Map b
m2
= (Word64 -> Word64 -> Word64Map a -> Word64Map a -> Word64Map a)
-> (Word64Map a -> Word64Map b -> Word64Map a)
-> (Word64Map a -> Word64Map a)
-> (Word64Map b -> Word64Map a)
-> Word64Map a
-> Word64Map b
-> Word64Map a
forall c a b.
(Word64 -> Word64 -> 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
mergeWithKey' Word64 -> Word64 -> Word64Map a -> Word64Map a -> Word64Map a
forall a.
Word64 -> Word64 -> Word64Map a -> Word64Map a -> Word64Map a
bin Word64Map a -> Word64Map b -> Word64Map a
forall a b. a -> b -> a
const (Word64Map a -> Word64Map a -> Word64Map a
forall a b. a -> b -> a
const Word64Map a
forall a. Word64Map a
Nil) (Word64Map a -> Word64Map b -> Word64Map a
forall a b. a -> b -> a
const Word64Map a
forall a. Word64Map a
Nil) Word64Map a
m1 Word64Map b
m2
restrictKeys :: Word64Map a -> Word64Set.Word64Set -> Word64Map a
restrictKeys :: forall a. Word64Map a -> Word64Set -> Word64Map a
restrictKeys t1 :: Word64Map a
t1@(Bin Word64
p1 Word64
m1 Word64Map a
l1 Word64Map a
r1) t2 :: Word64Set
t2@(Word64Set.Bin Word64
p2 Word64
m2 Word64Set
l2 Word64Set
r2)
| Word64 -> Word64 -> Bool
shorter Word64
m1 Word64
m2 = Word64Map a
intersection1
| Word64 -> Word64 -> Bool
shorter Word64
m2 Word64
m1 = Word64Map a
intersection2
| Word64
p1 Word64 -> Word64 -> Bool
forall a. Eq a => a -> a -> Bool
== Word64
p2 = Word64 -> Word64 -> Word64Map a -> Word64Map a -> Word64Map a
forall a.
Word64 -> Word64 -> Word64Map a -> Word64Map a -> Word64Map a
bin Word64
p1 Word64
m1 (Word64Map a -> Word64Set -> Word64Map a
forall a. Word64Map a -> Word64Set -> Word64Map a
restrictKeys Word64Map a
l1 Word64Set
l2) (Word64Map a -> Word64Set -> Word64Map a
forall a. Word64Map a -> Word64Set -> Word64Map a
restrictKeys Word64Map a
r1 Word64Set
r2)
| Bool
otherwise = Word64Map a
forall a. Word64Map a
Nil
where
intersection1 :: Word64Map a
intersection1
| Word64 -> Word64 -> Word64 -> Bool
nomatch Word64
p2 Word64
p1 Word64
m1 = Word64Map a
forall a. Word64Map a
Nil
| Word64 -> Word64 -> Bool
zero Word64
p2 Word64
m1 = Word64Map a -> Word64Set -> Word64Map a
forall a. Word64Map a -> Word64Set -> Word64Map a
restrictKeys Word64Map a
l1 Word64Set
t2
| Bool
otherwise = Word64Map a -> Word64Set -> Word64Map a
forall a. Word64Map a -> Word64Set -> Word64Map a
restrictKeys Word64Map a
r1 Word64Set
t2
intersection2 :: Word64Map a
intersection2
| Word64 -> Word64 -> Word64 -> Bool
nomatch Word64
p1 Word64
p2 Word64
m2 = Word64Map a
forall a. Word64Map a
Nil
| Word64 -> Word64 -> Bool
zero Word64
p1 Word64
m2 = Word64Map a -> Word64Set -> Word64Map a
forall a. Word64Map a -> Word64Set -> Word64Map a
restrictKeys Word64Map a
t1 Word64Set
l2
| Bool
otherwise = Word64Map a -> Word64Set -> Word64Map a
forall a. Word64Map a -> Word64Set -> Word64Map a
restrictKeys Word64Map a
t1 Word64Set
r2
restrictKeys t1 :: Word64Map a
t1@(Bin Word64
p1 Word64
m1 Word64Map a
_ Word64Map a
_) (Word64Set.Tip Word64
p2 Word64
bm2) =
let minbit :: Word64
minbit = Word64 -> Word64
bitmapOf Word64
p1
ge_minbit :: Word64
ge_minbit = Word64 -> Word64
forall a. Bits a => a -> a
complement (Word64
minbit Word64 -> Word64 -> Word64
forall a. Num a => a -> a -> a
- Word64
1)
maxbit :: Word64
maxbit = Word64 -> Word64
bitmapOf (Word64
p1 Word64 -> Word64 -> Word64
forall a. Bits a => a -> a -> a
.|. (Word64
m1 Word64 -> Word64 -> Word64
forall a. Bits a => a -> a -> a
.|. (Word64
m1 Word64 -> Word64 -> Word64
forall a. Num a => a -> a -> a
- Word64
1)))
le_maxbit :: Word64
le_maxbit = Word64
maxbit Word64 -> Word64 -> Word64
forall a. Bits a => a -> a -> a
.|. (Word64
maxbit Word64 -> Word64 -> Word64
forall a. Num a => a -> a -> a
- Word64
1)
in Word64 -> Word64Map a -> Word64Map a
forall a. Word64 -> Word64Map a -> Word64Map a
restrictBM (Word64
bm2 Word64 -> Word64 -> Word64
forall a. Bits a => a -> a -> a
.&. Word64
ge_minbit Word64 -> Word64 -> Word64
forall a. Bits a => a -> a -> a
.&. Word64
le_maxbit) (Word64 -> Word64Map a -> Word64Map a
forall a. Word64 -> Word64Map a -> Word64Map a
lookupPrefix Word64
p2 Word64Map a
t1)
restrictKeys (Bin Word64
_ Word64
_ Word64Map a
_ Word64Map a
_) Word64Set
Word64Set.Nil = Word64Map a
forall a. Word64Map a
Nil
restrictKeys t1 :: Word64Map a
t1@(Tip Word64
k1 a
_) Word64Set
t2
| Word64
k1 Word64 -> Word64Set -> Bool
`Word64Set.member` Word64Set
t2 = Word64Map a
t1
| Bool
otherwise = Word64Map a
forall a. Word64Map a
Nil
restrictKeys Word64Map a
Nil Word64Set
_ = Word64Map a
forall a. Word64Map a
Nil
lookupPrefix :: Word64SetPrefix -> Word64Map a -> Word64Map a
lookupPrefix :: forall a. Word64 -> Word64Map a -> Word64Map a
lookupPrefix !Word64
kp t :: Word64Map a
t@(Bin Word64
p Word64
m Word64Map a
l Word64Map a
r)
| Word64
m Word64 -> Word64 -> Word64
forall a. Bits a => a -> a -> a
.&. Word64
Word64Set.suffixBitMask Word64 -> Word64 -> Bool
forall a. Eq a => a -> a -> Bool
/= Word64
0 =
if Word64
p Word64 -> Word64 -> Word64
forall a. Bits a => a -> a -> a
.&. Word64
Word64Set.prefixBitMask Word64 -> Word64 -> Bool
forall a. Eq a => a -> a -> Bool
== Word64
kp then Word64Map a
t else Word64Map a
forall a. Word64Map a
Nil
| Word64 -> Word64 -> Word64 -> Bool
nomatch Word64
kp Word64
p Word64
m = Word64Map a
forall a. Word64Map a
Nil
| Word64 -> Word64 -> Bool
zero Word64
kp Word64
m = Word64 -> Word64Map a -> Word64Map a
forall a. Word64 -> Word64Map a -> Word64Map a
lookupPrefix Word64
kp Word64Map a
l
| Bool
otherwise = Word64 -> Word64Map a -> Word64Map a
forall a. Word64 -> Word64Map a -> Word64Map a
lookupPrefix Word64
kp Word64Map a
r
lookupPrefix Word64
kp t :: Word64Map a
t@(Tip Word64
kx a
_)
| (Word64
kx Word64 -> Word64 -> Word64
forall a. Bits a => a -> a -> a
.&. Word64
Word64Set.prefixBitMask) Word64 -> Word64 -> Bool
forall a. Eq a => a -> a -> Bool
== Word64
kp = Word64Map a
t
| Bool
otherwise = Word64Map a
forall a. Word64Map a
Nil
lookupPrefix Word64
_ Word64Map a
Nil = Word64Map a
forall a. Word64Map a
Nil
restrictBM :: Word64SetBitMap -> Word64Map a -> Word64Map a
restrictBM :: forall a. Word64 -> Word64Map a -> Word64Map a
restrictBM Word64
0 Word64Map a
_ = Word64Map a
forall a. Word64Map a
Nil
restrictBM Word64
bm (Bin Word64
p Word64
m Word64Map a
l Word64Map a
r) =
let leftBits :: Word64
leftBits = Word64 -> Word64
bitmapOf (Word64
p Word64 -> Word64 -> Word64
forall a. Bits a => a -> a -> a
.|. Word64
m) Word64 -> Word64 -> Word64
forall a. Num a => a -> a -> a
- Word64
1
bmL :: Word64
bmL = Word64
bm Word64 -> Word64 -> Word64
forall a. Bits a => a -> a -> a
.&. Word64
leftBits
bmR :: Word64
bmR = Word64
bm Word64 -> Word64 -> Word64
forall a. Bits a => a -> a -> a
`xor` Word64
bmL
in Word64 -> Word64 -> Word64Map a -> Word64Map a -> Word64Map a
forall a.
Word64 -> Word64 -> Word64Map a -> Word64Map a -> Word64Map a
bin Word64
p Word64
m (Word64 -> Word64Map a -> Word64Map a
forall a. Word64 -> Word64Map a -> Word64Map a
restrictBM Word64
bmL Word64Map a
l) (Word64 -> Word64Map a -> Word64Map a
forall a. Word64 -> Word64Map a -> Word64Map a
restrictBM Word64
bmR Word64Map a
r)
restrictBM Word64
bm t :: Word64Map a
t@(Tip Word64
k a
_)
| Word64
k Word64 -> Word64Set -> Bool
`Word64Set.member` Word64 -> Word64 -> Word64Set
Word64Set.Tip (Word64
k Word64 -> Word64 -> Word64
forall a. Bits a => a -> a -> a
.&. Word64
Word64Set.prefixBitMask) Word64
bm = Word64Map a
t
| Bool
otherwise = Word64Map a
forall a. Word64Map a
Nil
restrictBM Word64
_ Word64Map a
Nil = Word64Map a
forall a. Word64Map a
Nil
intersectionWith :: (a -> b -> c) -> Word64Map a -> Word64Map b -> Word64Map c
intersectionWith :: forall a b c.
(a -> b -> c) -> Word64Map a -> Word64Map b -> Word64Map c
intersectionWith a -> b -> c
f Word64Map a
m1 Word64Map b
m2
= (Word64 -> a -> b -> c)
-> Word64Map a -> Word64Map b -> Word64Map c
forall a b c.
(Word64 -> a -> b -> c)
-> Word64Map a -> Word64Map b -> Word64Map c
intersectionWithKey (\Word64
_ a
x b
y -> a -> b -> c
f a
x b
y) Word64Map a
m1 Word64Map b
m2
intersectionWithKey :: (Key -> a -> b -> c) -> Word64Map a -> Word64Map b -> Word64Map c
intersectionWithKey :: forall a b c.
(Word64 -> a -> b -> c)
-> Word64Map a -> Word64Map b -> Word64Map c
intersectionWithKey Word64 -> a -> b -> c
f Word64Map a
m1 Word64Map b
m2
= (Word64 -> Word64 -> 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
forall c a b.
(Word64 -> Word64 -> 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
mergeWithKey' Word64 -> Word64 -> Word64Map c -> Word64Map c -> Word64Map c
forall a.
Word64 -> Word64 -> Word64Map a -> Word64Map a -> Word64Map a
bin (\(Tip Word64
k1 a
x1) (Tip Word64
_k2 b
x2) -> Word64 -> c -> Word64Map c
forall a. Word64 -> a -> Word64Map a
Tip Word64
k1 (Word64 -> a -> b -> c
f Word64
k1 a
x1 b
x2)) (Word64Map c -> Word64Map a -> Word64Map c
forall a b. a -> b -> a
const Word64Map c
forall a. Word64Map a
Nil) (Word64Map c -> Word64Map b -> Word64Map c
forall a b. a -> b -> a
const Word64Map c
forall a. Word64Map a
Nil) Word64Map a
m1 Word64Map b
m2
mergeWithKey :: (Key -> a -> b -> Maybe c) -> (Word64Map a -> Word64Map c) -> (Word64Map b -> Word64Map c)
-> Word64Map a -> Word64Map b -> Word64Map c
mergeWithKey :: forall a b c.
(Word64 -> a -> b -> Maybe c)
-> (Word64Map a -> Word64Map c)
-> (Word64Map b -> Word64Map c)
-> Word64Map a
-> Word64Map b
-> Word64Map c
mergeWithKey Word64 -> a -> b -> Maybe c
f Word64Map a -> Word64Map c
g1 Word64Map b -> Word64Map c
g2 = (Word64 -> Word64 -> 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
forall c a b.
(Word64 -> Word64 -> 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
mergeWithKey' Word64 -> Word64 -> Word64Map c -> Word64Map c -> Word64Map c
forall a.
Word64 -> Word64 -> Word64Map a -> Word64Map a -> Word64Map a
bin Word64Map a -> Word64Map b -> Word64Map c
combine Word64Map a -> Word64Map c
g1 Word64Map b -> Word64Map c
g2
where
combine :: Word64Map a -> Word64Map b -> Word64Map c
combine = \(Tip Word64
k1 a
x1) (Tip Word64
_k2 b
x2) ->
case Word64 -> a -> b -> Maybe c
f Word64
k1 a
x1 b
x2 of
Maybe c
Nothing -> Word64Map c
forall a. Word64Map a
Nil
Just c
x -> Word64 -> c -> Word64Map c
forall a. Word64 -> a -> Word64Map a
Tip Word64
k1 c
x
{-# INLINE combine #-}
{-# INLINE mergeWithKey #-}
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
mergeWithKey' :: forall c a b.
(Word64 -> Word64 -> 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
mergeWithKey' Word64 -> Word64 -> Word64Map c -> Word64Map c -> Word64Map c
bin' Word64Map a -> Word64Map b -> Word64Map c
f Word64Map a -> Word64Map c
g1 Word64Map b -> Word64Map c
g2 = Word64Map a -> Word64Map b -> Word64Map c
go
where
go :: Word64Map a -> Word64Map b -> Word64Map c
go t1 :: Word64Map a
t1@(Bin Word64
p1 Word64
m1 Word64Map a
l1 Word64Map a
r1) t2 :: Word64Map b
t2@(Bin Word64
p2 Word64
m2 Word64Map b
l2 Word64Map b
r2)
| Word64 -> Word64 -> Bool
shorter Word64
m1 Word64
m2 = Word64Map c
merge1
| Word64 -> Word64 -> Bool
shorter Word64
m2 Word64
m1 = Word64Map c
merge2
| Word64
p1 Word64 -> Word64 -> Bool
forall a. Eq a => a -> a -> Bool
== Word64
p2 = Word64 -> Word64 -> Word64Map c -> Word64Map c -> Word64Map c
bin' Word64
p1 Word64
m1 (Word64Map a -> Word64Map b -> Word64Map c
go Word64Map a
l1 Word64Map b
l2) (Word64Map a -> Word64Map b -> Word64Map c
go Word64Map a
r1 Word64Map b
r2)
| Bool
otherwise = Word64 -> Word64Map c -> Word64 -> Word64Map c -> Word64Map c
forall a.
Word64 -> Word64Map a -> Word64 -> Word64Map a -> Word64Map a
maybe_link Word64
p1 (Word64Map a -> Word64Map c
g1 Word64Map a
t1) Word64
p2 (Word64Map b -> Word64Map c
g2 Word64Map b
t2)
where
merge1 :: Word64Map c
merge1 | Word64 -> Word64 -> Word64 -> Bool
nomatch Word64
p2 Word64
p1 Word64
m1 = Word64 -> Word64Map c -> Word64 -> Word64Map c -> Word64Map c
forall a.
Word64 -> Word64Map a -> Word64 -> Word64Map a -> Word64Map a
maybe_link Word64
p1 (Word64Map a -> Word64Map c
g1 Word64Map a
t1) Word64
p2 (Word64Map b -> Word64Map c
g2 Word64Map b
t2)
| Word64 -> Word64 -> Bool
zero Word64
p2 Word64
m1 = Word64 -> Word64 -> Word64Map c -> Word64Map c -> Word64Map c
bin' Word64
p1 Word64
m1 (Word64Map a -> Word64Map b -> Word64Map c
go Word64Map a
l1 Word64Map b
t2) (Word64Map a -> Word64Map c
g1 Word64Map a
r1)
| Bool
otherwise = Word64 -> Word64 -> Word64Map c -> Word64Map c -> Word64Map c
bin' Word64
p1 Word64
m1 (Word64Map a -> Word64Map c
g1 Word64Map a
l1) (Word64Map a -> Word64Map b -> Word64Map c
go Word64Map a
r1 Word64Map b
t2)
merge2 :: Word64Map c
merge2 | Word64 -> Word64 -> Word64 -> Bool
nomatch Word64
p1 Word64
p2 Word64
m2 = Word64 -> Word64Map c -> Word64 -> Word64Map c -> Word64Map c
forall a.
Word64 -> Word64Map a -> Word64 -> Word64Map a -> Word64Map a
maybe_link Word64
p1 (Word64Map a -> Word64Map c
g1 Word64Map a
t1) Word64
p2 (Word64Map b -> Word64Map c
g2 Word64Map b
t2)
| Word64 -> Word64 -> Bool
zero Word64
p1 Word64
m2 = Word64 -> Word64 -> Word64Map c -> Word64Map c -> Word64Map c
bin' Word64
p2 Word64
m2 (Word64Map a -> Word64Map b -> Word64Map c
go Word64Map a
t1 Word64Map b
l2) (Word64Map b -> Word64Map c
g2 Word64Map b
r2)
| Bool
otherwise = Word64 -> Word64 -> Word64Map c -> Word64Map c -> Word64Map c
bin' Word64
p2 Word64
m2 (Word64Map b -> Word64Map c
g2 Word64Map b
l2) (Word64Map a -> Word64Map b -> Word64Map c
go Word64Map a
t1 Word64Map b
r2)
go t1' :: Word64Map a
t1'@(Bin Word64
_ Word64
_ Word64Map a
_ Word64Map a
_) t2' :: Word64Map b
t2'@(Tip Word64
k2' b
_) = Word64Map b -> Word64 -> Word64Map a -> Word64Map c
merge0 Word64Map b
t2' Word64
k2' Word64Map a
t1'
where
merge0 :: Word64Map b -> Word64 -> Word64Map a -> Word64Map c
merge0 Word64Map b
t2 Word64
k2 t1 :: Word64Map a
t1@(Bin Word64
p1 Word64
m1 Word64Map a
l1 Word64Map a
r1)
| Word64 -> Word64 -> Word64 -> Bool
nomatch Word64
k2 Word64
p1 Word64
m1 = Word64 -> Word64Map c -> Word64 -> Word64Map c -> Word64Map c
forall a.
Word64 -> Word64Map a -> Word64 -> Word64Map a -> Word64Map a
maybe_link Word64
p1 (Word64Map a -> Word64Map c
g1 Word64Map a
t1) Word64
k2 (Word64Map b -> Word64Map c
g2 Word64Map b
t2)
| Word64 -> Word64 -> Bool
zero Word64
k2 Word64
m1 = Word64 -> Word64 -> Word64Map c -> Word64Map c -> Word64Map c
bin' Word64
p1 Word64
m1 (Word64Map b -> Word64 -> Word64Map a -> Word64Map c
merge0 Word64Map b
t2 Word64
k2 Word64Map a
l1) (Word64Map a -> Word64Map c
g1 Word64Map a
r1)
| Bool
otherwise = Word64 -> Word64 -> Word64Map c -> Word64Map c -> Word64Map c
bin' Word64
p1 Word64
m1 (Word64Map a -> Word64Map c
g1 Word64Map a
l1) (Word64Map b -> Word64 -> Word64Map a -> Word64Map c
merge0 Word64Map b
t2 Word64
k2 Word64Map a
r1)
merge0 Word64Map b
t2 Word64
k2 t1 :: Word64Map a
t1@(Tip Word64
k1 a
_)
| Word64
k1 Word64 -> Word64 -> Bool
forall a. Eq a => a -> a -> Bool
== Word64
k2 = Word64Map a -> Word64Map b -> Word64Map c
f Word64Map a
t1 Word64Map b
t2
| Bool
otherwise = Word64 -> Word64Map c -> Word64 -> Word64Map c -> Word64Map c
forall a.
Word64 -> Word64Map a -> Word64 -> Word64Map a -> Word64Map a
maybe_link Word64
k1 (Word64Map a -> Word64Map c
g1 Word64Map a
t1) Word64
k2 (Word64Map b -> Word64Map c
g2 Word64Map b
t2)
merge0 Word64Map b
t2 Word64
_ Word64Map a
Nil = Word64Map b -> Word64Map c
g2 Word64Map b
t2
go t1 :: Word64Map a
t1@(Bin Word64
_ Word64
_ Word64Map a
_ Word64Map a
_) Word64Map b
Nil = Word64Map a -> Word64Map c
g1 Word64Map a
t1
go t1' :: Word64Map a
t1'@(Tip Word64
k1' a
_) Word64Map b
t2' = Word64Map a -> Word64 -> Word64Map b -> Word64Map c
merge0 Word64Map a
t1' Word64
k1' Word64Map b
t2'
where
merge0 :: Word64Map a -> Word64 -> Word64Map b -> Word64Map c
merge0 Word64Map a
t1 Word64
k1 t2 :: Word64Map b
t2@(Bin Word64
p2 Word64
m2 Word64Map b
l2 Word64Map b
r2)
| Word64 -> Word64 -> Word64 -> Bool
nomatch Word64
k1 Word64
p2 Word64
m2 = Word64 -> Word64Map c -> Word64 -> Word64Map c -> Word64Map c
forall a.
Word64 -> Word64Map a -> Word64 -> Word64Map a -> Word64Map a
maybe_link Word64
k1 (Word64Map a -> Word64Map c
g1 Word64Map a
t1) Word64
p2 (Word64Map b -> Word64Map c
g2 Word64Map b
t2)
| Word64 -> Word64 -> Bool
zero Word64
k1 Word64
m2 = Word64 -> Word64 -> Word64Map c -> Word64Map c -> Word64Map c
bin' Word64
p2 Word64
m2 (Word64Map a -> Word64 -> Word64Map b -> Word64Map c
merge0 Word64Map a
t1 Word64
k1 Word64Map b
l2) (Word64Map b -> Word64Map c
g2 Word64Map b
r2)
| Bool
otherwise = Word64 -> Word64 -> Word64Map c -> Word64Map c -> Word64Map c
bin' Word64
p2 Word64
m2 (Word64Map b -> Word64Map c
g2 Word64Map b
l2) (Word64Map a -> Word64 -> Word64Map b -> Word64Map c
merge0 Word64Map a
t1 Word64
k1 Word64Map b
r2)
merge0 Word64Map a
t1 Word64
k1 t2 :: Word64Map b
t2@(Tip Word64
k2 b
_)
| Word64
k1 Word64 -> Word64 -> Bool
forall a. Eq a => a -> a -> Bool
== Word64
k2 = Word64Map a -> Word64Map b -> Word64Map c
f Word64Map a
t1 Word64Map b
t2
| Bool
otherwise = Word64 -> Word64Map c -> Word64 -> Word64Map c -> Word64Map c
forall a.
Word64 -> Word64Map a -> Word64 -> Word64Map a -> Word64Map a
maybe_link Word64
k1 (Word64Map a -> Word64Map c
g1 Word64Map a
t1) Word64
k2 (Word64Map b -> Word64Map c
g2 Word64Map b
t2)
merge0 Word64Map a
t1 Word64
_ Word64Map b
Nil = Word64Map a -> Word64Map c
g1 Word64Map a
t1
go Word64Map a
Nil Word64Map b
t2 = Word64Map b -> Word64Map c
g2 Word64Map b
t2
maybe_link :: Word64 -> Word64Map a -> Word64 -> Word64Map a -> Word64Map a
maybe_link Word64
_ Word64Map a
Nil Word64
_ Word64Map a
t2 = Word64Map a
t2
maybe_link Word64
_ Word64Map a
t1 Word64
_ Word64Map a
Nil = Word64Map a
t1
maybe_link Word64
p1 Word64Map a
t1 Word64
p2 Word64Map a
t2 = Word64 -> Word64Map a -> Word64 -> Word64Map a -> Word64Map a
forall a.
Word64 -> Word64Map a -> Word64 -> Word64Map a -> Word64Map a
link Word64
p1 Word64Map a
t1 Word64
p2 Word64Map a
t2
{-# INLINE maybe_link #-}
{-# INLINE mergeWithKey' #-}
data WhenMissing f x y = WhenMissing
{ forall (f :: * -> *) x y.
WhenMissing f x y -> Word64Map x -> f (Word64Map y)
missingSubtree :: Word64Map x -> f (Word64Map y)
, forall (f :: * -> *) x y.
WhenMissing f x y -> Word64 -> x -> f (Maybe y)
missingKey :: Key -> x -> f (Maybe y)}
instance (Applicative f, Monad f) => Functor (WhenMissing f x) where
fmap :: forall a b. (a -> b) -> WhenMissing f x a -> WhenMissing f x b
fmap = (a -> b) -> WhenMissing f x a -> WhenMissing f x b
forall (f :: * -> *) a b x.
(Applicative f, Monad f) =>
(a -> b) -> WhenMissing f x a -> WhenMissing f x b
mapWhenMissing
{-# INLINE fmap #-}
instance (Applicative f, Monad f) => Category.Category (WhenMissing f)
where
id :: forall a. WhenMissing f a a
id = WhenMissing f a a
forall (f :: * -> *) x. Applicative f => WhenMissing f x x
preserveMissing
WhenMissing f b c
f . :: forall b c a.
WhenMissing f b c -> WhenMissing f a b -> WhenMissing f a c
. WhenMissing f a b
g =
(Word64 -> a -> f (Maybe c)) -> WhenMissing f a c
forall (f :: * -> *) x y.
Applicative f =>
(Word64 -> x -> f (Maybe y)) -> WhenMissing f x y
traverseMaybeMissing ((Word64 -> a -> f (Maybe c)) -> WhenMissing f a c)
-> (Word64 -> a -> f (Maybe c)) -> WhenMissing f a c
forall a b. (a -> b) -> a -> b
$ \ Word64
k a
x -> do
y <- WhenMissing f a b -> Word64 -> a -> f (Maybe b)
forall (f :: * -> *) x y.
WhenMissing f x y -> Word64 -> x -> f (Maybe y)
missingKey WhenMissing f a b
g Word64
k a
x
case y of
Maybe b
Nothing -> Maybe c -> f (Maybe c)
forall a. a -> f a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Maybe c
forall a. Maybe a
Nothing
Just b
q -> WhenMissing f b c -> Word64 -> b -> f (Maybe c)
forall (f :: * -> *) x y.
WhenMissing f x y -> Word64 -> x -> f (Maybe y)
missingKey WhenMissing f b c
f Word64
k b
q
{-# INLINE id #-}
{-# INLINE (.) #-}
instance (Applicative f, Monad f) => Applicative (WhenMissing f x) where
pure :: forall a. a -> WhenMissing f x a
pure a
x = (Word64 -> x -> a) -> WhenMissing f x a
forall (f :: * -> *) x y.
Applicative f =>
(Word64 -> x -> y) -> WhenMissing f x y
mapMissing (\ Word64
_ x
_ -> a
x)
WhenMissing f x (a -> b)
f <*> :: forall a b.
WhenMissing f x (a -> b) -> WhenMissing f x a -> WhenMissing f x b
<*> WhenMissing f x a
g =
(Word64 -> x -> f (Maybe b)) -> WhenMissing f x b
forall (f :: * -> *) x y.
Applicative f =>
(Word64 -> x -> f (Maybe y)) -> WhenMissing f x y
traverseMaybeMissing ((Word64 -> x -> f (Maybe b)) -> WhenMissing f x b)
-> (Word64 -> x -> f (Maybe b)) -> WhenMissing f x b
forall a b. (a -> b) -> a -> b
$ \Word64
k x
x -> do
res1 <- WhenMissing f x (a -> b) -> Word64 -> x -> f (Maybe (a -> b))
forall (f :: * -> *) x y.
WhenMissing f x y -> Word64 -> x -> f (Maybe y)
missingKey WhenMissing f x (a -> b)
f Word64
k x
x
case res1 of
Maybe (a -> b)
Nothing -> Maybe b -> f (Maybe b)
forall a. a -> f a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Maybe b
forall a. Maybe a
Nothing
Just a -> b
r -> (Maybe b -> f (Maybe b)
forall a. a -> f a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Maybe b -> f (Maybe b)) -> Maybe b -> f (Maybe b)
forall a b. (a -> b) -> a -> b
$!) (Maybe b -> f (Maybe b))
-> (Maybe a -> Maybe b) -> Maybe a -> f (Maybe b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> b) -> Maybe a -> Maybe b
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> b
r (Maybe a -> f (Maybe b)) -> f (Maybe a) -> f (Maybe b)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< WhenMissing f x a -> Word64 -> x -> f (Maybe a)
forall (f :: * -> *) x y.
WhenMissing f x y -> Word64 -> x -> f (Maybe y)
missingKey WhenMissing f x a
g Word64
k x
x
{-# INLINE pure #-}
{-# INLINE (<*>) #-}
instance (Applicative f, Monad f) => Monad (WhenMissing f x) where
WhenMissing f x a
m >>= :: forall a b.
WhenMissing f x a -> (a -> WhenMissing f x b) -> WhenMissing f x b
>>= a -> WhenMissing f x b
f =
(Word64 -> x -> f (Maybe b)) -> WhenMissing f x b
forall (f :: * -> *) x y.
Applicative f =>
(Word64 -> x -> f (Maybe y)) -> WhenMissing f x y
traverseMaybeMissing ((Word64 -> x -> f (Maybe b)) -> WhenMissing f x b)
-> (Word64 -> x -> f (Maybe b)) -> WhenMissing f x b
forall a b. (a -> b) -> a -> b
$ \Word64
k x
x -> do
res1 <- WhenMissing f x a -> Word64 -> x -> f (Maybe a)
forall (f :: * -> *) x y.
WhenMissing f x y -> Word64 -> x -> f (Maybe y)
missingKey WhenMissing f x a
m Word64
k x
x
case res1 of
Maybe a
Nothing -> Maybe b -> f (Maybe b)
forall a. a -> f a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Maybe b
forall a. Maybe a
Nothing
Just a
r -> WhenMissing f x b -> Word64 -> x -> f (Maybe b)
forall (f :: * -> *) x y.
WhenMissing f x y -> Word64 -> x -> f (Maybe y)
missingKey (a -> WhenMissing f x b
f a
r) Word64
k x
x
{-# INLINE (>>=) #-}
mapWhenMissing
:: (Applicative f, Monad f)
=> (a -> b)
-> WhenMissing f x a
-> WhenMissing f x b
mapWhenMissing :: forall (f :: * -> *) a b x.
(Applicative f, Monad f) =>
(a -> b) -> WhenMissing f x a -> WhenMissing f x b
mapWhenMissing a -> b
f WhenMissing f x a
t = WhenMissing
{ missingSubtree :: Word64Map x -> f (Word64Map b)
missingSubtree = \Word64Map x
m -> WhenMissing f x a -> Word64Map x -> f (Word64Map a)
forall (f :: * -> *) x y.
WhenMissing f x y -> Word64Map x -> f (Word64Map y)
missingSubtree WhenMissing f x a
t Word64Map x
m f (Word64Map a)
-> (Word64Map a -> f (Word64Map b)) -> f (Word64Map b)
forall a b. f a -> (a -> f b) -> f b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Word64Map a
m' -> Word64Map b -> f (Word64Map b)
forall a. a -> f a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Word64Map b -> f (Word64Map b)) -> Word64Map b -> f (Word64Map b)
forall a b. (a -> b) -> a -> b
$! (a -> b) -> Word64Map a -> Word64Map b
forall a b. (a -> b) -> Word64Map a -> Word64Map b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> b
f Word64Map a
m'
, missingKey :: Word64 -> x -> f (Maybe b)
missingKey = \Word64
k x
x -> WhenMissing f x a -> Word64 -> x -> f (Maybe a)
forall (f :: * -> *) x y.
WhenMissing f x y -> Word64 -> x -> f (Maybe y)
missingKey WhenMissing f x a
t Word64
k x
x f (Maybe a) -> (Maybe a -> f (Maybe b)) -> f (Maybe b)
forall a b. f a -> (a -> f b) -> f b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Maybe a
q -> (Maybe b -> f (Maybe b)
forall a. a -> f a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Maybe b -> f (Maybe b)) -> Maybe b -> f (Maybe b)
forall a b. (a -> b) -> a -> b
$! (a -> b) -> Maybe a -> Maybe b
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> b
f Maybe a
q) }
{-# INLINE mapWhenMissing #-}
mapGentlyWhenMissing
:: Functor f
=> (a -> b)
-> WhenMissing f x a
-> WhenMissing f x b
mapGentlyWhenMissing :: forall (f :: * -> *) a b x.
Functor f =>
(a -> b) -> WhenMissing f x a -> WhenMissing f x b
mapGentlyWhenMissing a -> b
f WhenMissing f x a
t = WhenMissing
{ missingSubtree :: Word64Map x -> f (Word64Map b)
missingSubtree = \Word64Map x
m -> (a -> b) -> Word64Map a -> Word64Map b
forall a b. (a -> b) -> Word64Map a -> Word64Map b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> b
f (Word64Map a -> Word64Map b) -> f (Word64Map a) -> f (Word64Map b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> WhenMissing f x a -> Word64Map x -> f (Word64Map a)
forall (f :: * -> *) x y.
WhenMissing f x y -> Word64Map x -> f (Word64Map y)
missingSubtree WhenMissing f x a
t Word64Map x
m
, missingKey :: Word64 -> x -> f (Maybe b)
missingKey = \Word64
k x
x -> (a -> b) -> Maybe a -> Maybe b
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> b
f (Maybe a -> Maybe b) -> f (Maybe a) -> f (Maybe b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> WhenMissing f x a -> Word64 -> x -> f (Maybe a)
forall (f :: * -> *) x y.
WhenMissing f x y -> Word64 -> x -> f (Maybe y)
missingKey WhenMissing f x a
t Word64
k x
x }
{-# INLINE mapGentlyWhenMissing #-}
mapGentlyWhenMatched
:: Functor f
=> (a -> b)
-> WhenMatched f x y a
-> WhenMatched f x y b
mapGentlyWhenMatched :: forall (f :: * -> *) a b x y.
Functor f =>
(a -> b) -> WhenMatched f x y a -> WhenMatched f x y b
mapGentlyWhenMatched a -> b
f WhenMatched f x y a
t =
(Word64 -> x -> y -> f (Maybe b)) -> WhenMatched f x y b
forall x y (f :: * -> *) z.
(Word64 -> x -> y -> f (Maybe z)) -> WhenMatched f x y z
zipWithMaybeAMatched ((Word64 -> x -> y -> f (Maybe b)) -> WhenMatched f x y b)
-> (Word64 -> x -> y -> f (Maybe b)) -> WhenMatched f x y b
forall a b. (a -> b) -> a -> b
$ \Word64
k x
x y
y -> (a -> b) -> Maybe a -> Maybe b
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> b
f (Maybe a -> Maybe b) -> f (Maybe a) -> f (Maybe b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> WhenMatched f x y a -> Word64 -> x -> y -> f (Maybe a)
forall (f :: * -> *) x y z.
WhenMatched f x y z -> Word64 -> x -> y -> f (Maybe z)
runWhenMatched WhenMatched f x y a
t Word64
k x
x y
y
{-# INLINE mapGentlyWhenMatched #-}
lmapWhenMissing :: (b -> a) -> WhenMissing f a x -> WhenMissing f b x
lmapWhenMissing :: forall b a (f :: * -> *) x.
(b -> a) -> WhenMissing f a x -> WhenMissing f b x
lmapWhenMissing b -> a
f WhenMissing f a x
t = WhenMissing
{ missingSubtree :: Word64Map b -> f (Word64Map x)
missingSubtree = \Word64Map b
m -> WhenMissing f a x -> Word64Map a -> f (Word64Map x)
forall (f :: * -> *) x y.
WhenMissing f x y -> Word64Map x -> f (Word64Map y)
missingSubtree WhenMissing f a x
t ((b -> a) -> Word64Map b -> Word64Map a
forall a b. (a -> b) -> Word64Map a -> Word64Map b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap b -> a
f Word64Map b
m)
, missingKey :: Word64 -> b -> f (Maybe x)
missingKey = \Word64
k b
x -> WhenMissing f a x -> Word64 -> a -> f (Maybe x)
forall (f :: * -> *) x y.
WhenMissing f x y -> Word64 -> x -> f (Maybe y)
missingKey WhenMissing f a x
t Word64
k (b -> a
f b
x) }
{-# INLINE lmapWhenMissing #-}
contramapFirstWhenMatched
:: (b -> a)
-> WhenMatched f a y z
-> WhenMatched f b y z
contramapFirstWhenMatched :: forall b a (f :: * -> *) y z.
(b -> a) -> WhenMatched f a y z -> WhenMatched f b y z
contramapFirstWhenMatched b -> a
f WhenMatched f a y z
t =
(Word64 -> b -> y -> f (Maybe z)) -> WhenMatched f b y z
forall (f :: * -> *) x y z.
(Word64 -> x -> y -> f (Maybe z)) -> WhenMatched f x y z
WhenMatched ((Word64 -> b -> y -> f (Maybe z)) -> WhenMatched f b y z)
-> (Word64 -> b -> y -> f (Maybe z)) -> WhenMatched f b y z
forall a b. (a -> b) -> a -> b
$ \Word64
k b
x y
y -> WhenMatched f a y z -> Word64 -> a -> y -> f (Maybe z)
forall (f :: * -> *) x y z.
WhenMatched f x y z -> Word64 -> x -> y -> f (Maybe z)
runWhenMatched WhenMatched f a y z
t Word64
k (b -> a
f b
x) y
y
{-# INLINE contramapFirstWhenMatched #-}
contramapSecondWhenMatched
:: (b -> a)
-> WhenMatched f x a z
-> WhenMatched f x b z
contramapSecondWhenMatched :: forall b a (f :: * -> *) x z.
(b -> a) -> WhenMatched f x a z -> WhenMatched f x b z
contramapSecondWhenMatched b -> a
f WhenMatched f x a z
t =
(Word64 -> x -> b -> f (Maybe z)) -> WhenMatched f x b z
forall (f :: * -> *) x y z.
(Word64 -> x -> y -> f (Maybe z)) -> WhenMatched f x y z
WhenMatched ((Word64 -> x -> b -> f (Maybe z)) -> WhenMatched f x b z)
-> (Word64 -> x -> b -> f (Maybe z)) -> WhenMatched f x b z
forall a b. (a -> b) -> a -> b
$ \Word64
k x
x b
y -> WhenMatched f x a z -> Word64 -> x -> a -> f (Maybe z)
forall (f :: * -> *) x y z.
WhenMatched f x y z -> Word64 -> x -> y -> f (Maybe z)
runWhenMatched WhenMatched f x a z
t Word64
k x
x (b -> a
f b
y)
{-# INLINE contramapSecondWhenMatched #-}
type SimpleWhenMissing = WhenMissing Identity
newtype WhenMatched f x y z = WhenMatched
{ forall (f :: * -> *) x y z.
WhenMatched f x y z -> Word64 -> x -> y -> f (Maybe z)
matchedKey :: Key -> x -> y -> f (Maybe z) }
runWhenMatched :: WhenMatched f x y z -> Key -> x -> y -> f (Maybe z)
runWhenMatched :: forall (f :: * -> *) x y z.
WhenMatched f x y z -> Word64 -> x -> y -> f (Maybe z)
runWhenMatched = WhenMatched f x y z -> Word64 -> x -> y -> f (Maybe z)
forall (f :: * -> *) x y z.
WhenMatched f x y z -> Word64 -> x -> y -> f (Maybe z)
matchedKey
{-# INLINE runWhenMatched #-}
runWhenMissing :: WhenMissing f x y -> Key-> x -> f (Maybe y)
runWhenMissing :: forall (f :: * -> *) x y.
WhenMissing f x y -> Word64 -> x -> f (Maybe y)
runWhenMissing = WhenMissing f x y -> Word64 -> x -> f (Maybe y)
forall (f :: * -> *) x y.
WhenMissing f x y -> Word64 -> x -> f (Maybe y)
missingKey
{-# INLINE runWhenMissing #-}
instance Functor f => Functor (WhenMatched f x y) where
fmap :: forall a b. (a -> b) -> WhenMatched f x y a -> WhenMatched f x y b
fmap = (a -> b) -> WhenMatched f x y a -> WhenMatched f x y b
forall (f :: * -> *) a b x y.
Functor f =>
(a -> b) -> WhenMatched f x y a -> WhenMatched f x y b
mapWhenMatched
{-# INLINE fmap #-}
instance (Monad f, Applicative f) => Category.Category (WhenMatched f x)
where
id :: forall a. WhenMatched f x a a
id = (Word64 -> x -> a -> a) -> WhenMatched f x a a
forall (f :: * -> *) x y z.
Applicative f =>
(Word64 -> x -> y -> z) -> WhenMatched f x y z
zipWithMatched (\Word64
_ x
_ a
y -> a
y)
WhenMatched f x b c
f . :: forall b c a.
WhenMatched f x b c -> WhenMatched f x a b -> WhenMatched f x a c
. WhenMatched f x a b
g =
(Word64 -> x -> a -> f (Maybe c)) -> WhenMatched f x a c
forall x y (f :: * -> *) z.
(Word64 -> x -> y -> f (Maybe z)) -> WhenMatched f x y z
zipWithMaybeAMatched ((Word64 -> x -> a -> f (Maybe c)) -> WhenMatched f x a c)
-> (Word64 -> x -> a -> f (Maybe c)) -> WhenMatched f x a c
forall a b. (a -> b) -> a -> b
$ \Word64
k x
x a
y -> do
res <- WhenMatched f x a b -> Word64 -> x -> a -> f (Maybe b)
forall (f :: * -> *) x y z.
WhenMatched f x y z -> Word64 -> x -> y -> f (Maybe z)
runWhenMatched WhenMatched f x a b
g Word64
k x
x a
y
case res of
Maybe b
Nothing -> Maybe c -> f (Maybe c)
forall a. a -> f a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Maybe c
forall a. Maybe a
Nothing
Just b
r -> WhenMatched f x b c -> Word64 -> x -> b -> f (Maybe c)
forall (f :: * -> *) x y z.
WhenMatched f x y z -> Word64 -> x -> y -> f (Maybe z)
runWhenMatched WhenMatched f x b c
f Word64
k x
x b
r
{-# INLINE id #-}
{-# INLINE (.) #-}
instance (Monad f, Applicative f) => Applicative (WhenMatched f x y) where
pure :: forall a. a -> WhenMatched f x y a
pure a
x = (Word64 -> x -> y -> a) -> WhenMatched f x y a
forall (f :: * -> *) x y z.
Applicative f =>
(Word64 -> x -> y -> z) -> WhenMatched f x y z
zipWithMatched (\Word64
_ x
_ y
_ -> a
x)
WhenMatched f x y (a -> b)
fs <*> :: forall a b.
WhenMatched f x y (a -> b)
-> WhenMatched f x y a -> WhenMatched f x y b
<*> WhenMatched f x y a
xs =
(Word64 -> x -> y -> f (Maybe b)) -> WhenMatched f x y b
forall x y (f :: * -> *) z.
(Word64 -> x -> y -> f (Maybe z)) -> WhenMatched f x y z
zipWithMaybeAMatched ((Word64 -> x -> y -> f (Maybe b)) -> WhenMatched f x y b)
-> (Word64 -> x -> y -> f (Maybe b)) -> WhenMatched f x y b
forall a b. (a -> b) -> a -> b
$ \Word64
k x
x y
y -> do
res <- WhenMatched f x y (a -> b)
-> Word64 -> x -> y -> f (Maybe (a -> b))
forall (f :: * -> *) x y z.
WhenMatched f x y z -> Word64 -> x -> y -> f (Maybe z)
runWhenMatched WhenMatched f x y (a -> b)
fs Word64
k x
x y
y
case res of
Maybe (a -> b)
Nothing -> Maybe b -> f (Maybe b)
forall a. a -> f a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Maybe b
forall a. Maybe a
Nothing
Just a -> b
r -> (Maybe b -> f (Maybe b)
forall a. a -> f a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Maybe b -> f (Maybe b)) -> Maybe b -> f (Maybe b)
forall a b. (a -> b) -> a -> b
$!) (Maybe b -> f (Maybe b))
-> (Maybe a -> Maybe b) -> Maybe a -> f (Maybe b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> b) -> Maybe a -> Maybe b
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> b
r (Maybe a -> f (Maybe b)) -> f (Maybe a) -> f (Maybe b)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< WhenMatched f x y a -> Word64 -> x -> y -> f (Maybe a)
forall (f :: * -> *) x y z.
WhenMatched f x y z -> Word64 -> x -> y -> f (Maybe z)
runWhenMatched WhenMatched f x y a
xs Word64
k x
x y
y
{-# INLINE pure #-}
{-# INLINE (<*>) #-}
instance (Monad f, Applicative f) => Monad (WhenMatched f x y) where
WhenMatched f x y a
m >>= :: forall a b.
WhenMatched f x y a
-> (a -> WhenMatched f x y b) -> WhenMatched f x y b
>>= a -> WhenMatched f x y b
f =
(Word64 -> x -> y -> f (Maybe b)) -> WhenMatched f x y b
forall x y (f :: * -> *) z.
(Word64 -> x -> y -> f (Maybe z)) -> WhenMatched f x y z
zipWithMaybeAMatched ((Word64 -> x -> y -> f (Maybe b)) -> WhenMatched f x y b)
-> (Word64 -> x -> y -> f (Maybe b)) -> WhenMatched f x y b
forall a b. (a -> b) -> a -> b
$ \Word64
k x
x y
y -> do
res <- WhenMatched f x y a -> Word64 -> x -> y -> f (Maybe a)
forall (f :: * -> *) x y z.
WhenMatched f x y z -> Word64 -> x -> y -> f (Maybe z)
runWhenMatched WhenMatched f x y a
m Word64
k x
x y
y
case res of
Maybe a
Nothing -> Maybe b -> f (Maybe b)
forall a. a -> f a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Maybe b
forall a. Maybe a
Nothing
Just a
r -> WhenMatched f x y b -> Word64 -> x -> y -> f (Maybe b)
forall (f :: * -> *) x y z.
WhenMatched f x y z -> Word64 -> x -> y -> f (Maybe z)
runWhenMatched (a -> WhenMatched f x y b
f a
r) Word64
k x
x y
y
{-# INLINE (>>=) #-}
mapWhenMatched
:: Functor f
=> (a -> b)
-> WhenMatched f x y a
-> WhenMatched f x y b
mapWhenMatched :: forall (f :: * -> *) a b x y.
Functor f =>
(a -> b) -> WhenMatched f x y a -> WhenMatched f x y b
mapWhenMatched a -> b
f (WhenMatched Word64 -> x -> y -> f (Maybe a)
g) =
(Word64 -> x -> y -> f (Maybe b)) -> WhenMatched f x y b
forall (f :: * -> *) x y z.
(Word64 -> x -> y -> f (Maybe z)) -> WhenMatched f x y z
WhenMatched ((Word64 -> x -> y -> f (Maybe b)) -> WhenMatched f x y b)
-> (Word64 -> x -> y -> f (Maybe b)) -> WhenMatched f x y b
forall a b. (a -> b) -> a -> b
$ \Word64
k x
x y
y -> (Maybe a -> Maybe b) -> f (Maybe a) -> f (Maybe b)
forall a b. (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((a -> b) -> Maybe a -> Maybe b
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> b
f) (Word64 -> x -> y -> f (Maybe a)
g Word64
k x
x y
y)
{-# INLINE mapWhenMatched #-}
type SimpleWhenMatched = WhenMatched Identity
zipWithMatched
:: Applicative f
=> (Key -> x -> y -> z)
-> WhenMatched f x y z
zipWithMatched :: forall (f :: * -> *) x y z.
Applicative f =>
(Word64 -> x -> y -> z) -> WhenMatched f x y z
zipWithMatched Word64 -> x -> y -> z
f = (Word64 -> x -> y -> f (Maybe z)) -> WhenMatched f x y z
forall (f :: * -> *) x y z.
(Word64 -> x -> y -> f (Maybe z)) -> WhenMatched f x y z
WhenMatched ((Word64 -> x -> y -> f (Maybe z)) -> WhenMatched f x y z)
-> (Word64 -> x -> y -> f (Maybe z)) -> WhenMatched f x y z
forall a b. (a -> b) -> a -> b
$ \ Word64
k x
x y
y -> Maybe z -> f (Maybe z)
forall a. a -> f a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Maybe z -> f (Maybe z)) -> (z -> Maybe z) -> z -> f (Maybe z)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. z -> Maybe z
forall a. a -> Maybe a
Just (z -> f (Maybe z)) -> z -> f (Maybe z)
forall a b. (a -> b) -> a -> b
$ Word64 -> x -> y -> z
f Word64
k x
x y
y
{-# INLINE zipWithMatched #-}
zipWithAMatched
:: Applicative f
=> (Key -> x -> y -> f z)
-> WhenMatched f x y z
zipWithAMatched :: forall (f :: * -> *) x y z.
Applicative f =>
(Word64 -> x -> y -> f z) -> WhenMatched f x y z
zipWithAMatched Word64 -> x -> y -> f z
f = (Word64 -> x -> y -> f (Maybe z)) -> WhenMatched f x y z
forall (f :: * -> *) x y z.
(Word64 -> x -> y -> f (Maybe z)) -> WhenMatched f x y z
WhenMatched ((Word64 -> x -> y -> f (Maybe z)) -> WhenMatched f x y z)
-> (Word64 -> x -> y -> f (Maybe z)) -> WhenMatched f x y z
forall a b. (a -> b) -> a -> b
$ \ Word64
k x
x y
y -> z -> Maybe z
forall a. a -> Maybe a
Just (z -> Maybe z) -> f z -> f (Maybe z)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Word64 -> x -> y -> f z
f Word64
k x
x y
y
{-# INLINE zipWithAMatched #-}
zipWithMaybeMatched
:: Applicative f
=> (Key -> x -> y -> Maybe z)
-> WhenMatched f x y z
zipWithMaybeMatched :: forall (f :: * -> *) x y z.
Applicative f =>
(Word64 -> x -> y -> Maybe z) -> WhenMatched f x y z
zipWithMaybeMatched Word64 -> x -> y -> Maybe z
f = (Word64 -> x -> y -> f (Maybe z)) -> WhenMatched f x y z
forall (f :: * -> *) x y z.
(Word64 -> x -> y -> f (Maybe z)) -> WhenMatched f x y z
WhenMatched ((Word64 -> x -> y -> f (Maybe z)) -> WhenMatched f x y z)
-> (Word64 -> x -> y -> f (Maybe z)) -> WhenMatched f x y z
forall a b. (a -> b) -> a -> b
$ \ Word64
k x
x y
y -> Maybe z -> f (Maybe z)
forall a. a -> f a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Maybe z -> f (Maybe z)) -> Maybe z -> f (Maybe z)
forall a b. (a -> b) -> a -> b
$ Word64 -> x -> y -> Maybe z
f Word64
k x
x y
y
{-# INLINE zipWithMaybeMatched #-}
zipWithMaybeAMatched
:: (Key -> x -> y -> f (Maybe z))
-> WhenMatched f x y z
zipWithMaybeAMatched :: forall x y (f :: * -> *) z.
(Word64 -> x -> y -> f (Maybe z)) -> WhenMatched f x y z
zipWithMaybeAMatched Word64 -> x -> y -> f (Maybe z)
f = (Word64 -> x -> y -> f (Maybe z)) -> WhenMatched f x y z
forall (f :: * -> *) x y z.
(Word64 -> x -> y -> f (Maybe z)) -> WhenMatched f x y z
WhenMatched ((Word64 -> x -> y -> f (Maybe z)) -> WhenMatched f x y z)
-> (Word64 -> x -> y -> f (Maybe z)) -> WhenMatched f x y z
forall a b. (a -> b) -> a -> b
$ \ Word64
k x
x y
y -> Word64 -> x -> y -> f (Maybe z)
f Word64
k x
x y
y
{-# INLINE zipWithMaybeAMatched #-}
dropMissing :: Applicative f => WhenMissing f x y
dropMissing :: forall (f :: * -> *) x y. Applicative f => WhenMissing f x y
dropMissing = WhenMissing
{ missingSubtree :: Word64Map x -> f (Word64Map y)
missingSubtree = f (Word64Map y) -> Word64Map x -> f (Word64Map y)
forall a b. a -> b -> a
const (Word64Map y -> f (Word64Map y)
forall a. a -> f a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Word64Map y
forall a. Word64Map a
Nil)
, missingKey :: Word64 -> x -> f (Maybe y)
missingKey = \Word64
_ x
_ -> Maybe y -> f (Maybe y)
forall a. a -> f a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Maybe y
forall a. Maybe a
Nothing }
{-# INLINE dropMissing #-}
preserveMissing :: Applicative f => WhenMissing f x x
preserveMissing :: forall (f :: * -> *) x. Applicative f => WhenMissing f x x
preserveMissing = WhenMissing
{ missingSubtree :: Word64Map x -> f (Word64Map x)
missingSubtree = Word64Map x -> f (Word64Map x)
forall a. a -> f a
forall (f :: * -> *) a. Applicative f => a -> f a
pure
, missingKey :: Word64 -> x -> f (Maybe x)
missingKey = \Word64
_ x
v -> Maybe x -> f (Maybe x)
forall a. a -> f a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (x -> Maybe x
forall a. a -> Maybe a
Just x
v) }
{-# INLINE preserveMissing #-}
mapMissing :: Applicative f => (Key -> x -> y) -> WhenMissing f x y
mapMissing :: forall (f :: * -> *) x y.
Applicative f =>
(Word64 -> x -> y) -> WhenMissing f x y
mapMissing Word64 -> x -> y
f = WhenMissing
{ missingSubtree :: Word64Map x -> f (Word64Map y)
missingSubtree = \Word64Map x
m -> Word64Map y -> f (Word64Map y)
forall a. a -> f a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Word64Map y -> f (Word64Map y)) -> Word64Map y -> f (Word64Map y)
forall a b. (a -> b) -> a -> b
$! (Word64 -> x -> y) -> Word64Map x -> Word64Map y
forall a b. (Word64 -> a -> b) -> Word64Map a -> Word64Map b
mapWithKey Word64 -> x -> y
f Word64Map x
m
, missingKey :: Word64 -> x -> f (Maybe y)
missingKey = \Word64
k x
x -> Maybe y -> f (Maybe y)
forall a. a -> f a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Maybe y -> f (Maybe y)) -> Maybe y -> f (Maybe y)
forall a b. (a -> b) -> a -> b
$ y -> Maybe y
forall a. a -> Maybe a
Just (Word64 -> x -> y
f Word64
k x
x) }
{-# INLINE mapMissing #-}
mapMaybeMissing
:: Applicative f => (Key -> x -> Maybe y) -> WhenMissing f x y
mapMaybeMissing :: forall (f :: * -> *) x y.
Applicative f =>
(Word64 -> x -> Maybe y) -> WhenMissing f x y
mapMaybeMissing Word64 -> x -> Maybe y
f = WhenMissing
{ missingSubtree :: Word64Map x -> f (Word64Map y)
missingSubtree = \Word64Map x
m -> Word64Map y -> f (Word64Map y)
forall a. a -> f a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Word64Map y -> f (Word64Map y)) -> Word64Map y -> f (Word64Map y)
forall a b. (a -> b) -> a -> b
$! (Word64 -> x -> Maybe y) -> Word64Map x -> Word64Map y
forall a b. (Word64 -> a -> Maybe b) -> Word64Map a -> Word64Map b
mapMaybeWithKey Word64 -> x -> Maybe y
f Word64Map x
m
, missingKey :: Word64 -> x -> f (Maybe y)
missingKey = \Word64
k x
x -> Maybe y -> f (Maybe y)
forall a. a -> f a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Maybe y -> f (Maybe y)) -> Maybe y -> f (Maybe y)
forall a b. (a -> b) -> a -> b
$! Word64 -> x -> Maybe y
f Word64
k x
x }
{-# INLINE mapMaybeMissing #-}
filterMissing
:: Applicative f => (Key -> x -> Bool) -> WhenMissing f x x
filterMissing :: forall (f :: * -> *) x.
Applicative f =>
(Word64 -> x -> Bool) -> WhenMissing f x x
filterMissing Word64 -> x -> Bool
f = WhenMissing
{ missingSubtree :: Word64Map x -> f (Word64Map x)
missingSubtree = \Word64Map x
m -> Word64Map x -> f (Word64Map x)
forall a. a -> f a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Word64Map x -> f (Word64Map x)) -> Word64Map x -> f (Word64Map x)
forall a b. (a -> b) -> a -> b
$! (Word64 -> x -> Bool) -> Word64Map x -> Word64Map x
forall a. (Word64 -> a -> Bool) -> Word64Map a -> Word64Map a
filterWithKey Word64 -> x -> Bool
f Word64Map x
m
, missingKey :: Word64 -> x -> f (Maybe x)
missingKey = \Word64
k x
x -> Maybe x -> f (Maybe x)
forall a. a -> f a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Maybe x -> f (Maybe x)) -> Maybe x -> f (Maybe x)
forall a b. (a -> b) -> a -> b
$! if Word64 -> x -> Bool
f Word64
k x
x then x -> Maybe x
forall a. a -> Maybe a
Just x
x else Maybe x
forall a. Maybe a
Nothing }
{-# INLINE filterMissing #-}
filterAMissing
:: Applicative f => (Key -> x -> f Bool) -> WhenMissing f x x
filterAMissing :: forall (f :: * -> *) x.
Applicative f =>
(Word64 -> x -> f Bool) -> WhenMissing f x x
filterAMissing Word64 -> x -> f Bool
f = WhenMissing
{ missingSubtree :: Word64Map x -> f (Word64Map x)
missingSubtree = \Word64Map x
m -> (Word64 -> x -> f Bool) -> Word64Map x -> f (Word64Map x)
forall (f :: * -> *) a.
Applicative f =>
(Word64 -> a -> f Bool) -> Word64Map a -> f (Word64Map a)
filterWithKeyA Word64 -> x -> f Bool
f Word64Map x
m
, missingKey :: Word64 -> x -> f (Maybe x)
missingKey = \Word64
k x
x -> Maybe x -> Maybe x -> Bool -> Maybe x
forall a. a -> a -> Bool -> a
bool Maybe x
forall a. Maybe a
Nothing (x -> Maybe x
forall a. a -> Maybe a
Just x
x) (Bool -> Maybe x) -> f Bool -> f (Maybe x)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Word64 -> x -> f Bool
f Word64
k x
x }
{-# INLINE filterAMissing #-}
filterWithKeyA
:: Applicative f => (Key -> a -> f Bool) -> Word64Map a -> f (Word64Map a)
filterWithKeyA :: forall (f :: * -> *) a.
Applicative f =>
(Word64 -> a -> f Bool) -> Word64Map a -> f (Word64Map a)
filterWithKeyA Word64 -> a -> f Bool
_ Word64Map a
Nil = Word64Map a -> f (Word64Map a)
forall a. a -> f a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Word64Map a
forall a. Word64Map a
Nil
filterWithKeyA Word64 -> a -> f Bool
f t :: Word64Map a
t@(Tip Word64
k a
x) = (\Bool
b -> if Bool
b then Word64Map a
t else Word64Map a
forall a. Word64Map a
Nil) (Bool -> Word64Map a) -> f Bool -> f (Word64Map a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Word64 -> a -> f Bool
f Word64
k a
x
filterWithKeyA Word64 -> a -> f Bool
f (Bin Word64
p Word64
m Word64Map a
l Word64Map a
r)
| Word64
m Word64 -> Word64 -> Bool
forall a. Ord a => a -> a -> Bool
< Word64
0 = (Word64Map a -> Word64Map a -> Word64Map a)
-> f (Word64Map a) -> f (Word64Map a) -> f (Word64Map a)
forall a b c. (a -> b -> c) -> f a -> f b -> f c
forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 ((Word64Map a -> Word64Map a -> Word64Map a)
-> Word64Map a -> Word64Map a -> Word64Map a
forall a b c. (a -> b -> c) -> b -> a -> c
flip (Word64 -> Word64 -> Word64Map a -> Word64Map a -> Word64Map a
forall a.
Word64 -> Word64 -> Word64Map a -> Word64Map a -> Word64Map a
bin Word64
p Word64
m)) ((Word64 -> a -> f Bool) -> Word64Map a -> f (Word64Map a)
forall (f :: * -> *) a.
Applicative f =>
(Word64 -> a -> f Bool) -> Word64Map a -> f (Word64Map a)
filterWithKeyA Word64 -> a -> f Bool
f Word64Map a
r) ((Word64 -> a -> f Bool) -> Word64Map a -> f (Word64Map a)
forall (f :: * -> *) a.
Applicative f =>
(Word64 -> a -> f Bool) -> Word64Map a -> f (Word64Map a)
filterWithKeyA Word64 -> a -> f Bool
f Word64Map a
l)
| Bool
otherwise = (Word64Map a -> Word64Map a -> Word64Map a)
-> f (Word64Map a) -> f (Word64Map a) -> f (Word64Map a)
forall a b c. (a -> b -> c) -> f a -> f b -> f c
forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 (Word64 -> Word64 -> Word64Map a -> Word64Map a -> Word64Map a
forall a.
Word64 -> Word64 -> Word64Map a -> Word64Map a -> Word64Map a
bin Word64
p Word64
m) ((Word64 -> a -> f Bool) -> Word64Map a -> f (Word64Map a)
forall (f :: * -> *) a.
Applicative f =>
(Word64 -> a -> f Bool) -> Word64Map a -> f (Word64Map a)
filterWithKeyA Word64 -> a -> f Bool
f Word64Map a
l) ((Word64 -> a -> f Bool) -> Word64Map a -> f (Word64Map a)
forall (f :: * -> *) a.
Applicative f =>
(Word64 -> a -> f Bool) -> Word64Map a -> f (Word64Map a)
filterWithKeyA Word64 -> a -> f Bool
f Word64Map a
r)
bool :: a -> a -> Bool -> a
bool :: forall a. a -> a -> Bool -> a
bool a
f a
_ Bool
False = a
f
bool a
_ a
t Bool
True = a
t
traverseMissing
:: Applicative f => (Key -> x -> f y) -> WhenMissing f x y
traverseMissing :: forall (f :: * -> *) x y.
Applicative f =>
(Word64 -> x -> f y) -> WhenMissing f x y
traverseMissing Word64 -> x -> f y
f = WhenMissing
{ missingSubtree :: Word64Map x -> f (Word64Map y)
missingSubtree = (Word64 -> x -> f y) -> Word64Map x -> f (Word64Map y)
forall (t :: * -> *) a b.
Applicative t =>
(Word64 -> a -> t b) -> Word64Map a -> t (Word64Map b)
traverseWithKey Word64 -> x -> f y
f
, missingKey :: Word64 -> x -> f (Maybe y)
missingKey = \Word64
k x
x -> y -> Maybe y
forall a. a -> Maybe a
Just (y -> Maybe y) -> f y -> f (Maybe y)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Word64 -> x -> f y
f Word64
k x
x }
{-# INLINE traverseMissing #-}
traverseMaybeMissing
:: Applicative f => (Key -> x -> f (Maybe y)) -> WhenMissing f x y
traverseMaybeMissing :: forall (f :: * -> *) x y.
Applicative f =>
(Word64 -> x -> f (Maybe y)) -> WhenMissing f x y
traverseMaybeMissing Word64 -> x -> f (Maybe y)
f = WhenMissing
{ missingSubtree :: Word64Map x -> f (Word64Map y)
missingSubtree = (Word64 -> x -> f (Maybe y)) -> Word64Map x -> f (Word64Map y)
forall (f :: * -> *) a b.
Applicative f =>
(Word64 -> a -> f (Maybe b)) -> Word64Map a -> f (Word64Map b)
traverseMaybeWithKey Word64 -> x -> f (Maybe y)
f
, missingKey :: Word64 -> x -> f (Maybe y)
missingKey = Word64 -> x -> f (Maybe y)
f }
{-# INLINE traverseMaybeMissing #-}
traverseMaybeWithKey
:: Applicative f => (Key -> a -> f (Maybe b)) -> Word64Map a -> f (Word64Map b)
traverseMaybeWithKey :: forall (f :: * -> *) a b.
Applicative f =>
(Word64 -> a -> f (Maybe b)) -> Word64Map a -> f (Word64Map b)
traverseMaybeWithKey Word64 -> a -> f (Maybe b)
f = Word64Map a -> f (Word64Map b)
go
where
go :: Word64Map a -> f (Word64Map b)
go Word64Map a
Nil = Word64Map b -> f (Word64Map b)
forall a. a -> f a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Word64Map b
forall a. Word64Map a
Nil
go (Tip Word64
k a
x) = Word64Map b -> (b -> Word64Map b) -> Maybe b -> Word64Map b
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Word64Map b
forall a. Word64Map a
Nil (Word64 -> b -> Word64Map b
forall a. Word64 -> a -> Word64Map a
Tip Word64
k) (Maybe b -> Word64Map b) -> f (Maybe b) -> f (Word64Map b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Word64 -> a -> f (Maybe b)
f Word64
k a
x
go (Bin Word64
p Word64
m Word64Map a
l Word64Map a
r)
| Word64
m Word64 -> Word64 -> Bool
forall a. Ord a => a -> a -> Bool
< Word64
0 = (Word64Map b -> Word64Map b -> Word64Map b)
-> f (Word64Map b) -> f (Word64Map b) -> f (Word64Map b)
forall a b c. (a -> b -> c) -> f a -> f b -> f c
forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 ((Word64Map b -> Word64Map b -> Word64Map b)
-> Word64Map b -> Word64Map b -> Word64Map b
forall a b c. (a -> b -> c) -> b -> a -> c
flip (Word64 -> Word64 -> Word64Map b -> Word64Map b -> Word64Map b
forall a.
Word64 -> Word64 -> Word64Map a -> Word64Map a -> Word64Map a
bin Word64
p Word64
m)) (Word64Map a -> f (Word64Map b)
go Word64Map a
r) (Word64Map a -> f (Word64Map b)
go Word64Map a
l)
| Bool
otherwise = (Word64Map b -> Word64Map b -> Word64Map b)
-> f (Word64Map b) -> f (Word64Map b) -> f (Word64Map b)
forall a b c. (a -> b -> c) -> f a -> f b -> f c
forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 (Word64 -> Word64 -> Word64Map b -> Word64Map b -> Word64Map b
forall a.
Word64 -> Word64 -> Word64Map a -> Word64Map a -> Word64Map a
bin Word64
p Word64
m) (Word64Map a -> f (Word64Map b)
go Word64Map a
l) (Word64Map a -> f (Word64Map b)
go Word64Map a
r)
merge
:: SimpleWhenMissing a c
-> SimpleWhenMissing b c
-> SimpleWhenMatched a b c
-> Word64Map a
-> Word64Map b
-> Word64Map c
merge :: forall a c b.
SimpleWhenMissing a c
-> SimpleWhenMissing b c
-> SimpleWhenMatched a b c
-> Word64Map a
-> Word64Map b
-> Word64Map c
merge SimpleWhenMissing a c
g1 SimpleWhenMissing b c
g2 SimpleWhenMatched a b c
f Word64Map a
m1 Word64Map b
m2 =
Identity (Word64Map c) -> Word64Map c
forall a. Identity a -> a
runIdentity (Identity (Word64Map c) -> Word64Map c)
-> Identity (Word64Map c) -> Word64Map c
forall a b. (a -> b) -> a -> b
$ SimpleWhenMissing a c
-> SimpleWhenMissing b c
-> SimpleWhenMatched a b c
-> Word64Map a
-> Word64Map b
-> Identity (Word64Map c)
forall (f :: * -> *) a c b.
Applicative f =>
WhenMissing f a c
-> WhenMissing f b c
-> WhenMatched f a b c
-> Word64Map a
-> Word64Map b
-> f (Word64Map c)
mergeA SimpleWhenMissing a c
g1 SimpleWhenMissing b c
g2 SimpleWhenMatched a b c
f Word64Map a
m1 Word64Map b
m2
{-# INLINE merge #-}
mergeA
:: (Applicative f)
=> WhenMissing f a c
-> WhenMissing f b c
-> WhenMatched f a b c
-> Word64Map a
-> Word64Map b
-> f (Word64Map c)
mergeA :: forall (f :: * -> *) a c b.
Applicative f =>
WhenMissing f a c
-> WhenMissing f b c
-> WhenMatched f a b c
-> Word64Map a
-> Word64Map b
-> f (Word64Map c)
mergeA
WhenMissing{missingSubtree :: forall (f :: * -> *) x y.
WhenMissing f x y -> Word64Map x -> f (Word64Map y)
missingSubtree = Word64Map a -> f (Word64Map c)
g1t, missingKey :: forall (f :: * -> *) x y.
WhenMissing f x y -> Word64 -> x -> f (Maybe y)
missingKey = Word64 -> a -> f (Maybe c)
g1k}
WhenMissing{missingSubtree :: forall (f :: * -> *) x y.
WhenMissing f x y -> Word64Map x -> f (Word64Map y)
missingSubtree = Word64Map b -> f (Word64Map c)
g2t, missingKey :: forall (f :: * -> *) x y.
WhenMissing f x y -> Word64 -> x -> f (Maybe y)
missingKey = Word64 -> b -> f (Maybe c)
g2k}
WhenMatched{matchedKey :: forall (f :: * -> *) x y z.
WhenMatched f x y z -> Word64 -> x -> y -> f (Maybe z)
matchedKey = Word64 -> a -> b -> f (Maybe c)
f}
= Word64Map a -> Word64Map b -> f (Word64Map c)
go
where
go :: Word64Map a -> Word64Map b -> f (Word64Map c)
go Word64Map a
t1 Word64Map b
Nil = Word64Map a -> f (Word64Map c)
g1t Word64Map a
t1
go Word64Map a
Nil Word64Map b
t2 = Word64Map b -> f (Word64Map c)
g2t Word64Map b
t2
go (Tip Word64
k1 a
x1) Word64Map b
t2' = Word64Map b -> f (Word64Map c)
merge2 Word64Map b
t2'
where
merge2 :: Word64Map b -> f (Word64Map c)
merge2 t2 :: Word64Map b
t2@(Bin Word64
p2 Word64
m2 Word64Map b
l2 Word64Map b
r2)
| Word64 -> Word64 -> Word64 -> Bool
nomatch Word64
k1 Word64
p2 Word64
m2 = Word64
-> f (Word64Map c) -> Word64 -> f (Word64Map c) -> f (Word64Map c)
forall (f :: * -> *) a.
Applicative f =>
Word64
-> f (Word64Map a) -> Word64 -> f (Word64Map a) -> f (Word64Map a)
linkA Word64
k1 ((Word64 -> a -> f (Maybe c)) -> Word64 -> a -> f (Word64Map c)
forall {f :: * -> *} {t} {a}.
Functor f =>
(Word64 -> t -> f (Maybe a)) -> Word64 -> t -> f (Word64Map a)
subsingletonBy Word64 -> a -> f (Maybe c)
g1k Word64
k1 a
x1) Word64
p2 (Word64Map b -> f (Word64Map c)
g2t Word64Map b
t2)
| Word64 -> Word64 -> Bool
zero Word64
k1 Word64
m2 = Word64
-> Word64 -> f (Word64Map c) -> f (Word64Map c) -> f (Word64Map c)
forall (f :: * -> *) a.
Applicative f =>
Word64
-> Word64 -> f (Word64Map a) -> f (Word64Map a) -> f (Word64Map a)
binA Word64
p2 Word64
m2 (Word64Map b -> f (Word64Map c)
merge2 Word64Map b
l2) (Word64Map b -> f (Word64Map c)
g2t Word64Map b
r2)
| Bool
otherwise = Word64
-> Word64 -> f (Word64Map c) -> f (Word64Map c) -> f (Word64Map c)
forall (f :: * -> *) a.
Applicative f =>
Word64
-> Word64 -> f (Word64Map a) -> f (Word64Map a) -> f (Word64Map a)
binA Word64
p2 Word64
m2 (Word64Map b -> f (Word64Map c)
g2t Word64Map b
l2) (Word64Map b -> f (Word64Map c)
merge2 Word64Map b
r2)
merge2 (Tip Word64
k2 b
x2) = Word64 -> a -> Word64 -> b -> f (Word64Map c)
mergeTips Word64
k1 a
x1 Word64
k2 b
x2
merge2 Word64Map b
Nil = (Word64 -> a -> f (Maybe c)) -> Word64 -> a -> f (Word64Map c)
forall {f :: * -> *} {t} {a}.
Functor f =>
(Word64 -> t -> f (Maybe a)) -> Word64 -> t -> f (Word64Map a)
subsingletonBy Word64 -> a -> f (Maybe c)
g1k Word64
k1 a
x1
go Word64Map a
t1' (Tip Word64
k2 b
x2) = Word64Map a -> f (Word64Map c)
merge1 Word64Map a
t1'
where
merge1 :: Word64Map a -> f (Word64Map c)
merge1 t1 :: Word64Map a
t1@(Bin Word64
p1 Word64
m1 Word64Map a
l1 Word64Map a
r1)
| Word64 -> Word64 -> Word64 -> Bool
nomatch Word64
k2 Word64
p1 Word64
m1 = Word64
-> f (Word64Map c) -> Word64 -> f (Word64Map c) -> f (Word64Map c)
forall (f :: * -> *) a.
Applicative f =>
Word64
-> f (Word64Map a) -> Word64 -> f (Word64Map a) -> f (Word64Map a)
linkA Word64
p1 (Word64Map a -> f (Word64Map c)
g1t Word64Map a
t1