{-# 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
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
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
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]
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) Word64
k2 ((Word64 -> b -> f (Maybe c)) -> Word64 -> b -> f (Word64Map c)
forall {f :: * -> *} {t} {a}.
Functor f =>
(Word64 -> t -> f (Maybe a)) -> Word64 -> t -> f (Word64Map a)
subsingletonBy Word64 -> b -> f (Maybe c)
g2k Word64
k2 b
x2)
| Word64 -> Word64 -> Bool
zero Word64
k2 Word64
m1 = 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
p1 Word64
m1 (Word64Map a -> f (Word64Map c)
merge1 Word64Map a
l1) (Word64Map a -> f (Word64Map c)
g1t Word64Map a
r1)
| 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
p1 Word64
m1 (Word64Map a -> f (Word64Map c)
g1t Word64Map a
l1) (Word64Map a -> f (Word64Map c)
merge1 Word64Map a
r1)
merge1 (Tip Word64
k1 a
x1) = Word64 -> a -> Word64 -> b -> f (Word64Map c)
mergeTips Word64
k1 a
x1 Word64
k2 b
x2
merge1 Word64Map a
Nil = (Word64 -> b -> f (Maybe c)) -> Word64 -> b -> f (Word64Map c)
forall {f :: * -> *} {t} {a}.
Functor f =>
(Word64 -> t -> f (Maybe a)) -> Word64 -> t -> f (Word64Map a)
subsingletonBy Word64 -> b -> f (Maybe c)
g2k Word64
k2 b
x2
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 = f (Word64Map c)
merge1
| Word64 -> Word64 -> Bool
shorter Word64
m2 Word64
m1 = f (Word64Map c)
merge2
| Word64
p1 Word64 -> Word64 -> Bool
forall a. Eq a => a -> a -> Bool
== Word64
p2 = 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
p1 Word64
m1 (Word64Map a -> Word64Map b -> f (Word64Map c)
go Word64Map a
l1 Word64Map b
l2) (Word64Map a -> Word64Map b -> f (Word64Map c)
go Word64Map a
r1 Word64Map b
r2)
| Bool
otherwise = 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) Word64
p2 (Word64Map b -> f (Word64Map c)
g2t Word64Map b
t2)
where
merge1 :: f (Word64Map c)
merge1 | Word64 -> Word64 -> Word64 -> Bool
nomatch Word64
p2 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) Word64
p2 (Word64Map b -> f (Word64Map c)
g2t Word64Map b
t2)
| Word64 -> Word64 -> Bool
zero Word64
p2 Word64
m1 = 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
p1 Word64
m1 (Word64Map a -> Word64Map b -> f (Word64Map c)
go Word64Map a
l1 Word64Map b
t2) (Word64Map a -> f (Word64Map c)
g1t Word64Map a
r1)
| 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
p1 Word64
m1 (Word64Map a -> f (Word64Map c)
g1t Word64Map a
l1) (Word64Map a -> Word64Map b -> f (Word64Map c)
go Word64Map a
r1 Word64Map b
t2)
merge2 :: f (Word64Map c)
merge2 | Word64 -> Word64 -> Word64 -> Bool
nomatch Word64
p1 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
p1 (Word64Map a -> f (Word64Map c)
g1t Word64Map a
t1) Word64
p2 (Word64Map b -> f (Word64Map c)
g2t Word64Map b
t2)
| Word64 -> Word64 -> Bool
zero Word64
p1 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 a -> Word64Map b -> f (Word64Map c)
go Word64Map a
t1 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 a -> Word64Map b -> f (Word64Map c)
go Word64Map a
t1 Word64Map b
r2)
subsingletonBy :: (Word64 -> t -> f (Maybe a)) -> Word64 -> t -> f (Word64Map a)
subsingletonBy Word64 -> t -> f (Maybe a)
gk Word64
k t
x = Word64Map a -> (a -> Word64Map a) -> Maybe a -> Word64Map a
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Word64Map a
forall a. Word64Map a
Nil (Word64 -> a -> Word64Map a
forall a. Word64 -> a -> Word64Map a
Tip Word64
k) (Maybe a -> Word64Map a) -> f (Maybe a) -> f (Word64Map a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Word64 -> t -> f (Maybe a)
gk Word64
k t
x
{-# INLINE subsingletonBy #-}
mergeTips :: Word64 -> a -> Word64 -> b -> f (Word64Map c)
mergeTips Word64
k1 a
x1 Word64
k2 b
x2
| Word64
k1 Word64 -> Word64 -> Bool
forall a. Eq a => a -> a -> Bool
== Word64
k2 = Word64Map c -> (c -> Word64Map c) -> Maybe c -> Word64Map c
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Word64Map c
forall a. Word64Map a
Nil (Word64 -> c -> Word64Map c
forall a. Word64 -> a -> Word64Map a
Tip Word64
k1) (Maybe c -> Word64Map c) -> f (Maybe c) -> f (Word64Map c)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Word64 -> a -> b -> f (Maybe c)
f Word64
k1 a
x1 b
x2
| Word64
k1 Word64 -> Word64 -> Bool
forall a. Ord a => a -> a -> Bool
< Word64
k2 = (Maybe c -> Maybe c -> Word64Map c)
-> f (Maybe c) -> f (Maybe c) -> f (Word64Map c)
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 -> Maybe c -> Maybe c -> Word64Map c
forall {a}. Word64 -> Word64 -> Maybe a -> Maybe a -> Word64Map a
subdoubleton Word64
k1 Word64
k2) (Word64 -> a -> f (Maybe c)
g1k Word64
k1 a
x1) (Word64 -> b -> f (Maybe c)
g2k Word64
k2 b
x2)
| Bool
otherwise = (Maybe c -> Maybe c -> Word64Map c)
-> f (Maybe c) -> f (Maybe c) -> f (Word64Map c)
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 -> Maybe c -> Maybe c -> Word64Map c
forall {a}. Word64 -> Word64 -> Maybe a -> Maybe a -> Word64Map a
subdoubleton Word64
k2 Word64
k1) (Word64 -> b -> f (Maybe c)
g2k Word64
k2 b
x2) (Word64 -> a -> f (Maybe c)
g1k Word64
k1 a
x1)
{-# INLINE mergeTips #-}
subdoubleton :: Word64 -> Word64 -> Maybe a -> Maybe a -> Word64Map a
subdoubleton Word64
_ Word64
_ Maybe a
Nothing Maybe a
Nothing = Word64Map a
forall a. Word64Map a
Nil
subdoubleton Word64
_ Word64
k2 Maybe a
Nothing (Just a
y2) = Word64 -> a -> Word64Map a
forall a. Word64 -> a -> Word64Map a
Tip Word64
k2 a
y2
subdoubleton Word64
k1 Word64
_ (Just a
y1) Maybe a
Nothing = Word64 -> a -> Word64Map a
forall a. Word64 -> a -> Word64Map a
Tip Word64
k1 a
y1
subdoubleton Word64
k1 Word64
k2 (Just a
y1) (Just a
y2) = Word64 -> Word64Map a -> Word64 -> Word64Map a -> Word64Map a
forall a.
Word64 -> Word64Map a -> Word64 -> Word64Map a -> Word64Map a
link Word64
k1 (Word64 -> a -> Word64Map a
forall a. Word64 -> a -> Word64Map a
Tip Word64
k1 a
y1) Word64
k2 (Word64 -> a -> Word64Map a
forall a. Word64 -> a -> Word64Map a
Tip Word64
k2 a
y2)
{-# INLINE subdoubleton #-}
linkA
:: Applicative f
=> Prefix -> f (Word64Map a)
-> Prefix -> f (Word64Map a)
-> f (Word64Map a)
linkA :: forall (f :: * -> *) a.
Applicative f =>
Word64
-> f (Word64Map a) -> Word64 -> f (Word64Map a) -> f (Word64Map a)
linkA Word64
p1 f (Word64Map a)
t1 Word64
p2 f (Word64Map a)
t2
| Word64 -> Word64 -> Bool
zero Word64
p1 Word64
m = Word64
-> Word64 -> f (Word64Map a) -> f (Word64Map a) -> f (Word64Map a)
forall (f :: * -> *) a.
Applicative f =>
Word64
-> Word64 -> f (Word64Map a) -> f (Word64Map a) -> f (Word64Map a)
binA Word64
p Word64
m f (Word64Map a)
t1 f (Word64Map a)
t2
| Bool
otherwise = Word64
-> Word64 -> f (Word64Map a) -> f (Word64Map a) -> f (Word64Map a)
forall (f :: * -> *) a.
Applicative f =>
Word64
-> Word64 -> f (Word64Map a) -> f (Word64Map a) -> f (Word64Map a)
binA Word64
p Word64
m f (Word64Map a)
t2 f (Word64Map a)
t1
where
m :: Word64
m = Word64 -> Word64 -> Word64
branchMask Word64
p1 Word64
p2
p :: Word64
p = Word64 -> Word64 -> Word64
mask Word64
p1 Word64
m
{-# INLINE linkA #-}
binA
:: Applicative f
=> Prefix
-> Mask
-> f (Word64Map a)
-> f (Word64Map a)
-> f (Word64Map a)
binA :: forall (f :: * -> *) a.
Applicative f =>
Word64
-> Word64 -> f (Word64Map a) -> f (Word64Map a) -> f (Word64Map a)
binA Word64
p Word64
m f (Word64Map a)
a f (Word64Map a)
b
| 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)) f (Word64Map a)
b f (Word64Map a)
a
| 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) f (Word64Map a)
a f (Word64Map a)
b
{-# INLINE binA #-}
{-# INLINE mergeA #-}
updateMinWithKey :: (Key -> a -> Maybe a) -> Word64Map a -> Word64Map a
updateMinWithKey :: forall a. (Word64 -> a -> Maybe a) -> Word64Map a -> Word64Map a
updateMinWithKey Word64 -> a -> Maybe a
f Word64Map a
t =
case Word64Map a
t of 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 -> 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) -> Word64Map a -> Word64Map a
forall a. (Word64 -> a -> Maybe a) -> Word64Map a -> Word64Map a
go Word64 -> a -> Maybe a
f Word64Map a
r)
Word64Map a
_ -> (Word64 -> a -> Maybe a) -> Word64Map a -> Word64Map a
forall a. (Word64 -> a -> Maybe a) -> Word64Map a -> Word64Map a
go Word64 -> a -> Maybe a
f Word64Map a
t
where
go :: (Word64 -> t -> Maybe t) -> Word64Map t -> Word64Map t
go Word64 -> t -> Maybe t
f' (Bin Word64
p Word64
m Word64Map t
l Word64Map t
r) = Word64 -> Word64 -> Word64Map t -> Word64Map t -> Word64Map t
forall a.
Word64 -> Word64 -> Word64Map a -> Word64Map a -> Word64Map a
binCheckLeft Word64
p Word64
m ((Word64 -> t -> Maybe t) -> Word64Map t -> Word64Map t
go Word64 -> t -> Maybe t
f' Word64Map t
l) Word64Map t
r
go Word64 -> t -> Maybe t
f' (Tip Word64
k t
y) = case Word64 -> t -> Maybe t
f' Word64
k t
y of
Just t
y' -> Word64 -> t -> Word64Map t
forall a. Word64 -> a -> Word64Map a
Tip Word64
k t
y'
Maybe t
Nothing -> Word64Map t
forall a. Word64Map a
Nil
go Word64 -> t -> Maybe t
_ Word64Map t
Nil = [Char] -> Word64Map t
forall a. HasCallStack => [Char] -> a
error [Char]
"updateMinWithKey Nil"
updateMaxWithKey :: (Key -> a -> Maybe a) -> Word64Map a -> Word64Map a
updateMaxWithKey :: forall a. (Word64 -> a -> Maybe a) -> Word64Map a -> Word64Map a
updateMaxWithKey Word64 -> a -> Maybe a
f Word64Map a
t =
case Word64Map a
t of 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 -> 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) -> Word64Map a -> Word64Map a
forall a. (Word64 -> a -> Maybe a) -> Word64Map a -> Word64Map a
go Word64 -> a -> Maybe a
f Word64Map a
l) Word64Map a
r
Word64Map a
_ -> (Word64 -> a -> Maybe a) -> Word64Map a -> Word64Map a
forall a. (Word64 -> a -> Maybe a) -> Word64Map a -> Word64Map a
go Word64 -> a -> Maybe a
f Word64Map a
t
where
go :: (Word64 -> t -> Maybe t) -> Word64Map t -> Word64Map t
go Word64 -> t -> Maybe t
f' (Bin Word64
p Word64
m Word64Map t
l Word64Map t
r) = Word64 -> Word64 -> Word64Map t -> Word64Map t -> Word64Map t
forall a.
Word64 -> Word64 -> Word64Map a -> Word64Map a -> Word64Map a
binCheckRight Word64
p Word64
m Word64Map t
l ((Word64 -> t -> Maybe t) -> Word64Map t -> Word64Map t
go Word64 -> t -> Maybe t
f' Word64Map t
r)
go Word64 -> t -> Maybe t
f' (Tip Word64
k t
y) = case Word64 -> t -> Maybe t
f' Word64
k t
y of
Just t
y' -> Word64 -> t -> Word64Map t
forall a. Word64 -> a -> Word64Map a
Tip Word64
k t
y'
Maybe t
Nothing -> Word64Map t
forall a. Word64Map a
Nil
go Word64 -> t -> Maybe t
_ Word64Map t
Nil = [Char] -> Word64Map t
forall a. HasCallStack => [Char] -> a
error [Char]
"updateMaxWithKey Nil"
data View a = View {-# UNPACK #-} !Key a !(Word64Map a)
maxViewWithKey :: Word64Map a -> Maybe ((Key, a), Word64Map a)
maxViewWithKey :: forall a. Word64Map a -> Maybe ((Word64, a), Word64Map a)
maxViewWithKey Word64Map a
t = case Word64Map a
t of
Word64Map a
Nil -> Maybe ((Word64, a), Word64Map a)
forall a. Maybe a
Nothing
Word64Map a
_ -> ((Word64, a), Word64Map a) -> Maybe ((Word64, a), Word64Map a)
forall a. a -> Maybe a
Just (((Word64, a), Word64Map a) -> Maybe ((Word64, a), Word64Map a))
-> ((Word64, a), Word64Map a) -> Maybe ((Word64, a), Word64Map a)
forall a b. (a -> b) -> a -> b
$ case Word64Map a -> View a
forall a. Word64Map a -> View a
maxViewWithKeySure Word64Map a
t of
View Word64
k a
v Word64Map a
t' -> ((Word64
k, a
v), Word64Map a
t')
{-# INLINE maxViewWithKey #-}
maxViewWithKeySure :: Word64Map a -> View a
maxViewWithKeySure :: forall a. Word64Map a -> View a
maxViewWithKeySure Word64Map a
t =
case Word64Map a
t of
Word64Map a
Nil -> [Char] -> View a
forall a. HasCallStack => [Char] -> a
error [Char]
"maxViewWithKeySure Nil"
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 ->
case Word64Map a -> View a
forall a. Word64Map a -> View a
go Word64Map a
l of View Word64
k a
a Word64Map a
l' -> Word64 -> a -> Word64Map a -> View a
forall a. Word64 -> a -> Word64Map a -> View a
View Word64
k a
a (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)
Word64Map a
_ -> Word64Map a -> View a
forall a. Word64Map a -> View a
go Word64Map a
t
where
go :: Word64Map a -> View a
go (Bin Word64
p Word64
m Word64Map a
l Word64Map a
r) =
case Word64Map a -> View a
go Word64Map a
r of View Word64
k a
a Word64Map a
r' -> Word64 -> a -> Word64Map a -> View a
forall a. Word64 -> a -> Word64Map a -> View a
View Word64
k a
a (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')
go (Tip Word64
k a
y) = Word64 -> a -> Word64Map a -> View a
forall a. Word64 -> a -> Word64Map a -> View a
View Word64
k a
y Word64Map a
forall a. Word64Map a
Nil
go Word64Map a
Nil = [Char] -> View a
forall a. HasCallStack => [Char] -> a
error [Char]
"maxViewWithKey_go Nil"
{-# NOINLINE maxViewWithKeySure #-}
minViewWithKey :: Word64Map a -> Maybe ((Key, a), Word64Map a)
minViewWithKey :: forall a. Word64Map a -> Maybe ((Word64, a), Word64Map a)
minViewWithKey Word64Map a
t =
case Word64Map a
t of
Word64Map a
Nil -> Maybe ((Word64, a), Word64Map a)
forall a. Maybe a
Nothing
Word64Map a
_ -> ((Word64, a), Word64Map a) -> Maybe ((Word64, a), Word64Map a)
forall a. a -> Maybe a
Just (((Word64, a), Word64Map a) -> Maybe ((Word64, a), Word64Map a))
-> ((Word64, a), Word64Map a) -> Maybe ((Word64, a), Word64Map a)
forall a b. (a -> b) -> a -> b
$ case Word64Map a -> View a
forall a. Word64Map a -> View a
minViewWithKeySure Word64Map a
t of
View Word64
k a
v Word64Map a
t' -> ((Word64
k, a
v), Word64Map a
t')
{-# INLINE minViewWithKey #-}
minViewWithKeySure :: Word64Map a -> View a
minViewWithKeySure :: forall a. Word64Map a -> View a
minViewWithKeySure Word64Map a
t =
case Word64Map a
t of
Word64Map a
Nil -> [Char] -> View a
forall a. HasCallStack => [Char] -> a
error [Char]
"minViewWithKeySure Nil"
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 ->
case Word64Map a -> View a
forall a. Word64Map a -> View a
go Word64Map a
r of
View Word64
k a
a Word64Map a
r' -> Word64 -> a -> Word64Map a -> View a
forall a. Word64 -> a -> Word64Map a -> View a
View Word64
k a
a (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')
Word64Map a
_ -> Word64Map a -> View a
forall a. Word64Map a -> View a
go Word64Map a
t
where
go :: Word64Map a -> View a
go (Bin Word64
p Word64
m Word64Map a
l Word64Map a
r) =
case Word64Map a -> View a
go Word64Map a
l of View Word64
k a
a Word64Map a
l' -> Word64 -> a -> Word64Map a -> View a
forall a. Word64 -> a -> Word64Map a -> View a
View Word64
k a
a (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)
go (Tip Word64
k a
y) = Word64 -> a -> Word64Map a -> View a
forall a. Word64 -> a -> Word64Map a -> View a
View Word64
k a
y Word64Map a
forall a. Word64Map a
Nil
go Word64Map a
Nil = [Char] -> View a
forall a. HasCallStack => [Char] -> a
error [Char]
"minViewWithKey_go Nil"
{-# NOINLINE minViewWithKeySure #-}
updateMax :: (a -> Maybe a) -> Word64Map a -> Word64Map a
updateMax :: forall a. (a -> Maybe a) -> Word64Map a -> Word64Map a
updateMax a -> Maybe a
f = (Word64 -> a -> Maybe a) -> Word64Map a -> Word64Map a
forall a. (Word64 -> a -> Maybe a) -> Word64Map a -> Word64Map a
updateMaxWithKey ((a -> Maybe a) -> Word64 -> a -> Maybe a
forall a b. a -> b -> a
const a -> Maybe a
f)
updateMin :: (a -> Maybe a) -> Word64Map a -> Word64Map a
updateMin :: forall a. (a -> Maybe a) -> Word64Map a -> Word64Map a
updateMin a -> Maybe a
f = (Word64 -> a -> Maybe a) -> Word64Map a -> Word64Map a
forall a. (Word64 -> a -> Maybe a) -> Word64Map a -> Word64Map a
updateMinWithKey ((a -> Maybe a) -> Word64 -> a -> Maybe a
forall a b. a -> b -> a
const a -> Maybe a
f)
maxView :: Word64Map a -> Maybe (a, Word64Map a)
maxView :: forall a. Word64Map a -> Maybe (a, Word64Map a)
maxView Word64Map a
t = (((Word64, a), Word64Map a) -> (a, Word64Map a))
-> Maybe ((Word64, a), Word64Map a) -> Maybe (a, Word64Map a)
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (\((Word64
_, a
x), Word64Map a
t') -> (a
x, Word64Map a
t')) (Word64Map a -> Maybe ((Word64, a), Word64Map a)
forall a. Word64Map a -> Maybe ((Word64, a), Word64Map a)
maxViewWithKey Word64Map a
t)
minView :: Word64Map a -> Maybe (a, Word64Map a)
minView :: forall a. Word64Map a -> Maybe (a, Word64Map a)
minView Word64Map a
t = (((Word64, a), Word64Map a) -> (a, Word64Map a))
-> Maybe ((Word64, a), Word64Map a) -> Maybe (a, Word64Map a)
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (\((Word64
_, a
x), Word64Map a
t') -> (a
x, Word64Map a
t')) (Word64Map a -> Maybe ((Word64, a), Word64Map a)
forall a. Word64Map a -> Maybe ((Word64, a), Word64Map a)
minViewWithKey Word64Map a
t)
deleteFindMax :: Word64Map a -> ((Key, a), Word64Map a)
deleteFindMax :: forall a. Word64Map a -> ((Word64, a), Word64Map a)
deleteFindMax = ((Word64, a), Word64Map a)
-> Maybe ((Word64, a), Word64Map a) -> ((Word64, a), Word64Map a)
forall a. a -> Maybe a -> a
fromMaybe ([Char] -> ((Word64, a), Word64Map a)
forall a. HasCallStack => [Char] -> a
error [Char]
"deleteFindMax: empty map has no maximal element") (Maybe ((Word64, a), Word64Map a) -> ((Word64, a), Word64Map a))
-> (Word64Map a -> Maybe ((Word64, a), Word64Map a))
-> Word64Map a
-> ((Word64, a), Word64Map a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word64Map a -> Maybe ((Word64, a), Word64Map a)
forall a. Word64Map a -> Maybe ((Word64, a), Word64Map a)
maxViewWithKey
deleteFindMin :: Word64Map a -> ((Key, a), Word64Map a)
deleteFindMin :: forall a. Word64Map a -> ((Word64, a), Word64Map a)
deleteFindMin = ((Word64, a), Word64Map a)
-> Maybe ((Word64, a), Word64Map a) -> ((Word64, a), Word64Map a)
forall a. a -> Maybe a -> a
fromMaybe ([Char] -> ((Word64, a), Word64Map a)
forall a. HasCallStack => [Char] -> a
error [Char]
"deleteFindMin: empty map has no minimal element") (Maybe ((Word64, a), Word64Map a) -> ((Word64, a), Word64Map a))
-> (Word64Map a -> Maybe ((Word64, a), Word64Map a))
-> Word64Map a
-> ((Word64, a), Word64Map a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word64Map a -> Maybe ((Word64, a), Word64Map a)
forall a. Word64Map a -> Maybe ((Word64, a), Word64Map a)
minViewWithKey
lookupMin :: Word64Map a -> Maybe (Key, a)
lookupMin :: forall a. Word64Map a -> Maybe (Word64, a)
lookupMin Word64Map a
Nil = Maybe (Word64, a)
forall a. Maybe a
Nothing
lookupMin (Tip Word64
k a
v) = (Word64, a) -> Maybe (Word64, a)
forall a. a -> Maybe a
Just (Word64
k,a
v)
lookupMin (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 -> Maybe (Word64, a)
forall a. Word64Map a -> Maybe (Word64, a)
go Word64Map a
r
| Bool
otherwise = Word64Map a -> Maybe (Word64, a)
forall a. Word64Map a -> Maybe (Word64, a)
go Word64Map a
l
where go :: Word64Map b -> Maybe (Word64, b)
go (Tip Word64
k b
v) = (Word64, b) -> Maybe (Word64, b)
forall a. a -> Maybe a
Just (Word64
k,b
v)
go (Bin Word64
_ Word64
_ Word64Map b
l' Word64Map b
_) = Word64Map b -> Maybe (Word64, b)
go Word64Map b
l'
go Word64Map b
Nil = Maybe (Word64, b)
forall a. Maybe a
Nothing
findMin :: Word64Map a -> (Key, a)
findMin :: forall a. Word64Map a -> (Word64, a)
findMin Word64Map a
t
| Just (Word64, a)
r <- Word64Map a -> Maybe (Word64, a)
forall a. Word64Map a -> Maybe (Word64, a)
lookupMin Word64Map a
t = (Word64, a)
r
| Bool
otherwise = [Char] -> (Word64, a)
forall a. HasCallStack => [Char] -> a
error [Char]
"findMin: empty map has no minimal element"
lookupMax :: Word64Map a -> Maybe (Key, a)
lookupMax :: forall a. Word64Map a -> Maybe (Word64, a)
lookupMax Word64Map a
Nil = Maybe (Word64, a)
forall a. Maybe a
Nothing
lookupMax (Tip Word64
k a
v) = (Word64, a) -> Maybe (Word64, a)
forall a. a -> Maybe a
Just (Word64
k,a
v)
lookupMax (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 -> Maybe (Word64, a)
forall a. Word64Map a -> Maybe (Word64, a)
go Word64Map a
l
| Bool
otherwise = Word64Map a -> Maybe (Word64, a)
forall a. Word64Map a -> Maybe (Word64, a)
go Word64Map a
r
where go :: Word64Map b -> Maybe (Word64, b)
go (Tip Word64
k b
v) = (Word64, b) -> Maybe (Word64, b)
forall a. a -> Maybe a
Just (Word64
k,b
v)
go (Bin Word64
_ Word64
_ Word64Map b
_ Word64Map b
r') = Word64Map b -> Maybe (Word64, b)
go Word64Map b
r'
go Word64Map b
Nil = Maybe (Word64, b)
forall a. Maybe a
Nothing
findMax :: Word64Map a -> (Key, a)
findMax :: forall a. Word64Map a -> (Word64, a)
findMax Word64Map a
t
| Just (Word64, a)
r <- Word64Map a -> Maybe (Word64, a)
forall a. Word64Map a -> Maybe (Word64, a)
lookupMax Word64Map a
t = (Word64, a)
r
| Bool
otherwise = [Char] -> (Word64, a)
forall a. HasCallStack => [Char] -> a
error [Char]
"findMax: empty map has no maximal element"
deleteMin :: Word64Map a -> Word64Map a
deleteMin :: forall a. Word64Map a -> Word64Map a
deleteMin = Word64Map a
-> ((a, Word64Map a) -> Word64Map a)
-> Maybe (a, Word64Map a)
-> Word64Map a
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Word64Map a
forall a. Word64Map a
Nil (a, Word64Map a) -> Word64Map a
forall a b. (a, b) -> b
snd (Maybe (a, Word64Map a) -> Word64Map a)
-> (Word64Map a -> Maybe (a, Word64Map a))
-> Word64Map a
-> Word64Map a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word64Map a -> Maybe (a, Word64Map a)
forall a. Word64Map a -> Maybe (a, Word64Map a)
minView
deleteMax :: Word64Map a -> Word64Map a
deleteMax :: forall a. Word64Map a -> Word64Map a
deleteMax = Word64Map a
-> ((a, Word64Map a) -> Word64Map a)
-> Maybe (a, Word64Map a)
-> Word64Map a
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Word64Map a
forall a. Word64Map a
Nil (a, Word64Map a) -> Word64Map a
forall a b. (a, b) -> b
snd (Maybe (a, Word64Map a) -> Word64Map a)
-> (Word64Map a -> Maybe (a, Word64Map a))
-> Word64Map a
-> Word64Map a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word64Map a -> Maybe (a, Word64Map a)
forall a. Word64Map a -> Maybe (a, Word64Map a)
maxView
isProperSubmapOf :: Eq a => Word64Map a -> Word64Map a -> Bool
isProperSubmapOf :: forall a. Eq a => Word64Map a -> Word64Map a -> Bool
isProperSubmapOf Word64Map a
m1 Word64Map a
m2
= (a -> a -> Bool) -> Word64Map a -> Word64Map a -> Bool
forall a b. (a -> b -> Bool) -> Word64Map a -> Word64Map b -> Bool
isProperSubmapOfBy a -> a -> Bool
forall a. Eq a => a -> a -> Bool
(==) Word64Map a
m1 Word64Map a
m2
isProperSubmapOfBy :: (a -> b -> Bool) -> Word64Map a -> Word64Map b -> Bool
isProperSubmapOfBy :: forall a b. (a -> b -> Bool) -> Word64Map a -> Word64Map b -> Bool
isProperSubmapOfBy a -> b -> Bool
predicate Word64Map a
t1 Word64Map b
t2
= case (a -> b -> Bool) -> Word64Map a -> Word64Map b -> Ordering
forall a b.
(a -> b -> Bool) -> Word64Map a -> Word64Map b -> Ordering
submapCmp a -> b -> Bool
predicate Word64Map a
t1 Word64Map b
t2 of
Ordering
LT -> Bool
True
Ordering
_ -> Bool
False
submapCmp :: (a -> b -> Bool) -> Word64Map a -> Word64Map b -> Ordering
submapCmp :: forall a b.
(a -> b -> Bool) -> Word64Map a -> Word64Map b -> Ordering
submapCmp a -> b -> Bool
predicate t1 :: Word64Map a
t1@(Bin Word64
p1 Word64
m1 Word64Map a
l1 Word64Map a
r1) (Bin Word64
p2 Word64
m2 Word64Map b
l2 Word64Map b
r2)
| Word64 -> Word64 -> Bool
shorter Word64
m1 Word64
m2 = Ordering
GT
| Word64 -> Word64 -> Bool
shorter Word64
m2 Word64
m1 = Ordering
submapCmpLt
| Word64
p1 Word64 -> Word64 -> Bool
forall a. Eq a => a -> a -> Bool
== Word64
p2 = Ordering
submapCmpEq
| Bool
otherwise = Ordering
GT
where
submapCmpLt :: Ordering
submapCmpLt | Word64 -> Word64 -> Word64 -> Bool
nomatch Word64
p1 Word64
p2 Word64
m2 = Ordering
GT
| Word64 -> Word64 -> Bool
zero Word64
p1 Word64
m2 = (a -> b -> Bool) -> Word64Map a -> Word64Map b -> Ordering
forall a b.
(a -> b -> Bool) -> Word64Map a -> Word64Map b -> Ordering
submapCmp a -> b -> Bool
predicate Word64Map a
t1 Word64Map b
l2
| Bool
otherwise = (a -> b -> Bool) -> Word64Map a -> Word64Map b -> Ordering
forall a b.
(a -> b -> Bool) -> Word64Map a -> Word64Map b -> Ordering
submapCmp a -> b -> Bool
predicate Word64Map a
t1 Word64Map b
r2
submapCmpEq :: Ordering
submapCmpEq = case ((a -> b -> Bool) -> Word64Map a -> Word64Map b -> Ordering
forall a b.
(a -> b -> Bool) -> Word64Map a -> Word64Map b -> Ordering
submapCmp a -> b -> Bool
predicate Word64Map a
l1 Word64Map b
l2, (a -> b -> Bool) -> Word64Map a -> Word64Map b -> Ordering
forall a b.
(a -> b -> Bool) -> Word64Map a -> Word64Map b -> Ordering
submapCmp a -> b -> Bool
predicate Word64Map a
r1 Word64Map b
r2) of
(Ordering
GT,Ordering
_ ) -> Ordering
GT
(Ordering
_ ,Ordering
GT) -> Ordering
GT
(Ordering
EQ,Ordering
EQ) -> Ordering
EQ
(Ordering, Ordering)
_ -> Ordering
LT
submapCmp a -> b -> Bool
_ (Bin Word64
_ Word64
_ Word64Map a
_ Word64Map a
_) Word64Map b
_ = Ordering
GT
submapCmp a -> b -> Bool
predicate (Tip Word64
kx a
x) (Tip Word64
ky b
y)
| (Word64
kx Word64 -> Word64 -> Bool
forall a. Eq a => a -> a -> Bool
== Word64
ky) Bool -> Bool -> Bool
&& a -> b -> Bool
predicate a
x b
y = Ordering
EQ
| Bool
otherwise = Ordering
GT
submapCmp a -> b -> Bool
predicate (Tip Word64
k a
x) Word64Map b
t
= case Word64 -> Word64Map b -> Maybe b
forall a. Word64 -> Word64Map a -> Maybe a
lookup Word64
k Word64Map b
t of
Just b
y | a -> b -> Bool
predicate a
x b
y -> Ordering
LT
Maybe b
_ -> Ordering
GT
submapCmp a -> b -> Bool
_ Word64Map a
Nil Word64Map b
Nil = Ordering
EQ
submapCmp a -> b -> Bool
_ Word64Map a
Nil Word64Map b
_ = Ordering
LT
isSubmapOf :: Eq a => Word64Map a -> Word64Map a -> Bool
isSubmapOf :: forall a. Eq a => Word64Map a -> Word64Map a -> Bool
isSubmapOf Word64Map a
m1 Word64Map a
m2
= (a -> a -> Bool) -> Word64Map a -> Word64Map a -> Bool
forall a b. (a -> b -> Bool) -> Word64Map a -> Word64Map b -> Bool
isSubmapOfBy a -> a -> Bool
forall a. Eq a => a -> a -> Bool
(==) Word64Map a
m1 Word64Map a
m2
isSubmapOfBy :: (a -> b -> Bool) -> Word64Map a -> Word64Map b -> Bool
isSubmapOfBy :: forall a b. (a -> b -> Bool) -> Word64Map a -> Word64Map b -> Bool
isSubmapOfBy a -> b -> Bool
predicate t1 :: Word64Map a
t1@(Bin Word64
p1 Word64
m1 Word64Map a
l1 Word64Map a
r1) (Bin Word64
p2 Word64
m2 Word64Map b
l2 Word64Map b
r2)
| Word64 -> Word64 -> Bool
shorter Word64
m1 Word64
m2 = Bool
False
| Word64 -> Word64 -> Bool
shorter Word64
m2 Word64
m1 = Word64 -> Word64 -> Word64 -> Bool
match Word64
p1 Word64
p2 Word64
m2 Bool -> Bool -> Bool
&&
if Word64 -> Word64 -> Bool
zero Word64
p1 Word64
m2
then (a -> b -> Bool) -> Word64Map a -> Word64Map b -> Bool
forall a b. (a -> b -> Bool) -> Word64Map a -> Word64Map b -> Bool
isSubmapOfBy a -> b -> Bool
predicate Word64Map a
t1 Word64Map b
l2
else (a -> b -> Bool) -> Word64Map a -> Word64Map b -> Bool
forall a b. (a -> b -> Bool) -> Word64Map a -> Word64Map b -> Bool
isSubmapOfBy a -> b -> Bool
predicate Word64Map a
t1 Word64Map b
r2
| Bool
otherwise = (Word64
p1Word64 -> Word64 -> Bool
forall a. Eq a => a -> a -> Bool
==Word64
p2) Bool -> Bool -> Bool
&& (a -> b -> Bool) -> Word64Map a -> Word64Map b -> Bool
forall a b. (a -> b -> Bool) -> Word64Map a -> Word64Map b -> Bool
isSubmapOfBy a -> b -> Bool
predicate Word64Map a
l1 Word64Map b
l2 Bool -> Bool -> Bool
&& (a -> b -> Bool) -> Word64Map a -> Word64Map b -> Bool
forall a b. (a -> b -> Bool) -> Word64Map a -> Word64Map b -> Bool
isSubmapOfBy a -> b -> Bool
predicate Word64Map a
r1 Word64Map b
r2
isSubmapOfBy a -> b -> Bool
_ (Bin Word64
_ Word64
_ Word64Map a
_ Word64Map a
_) Word64Map b
_ = Bool
False
isSubmapOfBy a -> b -> Bool
predicate (Tip Word64
k a
x) Word64Map b
t = case Word64 -> Word64Map b -> Maybe b
forall a. Word64 -> Word64Map a -> Maybe a
lookup Word64
k Word64Map b
t of
Just b
y -> a -> b -> Bool
predicate a
x b
y
Maybe b
Nothing -> Bool
False
isSubmapOfBy a -> b -> Bool
_ Word64Map a
Nil Word64Map b
_ = Bool
True
map :: (a -> b) -> Word64Map a -> Word64Map b
map :: forall a b. (a -> b) -> Word64Map a -> Word64Map b
map a -> b
f = Word64Map a -> Word64Map b
go
where
go :: Word64Map a -> Word64Map b
go (Bin Word64
p Word64
m Word64Map a
l Word64Map a
r) = 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 -> Word64Map b
go Word64Map a
l) (Word64Map a -> Word64Map b
go Word64Map a
r)
go (Tip Word64
k a
x) = Word64 -> b -> Word64Map b
forall a. Word64 -> a -> Word64Map a
Tip Word64
k (a -> b
f a
x)
go Word64Map a
Nil = Word64Map b
forall a. Word64Map a
Nil
{-# NOINLINE [1] map #-}
{-# RULES
"map/map" forall f g xs . map f (map g xs) = map (f . g) xs
"map/coerce" map coerce = coerce
#-}
mapWithKey :: (Key -> a -> b) -> Word64Map a -> Word64Map b
mapWithKey :: forall a b. (Word64 -> a -> b) -> Word64Map a -> Word64Map b
mapWithKey Word64 -> a -> b
f Word64Map a
t
= case Word64Map a
t of
Bin Word64
p Word64
m Word64Map a
l Word64Map a
r -> Word64 -> Word64 -> Word64Map b -> Word64Map b -> Word64Map b
forall a.
Word64 -> Word64 -> Word64Map a -> Word64Map a -> Word64Map a
Bin Word64
p Word64
m ((Word64 -> a -> b) -> Word64Map a -> Word64Map b
forall a b. (Word64 -> a -> b) -> Word64Map a -> Word64Map b
mapWithKey Word64 -> a -> b
f Word64Map a
l) ((Word64 -> a -> b) -> Word64Map a -> Word64Map b
forall a b. (Word64 -> a -> b) -> Word64Map a -> Word64Map b
mapWithKey Word64 -> a -> b
f Word64Map a
r)
Tip Word64
k a
x -> Word64 -> b -> Word64Map b
forall a. Word64 -> a -> Word64Map a
Tip Word64
k (Word64 -> a -> b
f Word64
k a
x)
Word64Map a
Nil -> Word64Map b
forall a. Word64Map a
Nil
{-# NOINLINE [1] mapWithKey #-}
{-# RULES
"mapWithKey/mapWithKey" forall f g xs . mapWithKey f (mapWithKey g xs) =
mapWithKey (\k a -> f k (g k a)) xs
"mapWithKey/map" forall f g xs . mapWithKey f (map g xs) =
mapWithKey (\k a -> f k (g a)) xs
"map/mapWithKey" forall f g xs . map f (mapWithKey g xs) =
mapWithKey (\k a -> f (g k a)) xs
#-}
traverseWithKey :: Applicative t => (Key -> a -> t b) -> Word64Map a -> t (Word64Map b)
traverseWithKey :: forall (t :: * -> *) a b.
Applicative t =>
(Word64 -> a -> t b) -> Word64Map a -> t (Word64Map b)
traverseWithKey Word64 -> a -> t b
f = Word64Map a -> t (Word64Map b)
go
where
go :: Word64Map a -> t (Word64Map b)
go Word64Map a
Nil = Word64Map b -> t (Word64Map b)
forall a. a -> t a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Word64Map b
forall a. Word64Map a
Nil
go (Tip Word64
k a
v) = Word64 -> b -> Word64Map b
forall a. Word64 -> a -> Word64Map a
Tip Word64
k (b -> Word64Map b) -> t b -> t (Word64Map b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Word64 -> a -> t b
f Word64
k a
v
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)
-> t (Word64Map b) -> t (Word64Map b) -> t (Word64Map b)
forall a b c. (a -> b -> c) -> t a -> t b -> t 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 -> t (Word64Map b)
go Word64Map a
r) (Word64Map a -> t (Word64Map b)
go Word64Map a
l)
| Bool
otherwise = (Word64Map b -> Word64Map b -> Word64Map b)
-> t (Word64Map b) -> t (Word64Map b) -> t (Word64Map b)
forall a b c. (a -> b -> c) -> t a -> t b -> t 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 -> t (Word64Map b)
go Word64Map a
l) (Word64Map a -> t (Word64Map b)
go Word64Map a
r)
{-# INLINE traverseWithKey #-}
mapAccum :: (a -> b -> (a,c)) -> a -> Word64Map b -> (a,Word64Map c)
mapAccum :: forall a b c.
(a -> b -> (a, c)) -> a -> Word64Map b -> (a, Word64Map c)
mapAccum a -> b -> (a, c)
f = (a -> Word64 -> b -> (a, c))
-> a -> Word64Map b -> (a, Word64Map c)
forall a b c.
(a -> Word64 -> b -> (a, c))
-> a -> Word64Map b -> (a, Word64Map c)
mapAccumWithKey (\a
a' Word64
_ b
x -> a -> b -> (a, c)
f a
a' b
x)
mapAccumWithKey :: (a -> Key -> b -> (a,c)) -> a -> Word64Map b -> (a,Word64Map c)
mapAccumWithKey :: forall a b c.
(a -> Word64 -> b -> (a, c))
-> a -> Word64Map b -> (a, Word64Map c)
mapAccumWithKey a -> Word64 -> b -> (a, c)
f a
a Word64Map b
t
= (a -> Word64 -> b -> (a, c))
-> a -> Word64Map b -> (a, Word64Map c)
forall a b c.
(a -> Word64 -> b -> (a, c))
-> a -> Word64Map b -> (a, Word64Map c)
mapAccumL a -> Word64 -> b -> (a, c)
f a
a Word64Map b
t
mapAccumL :: (a -> Key -> b -> (a,c)) -> a -> Word64Map b -> (a,Word64Map c)
mapAccumL :: forall a b c.
(a -> Word64 -> b -> (a, c))
-> a -> Word64Map b -> (a, Word64Map c)
mapAccumL a -> Word64 -> b -> (a, c)
f a
a Word64Map b
t
= case Word64Map b
t of
Bin Word64
p Word64
m Word64Map b
l Word64Map b
r
| Word64
m Word64 -> Word64 -> Bool
forall a. Ord a => a -> a -> Bool
< Word64
0 ->
let (a
a1,Word64Map c
r') = (a -> Word64 -> b -> (a, c))
-> a -> Word64Map b -> (a, Word64Map c)
forall a b c.
(a -> Word64 -> b -> (a, c))
-> a -> Word64Map b -> (a, Word64Map c)
mapAccumL a -> Word64 -> b -> (a, c)
f a
a Word64Map b
r
(a
a2,Word64Map c
l') = (a -> Word64 -> b -> (a, c))
-> a -> Word64Map b -> (a, Word64Map c)
forall a b c.
(a -> Word64 -> b -> (a, c))
-> a -> Word64Map b -> (a, Word64Map c)
mapAccumL a -> Word64 -> b -> (a, c)
f a
a1 Word64Map b
l
in (a
a2,Word64 -> Word64 -> Word64Map c -> Word64Map c -> Word64Map c
forall a.
Word64 -> Word64 -> Word64Map a -> Word64Map a -> Word64Map a
Bin Word64
p Word64
m Word64Map c
l' Word64Map c
r')
| Bool
otherwise ->
let (a
a1,Word64Map c
l') = (a -> Word64 -> b -> (a, c))
-> a -> Word64Map b -> (a, Word64Map c)
forall a b c.
(a -> Word64 -> b -> (a, c))
-> a -> Word64Map b -> (a, Word64Map c)
mapAccumL a -> Word64 -> b -> (a, c)
f a
a Word64Map b
l
(a
a2,Word64Map c
r') = (a -> Word64 -> b -> (a, c))
-> a -> Word64Map b -> (a, Word64Map c)
forall a b c.
(a -> Word64 -> b -> (a, c))
-> a -> Word64Map b -> (a, Word64Map c)
mapAccumL a -> Word64 -> b -> (a, c)
f a
a1 Word64Map b
r
in (a
a2,Word64 -> Word64 -> Word64Map c -> Word64Map c -> Word64Map c
forall a.
Word64 -> Word64 -> Word64Map a -> Word64Map a -> Word64Map a
Bin Word64
p Word64
m Word64Map c
l' Word64Map c
r')
Tip Word64
k b
x -> let (a
a',c
x') = a -> Word64 -> b -> (a, c)
f a
a Word64
k b
x in (a
a',Word64 -> c -> Word64Map c
forall a. Word64 -> a -> Word64Map a
Tip Word64
k c
x')
Word64Map b
Nil -> (a
a,Word64Map c
forall a. Word64Map a
Nil)
mapAccumRWithKey :: (a -> Key -> b -> (a,c)) -> a -> Word64Map b -> (a,Word64Map c)
mapAccumRWithKey :: forall a b c.
(a -> Word64 -> b -> (a, c))
-> a -> Word64Map b -> (a, Word64Map c)
mapAccumRWithKey a -> Word64 -> b -> (a, c)
f a
a Word64Map b
t
= case Word64Map b
t of
Bin Word64
p Word64
m Word64Map b
l Word64Map b
r
| Word64
m Word64 -> Word64 -> Bool
forall a. Ord a => a -> a -> Bool
< Word64
0 ->
let (a
a1,Word64Map c
l') = (a -> Word64 -> b -> (a, c))
-> a -> Word64Map b -> (a, Word64Map c)
forall a b c.
(a -> Word64 -> b -> (a, c))
-> a -> Word64Map b -> (a, Word64Map c)
mapAccumRWithKey a -> Word64 -> b -> (a, c)
f a
a Word64Map b
l
(a
a2,Word64Map c
r') = (a -> Word64 -> b -> (a, c))
-> a -> Word64Map b -> (a, Word64Map c)
forall a b c.
(a -> Word64 -> b -> (a, c))
-> a -> Word64Map b -> (a, Word64Map c)
mapAccumRWithKey a -> Word64 -> b -> (a, c)
f a
a1 Word64Map b
r
in (a
a2,Word64 -> Word64 -> Word64Map c -> Word64Map c -> Word64Map c
forall a.
Word64 -> Word64 -> Word64Map a -> Word64Map a -> Word64Map a
Bin Word64
p Word64
m Word64Map c
l' Word64Map c
r')
| Bool
otherwise ->
let (a
a1,Word64Map c
r') = (a -> Word64 -> b -> (a, c))
-> a -> Word64Map b -> (a, Word64Map c)
forall a b c.
(a -> Word64 -> b -> (a, c))
-> a -> Word64Map b -> (a, Word64Map c)
mapAccumRWithKey a -> Word64 -> b -> (a, c)
f a
a Word64Map b
r
(a
a2,Word64Map c
l') = (a -> Word64 -> b -> (a, c))
-> a -> Word64Map b -> (a, Word64Map c)
forall a b c.
(a -> Word64 -> b -> (a, c))
-> a -> Word64Map b -> (a, Word64Map c)
mapAccumRWithKey a -> Word64 -> b -> (a, c)
f a
a1 Word64Map b
l
in (a
a2,Word64 -> Word64 -> Word64Map c -> Word64Map c -> Word64Map c
forall a.
Word64 -> Word64 -> Word64Map a -> Word64Map a -> Word64Map a
Bin Word64
p Word64
m Word64Map c
l' Word64Map c
r')
Tip Word64
k b
x -> let (a
a',c
x') = a -> Word64 -> b -> (a, c)
f a
a Word64
k b
x in (a
a',Word64 -> c -> Word64Map c
forall a. Word64 -> a -> Word64Map a
Tip Word64
k c
x')
Word64Map b
Nil -> (a
a,Word64Map c
forall a. Word64Map a
Nil)
mapKeys :: (Key->Key) -> Word64Map a -> Word64Map a
mapKeys :: forall a. (Word64 -> Word64) -> Word64Map a -> Word64Map a
mapKeys Word64 -> Word64
f = [(Word64, a)] -> Word64Map a
forall a. [(Word64, a)] -> Word64Map a
fromList ([(Word64, a)] -> Word64Map a)
-> (Word64Map a -> [(Word64, a)]) -> Word64Map a -> Word64Map a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Word64 -> a -> [(Word64, a)] -> [(Word64, a)])
-> [(Word64, a)] -> Word64Map a -> [(Word64, a)]
forall a b. (Word64 -> a -> b -> b) -> b -> Word64Map a -> b
foldrWithKey (\Word64
k a
x [(Word64, a)]
xs -> (Word64 -> Word64
f Word64
k, a
x) (Word64, a) -> [(Word64, a)] -> [(Word64, a)]
forall a. a -> [a] -> [a]
: [(Word64, a)]
xs) []
mapKeysWith :: (a -> a -> a) -> (Key->Key) -> Word64Map a -> Word64Map a
mapKeysWith :: forall a.
(a -> a -> a) -> (Word64 -> Word64) -> Word64Map a -> Word64Map a
mapKeysWith a -> a -> a
c Word64 -> Word64
f
= (a -> a -> a) -> [(Word64, a)] -> Word64Map a
forall a. (a -> a -> a) -> [(Word64, a)] -> Word64Map a
fromListWith a -> a -> a
c ([(Word64, a)] -> Word64Map a)
-> (Word64Map a -> [(Word64, a)]) -> Word64Map a -> Word64Map a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Word64 -> a -> [(Word64, a)] -> [(Word64, a)])
-> [(Word64, a)] -> Word64Map a -> [(Word64, a)]
forall a b. (Word64 -> a -> b -> b) -> b -> Word64Map a -> b
foldrWithKey (\Word64
k a
x [(Word64, a)]
xs -> (Word64 -> Word64
f Word64
k, a
x) (Word64, a) -> [(Word64, a)] -> [(Word64, a)]
forall a. a -> [a] -> [a]
: [(Word64, a)]
xs) []
mapKeysMonotonic :: (Key->Key) -> Word64Map a -> Word64Map a
mapKeysMonotonic :: forall a. (Word64 -> Word64) -> Word64Map a -> Word64Map a
mapKeysMonotonic Word64 -> Word64
f
= [(Word64, a)] -> Word64Map a
forall a. [(Word64, a)] -> Word64Map a
fromDistinctAscList ([(Word64, a)] -> Word64Map a)
-> (Word64Map a -> [(Word64, a)]) -> Word64Map a -> Word64Map a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Word64 -> a -> [(Word64, a)] -> [(Word64, a)])
-> [(Word64, a)] -> Word64Map a -> [(Word64, a)]
forall a b. (Word64 -> a -> b -> b) -> b -> Word64Map a -> b
foldrWithKey (\Word64
k a
x [(Word64, a)]
xs -> (Word64 -> Word64
f Word64
k, a
x) (Word64, a) -> [(Word64, a)] -> [(Word64, a)]
forall a. a -> [a] -> [a]
: [(Word64, a)]
xs) []
filter :: (a -> Bool) -> Word64Map a -> Word64Map a
filter :: forall a. (a -> Bool) -> Word64Map a -> Word64Map a
filter a -> Bool
p Word64Map a
m
= (Word64 -> a -> Bool) -> Word64Map a -> Word64Map a
forall a. (Word64 -> a -> Bool) -> Word64Map a -> Word64Map a
filterWithKey (\Word64
_ a
x -> a -> Bool
p a
x) Word64Map a
m
filterWithKey :: (Key -> a -> Bool) -> Word64Map a -> Word64Map a
filterWithKey :: forall a. (Word64 -> a -> Bool) -> Word64Map a -> Word64Map a
filterWithKey Word64 -> a -> Bool
predicate = Word64Map a -> Word64Map a
go
where
go :: Word64Map a -> Word64Map a
go Word64Map a
Nil = Word64Map a
forall a. Word64Map a
Nil
go t :: Word64Map a
t@(Tip Word64
k a
x) = if Word64 -> a -> Bool
predicate Word64
k a
x then Word64Map a
t else Word64Map a
forall a. Word64Map a
Nil
go (Bin Word64
p Word64
m Word64Map a
l Word64Map a
r) = 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 -> Word64Map a
go Word64Map a
l) (Word64Map a -> Word64Map a
go Word64Map a
r)
partition :: (a -> Bool) -> Word64Map a -> (Word64Map a,Word64Map a)
partition :: forall a. (a -> Bool) -> Word64Map a -> (Word64Map a, Word64Map a)
partition a -> Bool
p Word64Map a
m
= (Word64 -> a -> Bool) -> Word64Map a -> (Word64Map a, Word64Map a)
forall a.
(Word64 -> a -> Bool) -> Word64Map a -> (Word64Map a, Word64Map a)
partitionWithKey (\Word64
_ a
x -> a -> Bool
p a
x) Word64Map a
m
partitionWithKey :: (Key -> a -> Bool) -> Word64Map a -> (Word64Map a,Word64Map a)
partitionWithKey :: forall a.
(Word64 -> a -> Bool) -> Word64Map a -> (Word64Map a, Word64Map a)
partitionWithKey Word64 -> a -> Bool
predicate0 Word64Map a
t0 = StrictPair (Word64Map a) (Word64Map a)
-> (Word64Map a, Word64Map a)
forall a b. StrictPair a b -> (a, b)
toPair (StrictPair (Word64Map a) (Word64Map a)
-> (Word64Map a, Word64Map a))
-> StrictPair (Word64Map a) (Word64Map a)
-> (Word64Map a, Word64Map a)
forall a b. (a -> b) -> a -> b
$ (Word64 -> a -> Bool)
-> Word64Map a -> StrictPair (Word64Map a) (Word64Map a)
forall {a}.
(Word64 -> a -> Bool)
-> Word64Map a -> StrictPair (Word64Map a) (Word64Map a)
go Word64 -> a -> Bool
predicate0 Word64Map a
t0
where
go :: (Word64 -> a -> Bool)
-> Word64Map a -> StrictPair (Word64Map a) (Word64Map a)
go Word64 -> a -> Bool
predicate Word64Map a
t =
case Word64Map a
t of
Bin Word64
p Word64
m Word64Map a
l Word64Map a
r ->
let (Word64Map a
l1 :*: Word64Map a
l2) = (Word64 -> a -> Bool)
-> Word64Map a -> StrictPair (Word64Map a) (Word64Map a)
go Word64 -> a -> Bool
predicate Word64Map a
l
(Word64Map a
r1 :*: Word64Map a
r2) = (Word64 -> a -> Bool)
-> Word64Map a -> StrictPair (Word64Map a) (Word64Map a)
go Word64 -> a -> Bool
predicate Word64Map a
r
in 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
l1 Word64Map a
r1 Word64Map a
-> Word64Map a -> StrictPair (Word64Map a) (Word64Map a)
forall a b. a -> b -> StrictPair a b
:*: 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
l2 Word64Map a
r2
Tip Word64
k a
x
| Word64 -> a -> Bool
predicate Word64
k a
x -> (Word64Map a
t Word64Map a
-> Word64Map a -> StrictPair (Word64Map a) (Word64Map a)
forall a b. a -> b -> StrictPair a b
:*: Word64Map a
forall a. Word64Map a
Nil)
| Bool
otherwise -> (Word64Map a
forall a. Word64Map a
Nil Word64Map a
-> Word64Map a -> StrictPair (Word64Map a) (Word64Map a)
forall a b. a -> b -> StrictPair a b
:*: Word64Map a
t)
Word64Map a
Nil -> (Word64Map a
forall a. Word64Map a
Nil Word64Map a
-> Word64Map a -> StrictPair (Word64Map a) (Word64Map a)
forall a b. a -> b -> StrictPair a b
:*: Word64Map a
forall a. Word64Map a
Nil)
takeWhileAntitone :: (Key -> Bool) -> Word64Map a -> Word64Map a
takeWhileAntitone :: forall a. (Word64 -> Bool) -> Word64Map a -> Word64Map a
takeWhileAntitone Word64 -> Bool
predicate Word64Map a
t =
case Word64Map a
t of
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 ->
if Word64 -> Bool
predicate Word64
0
then Word64 -> Word64 -> Word64Map a -> Word64Map a -> Word64Map a
forall a.
Word64 -> Word64 -> Word64Map a -> Word64Map a -> Word64Map a
bin Word64
p Word64
m ((Word64 -> Bool) -> Word64Map a -> Word64Map a
forall a. (Word64 -> Bool) -> Word64Map a -> Word64Map a
go Word64 -> Bool
predicate Word64Map a
l) Word64Map a
r
else (Word64 -> Bool) -> Word64Map a -> Word64Map a
forall a. (Word64 -> Bool) -> Word64Map a -> Word64Map a
go Word64 -> Bool
predicate Word64Map a
r
Word64Map a
_ -> (Word64 -> Bool) -> Word64Map a -> Word64Map a
forall a. (Word64 -> Bool) -> Word64Map a -> Word64Map a
go Word64 -> Bool
predicate Word64Map a
t
where
go :: (Word64 -> Bool) -> Word64Map a -> Word64Map a
go Word64 -> Bool
predicate' (Bin Word64
p Word64
m Word64Map a
l Word64Map a
r)
| Word64 -> Bool
predicate' (Word64 -> Bool) -> Word64 -> Bool
forall a b. (a -> b) -> a -> b
$! Word64
pWord64 -> Word64 -> Word64
forall a. Num a => a -> a -> a
+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 Word64Map a
l ((Word64 -> Bool) -> Word64Map a -> Word64Map a
go Word64 -> Bool
predicate' Word64Map a
r)
| Bool
otherwise = (Word64 -> Bool) -> Word64Map a -> Word64Map a
go Word64 -> Bool
predicate' Word64Map a
l
go Word64 -> Bool
predicate' t' :: Word64Map a
t'@(Tip Word64
ky a
_)
| Word64 -> Bool
predicate' Word64
ky = Word64Map a
t'
| Bool
otherwise = Word64Map a
forall a. Word64Map a
Nil
go Word64 -> Bool
_ Word64Map a
Nil = Word64Map a
forall a. Word64Map a
Nil
dropWhileAntitone :: (Key -> Bool) -> Word64Map a -> Word64Map a
dropWhileAntitone :: forall a. (Word64 -> Bool) -> Word64Map a -> Word64Map a
dropWhileAntitone Word64 -> Bool
predicate Word64Map a
t =
case Word64Map a
t of
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 ->
if Word64 -> Bool
predicate Word64
0
then (Word64 -> Bool) -> Word64Map a -> Word64Map a
forall a. (Word64 -> Bool) -> Word64Map a -> Word64Map a
go Word64 -> Bool
predicate Word64Map a
l
else 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 -> Bool) -> Word64Map a -> Word64Map a
forall a. (Word64 -> Bool) -> Word64Map a -> Word64Map a
go Word64 -> Bool
predicate Word64Map a
r)
Word64Map a
_ -> (Word64 -> Bool) -> Word64Map a -> Word64Map a
forall a. (Word64 -> Bool) -> Word64Map a -> Word64Map a
go Word64 -> Bool
predicate Word64Map a
t
where
go :: (Word64 -> Bool) -> Word64Map a -> Word64Map a
go Word64 -> Bool
predicate' (Bin Word64
p Word64
m Word64Map a
l Word64Map a
r)
| Word64 -> Bool
predicate' (Word64 -> Bool) -> Word64 -> Bool
forall a b. (a -> b) -> a -> b
$! Word64
pWord64 -> Word64 -> Word64
forall a. Num a => a -> a -> a
+Word64
m = (Word64 -> Bool) -> Word64Map a -> Word64Map a
go Word64 -> Bool
predicate' 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 ((Word64 -> Bool) -> Word64Map a -> Word64Map a
go Word64 -> Bool
predicate' Word64Map a
l) Word64Map a
r
go Word64 -> Bool
predicate' t' :: Word64Map a
t'@(Tip Word64
ky a
_)
| Word64 -> Bool
predicate' Word64
ky = Word64Map a
forall a. Word64Map a
Nil
| Bool
otherwise = Word64Map a
t'
go Word64 -> Bool
_ Word64Map a
Nil = Word64Map a
forall a. Word64Map a
Nil
spanAntitone :: (Key -> Bool) -> Word64Map a -> (Word64Map a, Word64Map a)
spanAntitone :: forall a.
(Word64 -> Bool) -> Word64Map a -> (Word64Map a, Word64Map a)
spanAntitone Word64 -> Bool
predicate Word64Map a
t =
case Word64Map a
t of
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 ->
if Word64 -> Bool
predicate Word64
0
then
case (Word64 -> Bool)
-> Word64Map a -> StrictPair (Word64Map a) (Word64Map a)
forall {a}.
(Word64 -> Bool)
-> Word64Map a -> StrictPair (Word64Map a) (Word64Map a)
go Word64 -> Bool
predicate Word64Map a
l of
(Word64Map a
lt :*: Word64Map a
gt) ->
let !lt' :: Word64Map a
lt' = 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
lt Word64Map a
r
in (Word64Map a
lt', Word64Map a
gt)
else
case (Word64 -> Bool)
-> Word64Map a -> StrictPair (Word64Map a) (Word64Map a)
forall {a}.
(Word64 -> Bool)
-> Word64Map a -> StrictPair (Word64Map a) (Word64Map a)
go Word64 -> Bool
predicate Word64Map a
r of
(Word64Map a
lt :*: Word64Map a
gt) ->
let !gt' :: Word64Map a
gt' = 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
gt
in (Word64Map a
lt, Word64Map a
gt')
Word64Map a
_ -> case (Word64 -> Bool)
-> Word64Map a -> StrictPair (Word64Map a) (Word64Map a)
forall {a}.
(Word64 -> Bool)
-> Word64Map a -> StrictPair (Word64Map a) (Word64Map a)
go Word64 -> Bool
predicate Word64Map a
t of
(Word64Map a
lt :*: Word64Map a
gt) -> (Word64Map a
lt, Word64Map a
gt)
where
go :: (Word64 -> Bool)
-> Word64Map a -> StrictPair (Word64Map a) (Word64Map a)
go Word64 -> Bool
predicate' (Bin Word64
p Word64
m Word64Map a
l Word64Map a
r)
| Word64 -> Bool
predicate' (Word64 -> Bool) -> Word64 -> Bool
forall a b. (a -> b) -> a -> b
$! Word64
pWord64 -> Word64 -> Word64
forall a. Num a => a -> a -> a
+Word64
m = case (Word64 -> Bool)
-> Word64Map a -> StrictPair (Word64Map a) (Word64Map a)
go Word64 -> Bool
predicate' Word64Map a
r of (Word64Map a
lt :*: Word64Map a
gt) -> 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
lt Word64Map a
-> Word64Map a -> StrictPair (Word64Map a) (Word64Map a)
forall a b. a -> b -> StrictPair a b
:*: Word64Map a
gt
| Bool
otherwise = case (Word64 -> Bool)
-> Word64Map a -> StrictPair (Word64Map a) (Word64Map a)
go Word64 -> Bool
predicate' Word64Map a
l of (Word64Map a
lt :*: Word64Map a
gt) -> Word64Map a
lt Word64Map a
-> Word64Map a -> StrictPair (Word64Map a) (Word64Map a)
forall a b. a -> b -> StrictPair a b
:*: 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
gt Word64Map a
r
go Word64 -> Bool
predicate' t' :: Word64Map a
t'@(Tip Word64
ky a
_)
| Word64 -> Bool
predicate' Word64
ky = (Word64Map a
t' Word64Map a
-> Word64Map a -> StrictPair (Word64Map a) (Word64Map a)
forall a b. a -> b -> StrictPair a b
:*: Word64Map a
forall a. Word64Map a
Nil)
| Bool
otherwise = (Word64Map a
forall a. Word64Map a
Nil Word64Map a
-> Word64Map a -> StrictPair (Word64Map a) (Word64Map a)
forall a b. a -> b -> StrictPair a b
:*: Word64Map a
t')
go Word64 -> Bool
_ Word64Map a
Nil = (Word64Map a
forall a. Word64Map a
Nil Word64Map a
-> Word64Map a -> StrictPair (Word64Map a) (Word64Map a)
forall a b. a -> b -> StrictPair a b
:*: Word64Map a
forall a. Word64Map a
Nil)
mapMaybe :: (a -> Maybe b) -> Word64Map a -> Word64Map b
mapMaybe :: forall a b. (a -> Maybe b) -> Word64Map a -> Word64Map b
mapMaybe a -> Maybe b
f = (Word64 -> a -> Maybe b) -> Word64Map a -> Word64Map b
forall a b. (Word64 -> a -> Maybe b) -> Word64Map a -> Word64Map b
mapMaybeWithKey (\Word64
_ a
x -> a -> Maybe b
f a
x)
mapMaybeWithKey :: (Key -> a -> Maybe b) -> Word64Map a -> Word64Map b
mapMaybeWithKey :: forall a b. (Word64 -> a -> Maybe b) -> Word64Map a -> Word64Map b
mapMaybeWithKey Word64 -> a -> Maybe b
f (Bin Word64
p Word64
m Word64Map a
l Word64Map a
r)
= Word64 -> Word64 -> Word64Map b -> Word64Map b -> Word64Map b
forall a.
Word64 -> Word64 -> Word64Map a -> Word64Map a -> Word64Map a
bin Word64
p Word64
m ((Word64 -> a -> Maybe b) -> Word64Map a -> Word64Map b
forall a b. (Word64 -> a -> Maybe b) -> Word64Map a -> Word64Map b
mapMaybeWithKey Word64 -> a -> Maybe b
f Word64Map a
l) ((Word64 -> a -> Maybe b) -> Word64Map a -> Word64Map b
forall a b. (Word64 -> a -> Maybe b) -> Word64Map a -> Word64Map b
mapMaybeWithKey Word64 -> a -> Maybe b
f Word64Map a
r)
mapMaybeWithKey Word64 -> a -> Maybe b
f (Tip Word64
k a
x) = case Word64 -> a -> Maybe b
f Word64
k a
x of
Just b
y -> Word64 -> b -> Word64Map b
forall a. Word64 -> a -> Word64Map a
Tip Word64
k b
y
Maybe b
Nothing -> Word64Map b
forall a. Word64Map a
Nil
mapMaybeWithKey Word64 -> a -> Maybe b
_ Word64Map a
Nil = Word64Map b
forall a. Word64Map a
Nil
mapEither :: (a -> Either b c) -> Word64Map a -> (Word64Map b, Word64Map c)
mapEither :: forall a b c.
(a -> Either b c) -> Word64Map a -> (Word64Map b, Word64Map c)
mapEither a -> Either b c
f Word64Map a
m
= (Word64 -> a -> Either b c)
-> Word64Map a -> (Word64Map b, Word64Map c)
forall a b c.
(Word64 -> a -> Either b c)
-> Word64Map a -> (Word64Map b, Word64Map c)
mapEitherWithKey (\Word64
_ a
x -> a -> Either b c
f a
x) Word64Map a
m
mapEitherWithKey :: (Key -> a -> Either b c) -> Word64Map a -> (Word64Map b, Word64Map c)
mapEitherWithKey :: forall a b c.
(Word64 -> a -> Either b c)
-> Word64Map a -> (Word64Map b, Word64Map c)
mapEitherWithKey Word64 -> a -> Either b c
f0 Word64Map a
t0 = StrictPair (Word64Map b) (Word64Map c)
-> (Word64Map b, Word64Map c)
forall a b. StrictPair a b -> (a, b)
toPair (StrictPair (Word64Map b) (Word64Map c)
-> (Word64Map b, Word64Map c))
-> StrictPair (Word64Map b) (Word64Map c)
-> (Word64Map b, Word64Map c)
forall a b. (a -> b) -> a -> b
$ (Word64 -> a -> Either b c)
-> Word64Map a -> StrictPair (Word64Map b) (Word64Map c)
forall {t} {a} {a}.
(Word64 -> t -> Either a a)
-> Word64Map t -> StrictPair (Word64Map a) (Word64Map a)
go Word64 -> a -> Either b c
f0 Word64Map a
t0
where
go :: (Word64 -> t -> Either a a)
-> Word64Map t -> StrictPair (Word64Map a) (Word64Map a)
go Word64 -> t -> Either a a
f (Bin Word64
p Word64
m Word64Map t
l Word64Map t
r) =
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
l1 Word64Map a
r1 Word64Map a
-> Word64Map a -> StrictPair (Word64Map a) (Word64Map a)
forall a b. a -> b -> StrictPair a b
:*: 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
l2 Word64Map a
r2
where
(Word64Map a
l1 :*: Word64Map a
l2) = (Word64 -> t -> Either a a)
-> Word64Map t -> StrictPair (Word64Map a) (Word64Map a)
go Word64 -> t -> Either a a
f Word64Map t
l
(Word64Map a
r1 :*: Word64Map a
r2) = (Word64 -> t -> Either a a)
-> Word64Map t -> StrictPair (Word64Map a) (Word64Map a)
go Word64 -> t -> Either a a
f Word64Map t
r
go Word64 -> t -> Either a a
f (Tip Word64
k t
x) = case Word64 -> t -> Either a a
f Word64
k t
x of
Left a
y -> (Word64 -> a -> Word64Map a
forall a. Word64 -> a -> Word64Map a
Tip Word64
k a
y Word64Map a
-> Word64Map a -> StrictPair (Word64Map a) (Word64Map a)
forall a b. a -> b -> StrictPair a b
:*: Word64Map a
forall a. Word64Map a
Nil)
Right a
z -> (Word64Map a
forall a. Word64Map a
Nil Word64Map a
-> Word64Map a -> StrictPair (Word64Map a) (Word64Map a)
forall a b. a -> b -> StrictPair a b
:*: Word64 -> a -> Word64Map a
forall a. Word64 -> a -> Word64Map a
Tip Word64
k a
z)
go Word64 -> t -> Either a a
_ Word64Map t
Nil = (Word64Map a
forall a. Word64Map a
Nil Word64Map a
-> Word64Map a -> StrictPair (Word64Map a) (Word64Map a)
forall a b. a -> b -> StrictPair a b
:*: Word64Map a
forall a. Word64Map a
Nil)
split :: Key -> Word64Map a -> (Word64Map a, Word64Map a)
split :: forall a. Word64 -> Word64Map a -> (Word64Map a, Word64Map a)
split Word64
k Word64Map a
t =
case Word64Map a
t of
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 ->
if Word64
k Word64 -> Word64 -> Bool
forall a. Ord a => a -> a -> Bool
>= Word64
0
then
case Word64 -> Word64Map a -> StrictPair (Word64Map a) (Word64Map a)
forall {a}.
Word64 -> Word64Map a -> StrictPair (Word64Map a) (Word64Map a)
go Word64
k Word64Map a
l of
(Word64Map a
lt :*: Word64Map a
gt) ->
let !lt' :: Word64Map a
lt' = 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
lt Word64Map a
r
in (Word64Map a
lt', Word64Map a
gt)
else
case Word64 -> Word64Map a -> StrictPair (Word64Map a) (Word64Map a)
forall {a}.
Word64 -> Word64Map a -> StrictPair (Word64Map a) (Word64Map a)
go Word64
k Word64Map a
r of
(Word64Map a
lt :*: Word64Map a
gt) ->
let !gt' :: Word64Map a
gt' = 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
gt
in (Word64Map a
lt, Word64Map a
gt')
Word64Map a
_ -> case Word64 -> Word64Map a -> StrictPair (Word64Map a) (Word64Map a)
forall {a}.
Word64 -> Word64Map a -> StrictPair (Word64Map a) (Word64Map a)
go Word64
k Word64Map a
t of
(Word64Map a
lt :*: Word64Map a
gt) -> (Word64Map a
lt, Word64Map a
gt)
where
go :: Word64 -> Word64Map a -> StrictPair (Word64Map a) (Word64Map a)
go 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 = if Word64
k' Word64 -> Word64 -> Bool
forall a. Ord a => a -> a -> Bool
> Word64
p then Word64Map a
t' Word64Map a
-> Word64Map a -> StrictPair (Word64Map a) (Word64Map a)
forall a b. a -> b -> StrictPair a b
:*: Word64Map a
forall a. Word64Map a
Nil else Word64Map a
forall a. Word64Map a
Nil Word64Map a
-> Word64Map a -> StrictPair (Word64Map a) (Word64Map a)
forall a b. a -> b -> StrictPair a b
:*: Word64Map a
t'
| Word64 -> Word64 -> Bool
zero Word64
k' Word64
m = case Word64 -> Word64Map a -> StrictPair (Word64Map a) (Word64Map a)
go Word64
k' Word64Map a
l of (Word64Map a
lt :*: Word64Map a
gt) -> Word64Map a
lt Word64Map a
-> Word64Map a -> StrictPair (Word64Map a) (Word64Map a)
forall a b. a -> b -> StrictPair a b
:*: 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
gt Word64Map a
r
| Bool
otherwise = case Word64 -> Word64Map a -> StrictPair (Word64Map a) (Word64Map a)
go Word64
k' Word64Map a
r of (Word64Map a
lt :*: Word64Map a
gt) -> 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
lt Word64Map a
-> Word64Map a -> StrictPair (Word64Map a) (Word64Map a)
forall a b. a -> b -> StrictPair a b
:*: Word64Map a
gt
go Word64
k' t' :: Word64Map a
t'@(Tip Word64
ky a
_)
| Word64
k' Word64 -> Word64 -> Bool
forall a. Ord a => a -> a -> Bool
> Word64
ky = (Word64Map a
t' Word64Map a
-> Word64Map a -> StrictPair (Word64Map a) (Word64Map a)
forall a b. a -> b -> StrictPair a b
:*: Word64Map a
forall a. Word64Map a
Nil)
| Word64
k' Word64 -> Word64 -> Bool
forall a. Ord a => a -> a -> Bool
< Word64
ky = (Word64Map a
forall a. Word64Map a
Nil Word64Map a
-> Word64Map a -> StrictPair (Word64Map a) (Word64Map a)
forall a b. a -> b -> StrictPair a b
:*: Word64Map a
t')
| Bool
otherwise = (Word64Map a
forall a. Word64Map a
Nil Word64Map a
-> Word64Map a -> StrictPair (Word64Map a) (Word64Map a)
forall a b. a -> b -> StrictPair a b
:*: Word64Map a
forall a. Word64Map a
Nil)
go Word64
_ Word64Map a
Nil = (Word64Map a
forall a. Word64Map a
Nil Word64Map a
-> Word64Map a -> StrictPair (Word64Map a) (Word64Map a)
forall a b. a -> b -> StrictPair a b
:*: Word64Map a
forall a. Word64Map a
Nil)
data SplitLookup a = SplitLookup !(Word64Map a) !(Maybe a) !(Word64Map a)
mapLT :: (Word64Map a -> Word64Map a) -> SplitLookup a -> SplitLookup a
mapLT :: forall a.
(Word64Map a -> Word64Map a) -> SplitLookup a -> SplitLookup a
mapLT Word64Map a -> Word64Map a
f (SplitLookup Word64Map a
lt Maybe a
fnd Word64Map a
gt) = Word64Map a -> Maybe a -> Word64Map a -> SplitLookup a
forall a. Word64Map a -> Maybe a -> Word64Map a -> SplitLookup a
SplitLookup (Word64Map a -> Word64Map a
f Word64Map a
lt) Maybe a
fnd Word64Map a
gt
{-# INLINE mapLT #-}
mapGT :: (Word64Map a -> Word64Map a) -> SplitLookup a -> SplitLookup a
mapGT :: forall a.
(Word64Map a -> Word64Map a) -> SplitLookup a -> SplitLookup a
mapGT Word64Map a -> Word64Map a
f (SplitLookup Word64Map a
lt Maybe a
fnd Word64Map a
gt) = Word64Map a -> Maybe a -> Word64Map a -> SplitLookup a
forall a. Word64Map a -> Maybe a -> Word64Map a -> SplitLookup a
SplitLookup Word64Map a
lt Maybe a
fnd (Word64Map a -> Word64Map a
f Word64Map a
gt)
{-# INLINE mapGT #-}
splitLookup :: Key -> Word64Map a -> (Word64Map a, Maybe a, Word64Map a)
splitLookup :: forall a.
Word64 -> Word64Map a -> (Word64Map a, Maybe a, Word64Map a)
splitLookup Word64
k Word64Map a
t =
case
case Word64Map a
t of
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 ->
if Word64
k Word64 -> Word64 -> Bool
forall a. Ord a => a -> a -> Bool
>= Word64
0
then (Word64Map a -> Word64Map a) -> SplitLookup a -> SplitLookup a
forall a.
(Word64Map a -> Word64Map a) -> SplitLookup a -> SplitLookup a
mapLT ((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) Word64Map a
r) (Word64 -> Word64Map a -> SplitLookup a
forall {a}. Word64 -> Word64Map a -> SplitLookup a
go Word64
k Word64Map a
l)
else (Word64Map a -> Word64Map a) -> SplitLookup a -> SplitLookup a
forall a.
(Word64Map a -> Word64Map a) -> SplitLookup a -> SplitLookup a
mapGT (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 -> Word64Map a -> SplitLookup a
forall {a}. Word64 -> Word64Map a -> SplitLookup a
go Word64
k Word64Map a
r)
Word64Map a
_ -> Word64 -> Word64Map a -> SplitLookup a
forall {a}. Word64 -> Word64Map a -> SplitLookup a
go Word64
k Word64Map a
t
of SplitLookup Word64Map a
lt Maybe a
fnd Word64Map a
gt -> (Word64Map a
lt, Maybe a
fnd, Word64Map a
gt)
where
go :: Word64 -> Word64Map a -> SplitLookup a
go 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 =
if Word64
k' Word64 -> Word64 -> Bool
forall a. Ord a => a -> a -> Bool
> Word64
p
then Word64Map a -> Maybe a -> Word64Map a -> SplitLookup a
forall a. Word64Map a -> Maybe a -> Word64Map a -> SplitLookup a
SplitLookup Word64Map a
t' Maybe a
forall a. Maybe a
Nothing Word64Map a
forall a. Word64Map a
Nil
else Word64Map a -> Maybe a -> Word64Map a -> SplitLookup a
forall a. Word64Map a -> Maybe a -> Word64Map a -> SplitLookup a
SplitLookup Word64Map a
forall a. Word64Map a
Nil Maybe a
forall a. Maybe a
Nothing Word64Map a
t'
| Word64 -> Word64 -> Bool
zero Word64
k' Word64
m = (Word64Map a -> Word64Map a) -> SplitLookup a -> SplitLookup a
forall a.
(Word64Map a -> Word64Map a) -> SplitLookup a -> SplitLookup a
mapGT ((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) Word64Map a
r) (Word64 -> Word64Map a -> SplitLookup a
go Word64
k' Word64Map a
l)
| Bool
otherwise = (Word64Map a -> Word64Map a) -> SplitLookup a -> SplitLookup a
forall a.
(Word64Map a -> Word64Map a) -> SplitLookup a -> SplitLookup a
mapLT (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 -> Word64Map a -> SplitLookup a
go Word64
k' Word64Map a
r)
go Word64
k' t' :: Word64Map a
t'@(Tip Word64
ky a
y)
| Word64
k' Word64 -> Word64 -> Bool
forall a. Ord a => a -> a -> Bool
> Word64
ky = Word64Map a -> Maybe a -> Word64Map a -> SplitLookup a
forall a. Word64Map a -> Maybe a -> Word64Map a -> SplitLookup a
SplitLookup Word64Map a
t' Maybe a
forall a. Maybe a
Nothing Word64Map a
forall a. Word64Map a
Nil
| Word64
k' Word64 -> Word64 -> Bool
forall a. Ord a => a -> a -> Bool
< Word64
ky = Word64Map a -> Maybe a -> Word64Map a -> SplitLookup a
forall a. Word64Map a -> Maybe a -> Word64Map a -> SplitLookup a
SplitLookup Word64Map a
forall a. Word64Map a
Nil Maybe a
forall a. Maybe a
Nothing Word64Map a
t'
| Bool
otherwise = Word64Map a -> Maybe a -> Word64Map a -> SplitLookup a
forall a. Word64Map a -> Maybe a -> Word64Map a -> SplitLookup a
SplitLookup Word64Map a
forall a. Word64Map a
Nil (a -> Maybe a
forall a. a -> Maybe a
Just a
y) Word64Map a
forall a. Word64Map a
Nil
go Word64
_ Word64Map a
Nil = Word64Map a -> Maybe a -> Word64Map a -> SplitLookup a
forall a. Word64Map a -> Maybe a -> Word64Map a -> SplitLookup a
SplitLookup Word64Map a
forall a. Word64Map a
Nil Maybe a
forall a. Maybe a
Nothing Word64Map a
forall a. Word64Map a
Nil
foldr :: (a -> b -> b) -> b -> Word64Map a -> b
foldr :: forall a b. (a -> b -> b) -> b -> Word64Map a -> b
foldr a -> b -> b
f b
z = \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 -> b -> Word64Map a -> b
go (b -> Word64Map a -> b
go b
z Word64Map a
l) Word64Map a
r
| Bool
otherwise -> b -> Word64Map a -> b
go (b -> Word64Map a -> b
go b
z Word64Map a
r) Word64Map a
l
Word64Map a
_ -> b -> Word64Map a -> b
go b
z Word64Map a
t
where
go :: b -> Word64Map a -> b
go b
z' Word64Map a
Nil = b
z'
go b
z' (Tip Word64
_ a
x) = a -> b -> b
f a
x b
z'
go b
z' (Bin Word64
_ Word64
_ Word64Map a
l Word64Map a
r) = b -> Word64Map a -> b
go (b -> Word64Map a -> b
go b
z' Word64Map a
r) Word64Map a
l
{-# INLINE foldr #-}
foldr' :: (a -> b -> b) -> b -> Word64Map a -> b
foldr' :: forall a b. (a -> b -> b) -> b -> Word64Map a -> b
foldr' a -> b -> b
f b
z = \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 -> b -> Word64Map a -> b
go (b -> Word64Map a -> b
go b
z Word64Map a
l) Word64Map a
r
| Bool
otherwise -> b -> Word64Map a -> b
go (b -> Word64Map a -> b
go b
z Word64Map a
r) Word64Map a
l
Word64Map a
_ -> b -> Word64Map a -> b
go b
z Word64Map a
t
where
go :: b -> Word64Map a -> b
go !b
z' Word64Map a
Nil = b
z'
go b
z' (Tip Word64
_ a
x) = a -> b -> b
f a
x b
z'
go b
z' (Bin Word64
_ Word64
_ Word64Map a
l Word64Map a
r) = b -> Word64Map a -> b
go (b -> Word64Map a -> b
go b
z' Word64Map a
r) Word64Map a
l
{-# INLINE foldr' #-}
foldl :: (a -> b -> a) -> a -> Word64Map b -> a
foldl :: forall b a. (b -> a -> b) -> b -> Word64Map a -> b
foldl a -> b -> a
f a
z = \Word64Map b
t ->
case Word64Map b
t of
Bin Word64
_ Word64
m Word64Map b
l Word64Map b
r
| Word64
m Word64 -> Word64 -> Bool
forall a. Ord a => a -> a -> Bool
< Word64
0 -> a -> Word64Map b -> a
go (a -> Word64Map b -> a
go a
z Word64Map b
r) Word64Map b
l
| Bool
otherwise -> a -> Word64Map b -> a
go (a -> Word64Map b -> a
go a
z Word64Map b
l) Word64Map b
r
Word64Map b
_ -> a -> Word64Map b -> a
go a
z Word64Map b
t
where
go :: a -> Word64Map b -> a
go a
z' Word64Map b
Nil = a
z'
go a
z' (Tip Word64
_ b
x) = a -> b -> a
f a
z' b
x
go a
z' (Bin Word64
_ Word64
_ Word64Map b
l Word64Map b
r) = a -> Word64Map b -> a
go (a -> Word64Map b -> a
go a
z' Word64Map b
l) Word64Map b
r
{-# INLINE foldl #-}
foldl' :: (a -> b -> a) -> a -> Word64Map b -> a
foldl' :: forall b a. (b -> a -> b) -> b -> Word64Map a -> b
foldl' a -> b -> a
f a
z = \Word64Map b
t ->
case Word64Map b
t of
Bin Word64
_ Word64
m Word64Map b
l Word64Map b
r
| Word64
m Word64 -> Word64 -> Bool
forall a. Ord a => a -> a -> Bool
< Word64
0 -> a -> Word64Map b -> a
go (a -> Word64Map b -> a
go a
z Word64Map b
r) Word64Map b
l
| Bool
otherwise -> a -> Word64Map b -> a
go (a -> Word64Map b -> a
go a
z Word64Map b
l) Word64Map b
r
Word64Map b
_ -> a -> Word64Map b -> a
go a
z Word64Map b
t
where
go :: a -> Word64Map b -> a
go !a
z' Word64Map b
Nil = a
z'
go a
z' (Tip Word64
_ b
x) = a -> b -> a
f a
z' b
x
go a
z' (Bin Word64
_ Word64
_ Word64Map b
l Word64Map b
r) = a -> Word64Map b -> a
go (a -> Word64Map b -> a
go a
z' Word64Map b
l) Word64Map b
r
{-# INLINE foldl' #-}
foldrWithKey :: (Key -> a -> b -> b) -> b -> Word64Map a -> b
foldrWithKey :: forall a b. (Word64 -> a -> b -> b) -> b -> Word64Map a -> b
foldrWithKey Word64 -> a -> b -> b
f b
z = \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 -> b -> Word64Map a -> b
go (b -> Word64Map a -> b
go b
z Word64Map a
l) Word64Map a
r
| Bool
otherwise -> b -> Word64Map a -> b
go (b -> Word64Map a -> b
go b
z Word64Map a
r) Word64Map a
l
Word64Map a
_ -> b -> Word64Map a -> b
go b
z Word64Map a
t
where
go :: b -> Word64Map a -> b
go b
z' Word64Map a
Nil = b
z'
go b
z' (Tip Word64
kx a
x) = Word64 -> a -> b -> b
f Word64
kx a
x b
z'
go b
z' (Bin Word64
_ Word64
_ Word64Map a
l Word64Map a
r) = b -> Word64Map a -> b
go (b -> Word64Map a -> b
go b
z' Word64Map a
r) Word64Map a
l
{-# INLINE foldrWithKey #-}
foldrWithKey' :: (Key -> a -> b -> b) -> b -> Word64Map a -> b
foldrWithKey' :: forall a b. (Word64 -> a -> b -> b) -> b -> Word64Map a -> b
foldrWithKey' Word64 -> a -> b -> b
f b
z = \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 -> b -> Word64Map a -> b
go (b -> Word64Map a -> b
go b
z Word64Map a
l) Word64Map a
r
| Bool
otherwise -> b -> Word64Map a -> b
go (b -> Word64Map a -> b
go b
z Word64Map a
r) Word64Map a
l
Word64Map a
_ -> b -> Word64Map a -> b
go b
z Word64Map a
t
where
go :: b -> Word64Map a -> b
go !b
z' Word64Map a
Nil = b
z'
go b
z' (Tip Word64
kx a
x) = Word64 -> a -> b -> b
f Word64
kx a
x b
z'
go b
z' (Bin Word64
_ Word64
_ Word64Map a
l Word64Map a
r) = b -> Word64Map a -> b
go (b -> Word64Map a -> b
go b
z' Word64Map a
r) Word64Map a
l
{-# INLINE foldrWithKey' #-}
foldlWithKey :: (a -> Key -> b -> a) -> a -> Word64Map b -> a
foldlWithKey :: forall a b. (a -> Word64 -> b -> a) -> a -> Word64Map b -> a
foldlWithKey a -> Word64 -> b -> a
f a
z = \Word64Map b
t ->
case Word64Map b
t of
Bin Word64
_ Word64
m Word64Map b
l Word64Map b
r
| Word64
m Word64 -> Word64 -> Bool
forall a. Ord a => a -> a -> Bool
< Word64
0 -> a -> Word64Map b -> a
go (a -> Word64Map b -> a
go a
z Word64Map b
r) Word64Map b
l
| Bool
otherwise -> a -> Word64Map b -> a
go (a -> Word64Map b -> a
go a
z Word64Map b
l) Word64Map b
r
Word64Map b
_ -> a -> Word64Map b -> a
go a
z Word64Map b
t
where
go :: a -> Word64Map b -> a
go a
z' Word64Map b
Nil = a
z'
go a
z' (Tip Word64
kx b
x) = a -> Word64 -> b -> a
f a
z' Word64
kx b
x
go a
z' (Bin Word64
_ Word64
_ Word64Map b
l Word64Map b
r) = a -> Word64Map b -> a
go (a -> Word64Map b -> a
go a
z' Word64Map b
l) Word64Map b
r
{-# INLINE foldlWithKey #-}
foldlWithKey' :: (a -> Key -> b -> a) -> a -> Word64Map b -> a
foldlWithKey' :: forall a b. (a -> Word64 -> b -> a) -> a -> Word64Map b -> a
foldlWithKey' a -> Word64 -> b -> a
f a
z = \Word64Map b
t ->
case Word64Map b
t of
Bin Word64
_ Word64
m Word64Map b
l Word64Map b
r
| Word64
m Word64 -> Word64 -> Bool
forall a. Ord a => a -> a -> Bool
< Word64
0 -> a -> Word64Map b -> a
go (a -> Word64Map b -> a
go a
z Word64Map b
r) Word64Map b
l
| Bool
otherwise -> a -> Word64Map b -> a
go (a -> Word64Map b -> a
go a
z Word64Map b
l) Word64Map b
r
Word64Map b
_ -> a -> Word64Map b -> a
go a
z Word64Map b
t
where
go :: a -> Word64Map b -> a
go !a
z' Word64Map b
Nil = a
z'
go a
z' (Tip Word64
kx b
x) = a -> Word64 -> b -> a
f a
z' Word64
kx b
x
go a
z' (Bin Word64
_ Word64
_ Word64Map b
l Word64Map b
r) = a -> Word64Map b -> a
go (a -> Word64Map b -> a
go a
z' Word64Map b
l) Word64Map b
r
{-# INLINE foldlWithKey' #-}
foldMapWithKey :: Monoid m => (Key -> a -> m) -> Word64Map a -> m
foldMapWithKey :: forall m a. Monoid m => (Word64 -> a -> m) -> Word64Map a -> m
foldMapWithKey Word64 -> a -> m
f = Word64Map a -> m
go
where
go :: Word64Map a -> m
go Word64Map a
Nil = m
forall a. Monoid a => a
mempty
go (Tip Word64
kx a
x) = Word64 -> a -> m
f Word64
kx a
x
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 foldMapWithKey #-}
elems :: Word64Map a -> [a]
elems :: forall a. Word64Map a -> [a]
elems = (a -> [a] -> [a]) -> [a] -> Word64Map a -> [a]
forall a b. (a -> b -> b) -> b -> Word64Map a -> b
foldr (:) []
keys :: Word64Map a -> [Key]
keys :: forall a. Word64Map a -> [Word64]
keys = (Word64 -> a -> [Word64] -> [Word64])
-> [Word64] -> Word64Map a -> [Word64]
forall a b. (Word64 -> a -> b -> b) -> b -> Word64Map a -> b
foldrWithKey (\Word64
k a
_ [Word64]
ks -> Word64
k Word64 -> [Word64] -> [Word64]
forall a. a -> [a] -> [a]
: [Word64]
ks) []
assocs :: Word64Map a -> [(Key,a)]
assocs :: forall a. Word64Map a -> [(Word64, a)]
assocs = Word64Map a -> [(Word64, a)]
forall a. Word64Map a -> [(Word64, a)]
toAscList
keysSet :: Word64Map a -> Word64Set.Word64Set
keysSet :: forall a. Word64Map a -> Word64Set
keysSet Word64Map a
Nil = Word64Set
Word64Set.Nil
keysSet (Tip Word64
kx a
_) = Word64 -> Word64Set
Word64Set.singleton Word64
kx
keysSet (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 = Word64 -> Word64 -> Word64Set -> Word64Set -> Word64Set
Word64Set.Bin Word64
p Word64
m (Word64Map a -> Word64Set
forall a. Word64Map a -> Word64Set
keysSet Word64Map a
l) (Word64Map a -> Word64Set
forall a. Word64Map a -> Word64Set
keysSet Word64Map a
r)
| Bool
otherwise = Word64 -> Word64 -> Word64Set
Word64Set.Tip (Word64
p Word64 -> Word64 -> Word64
forall a. Bits a => a -> a -> a
.&. Word64
Word64Set.prefixBitMask) (Word64 -> Word64Map a -> Word64
forall {a}. Word64 -> Word64Map a -> Word64
computeBm (Word64 -> Word64Map a -> Word64
forall {a}. Word64 -> Word64Map a -> Word64
computeBm Word64
0 Word64Map a
l) Word64Map a
r)
where computeBm :: Word64 -> Word64Map a -> Word64
computeBm !Word64
acc (Bin Word64
_ Word64
_ Word64Map a
l' Word64Map a
r') = Word64 -> Word64Map a -> Word64
computeBm (Word64 -> Word64Map a -> Word64
computeBm Word64
acc Word64Map a
l') Word64Map a
r'
computeBm Word64
acc (Tip Word64
kx a
_) = Word64
acc Word64 -> Word64 -> Word64
forall a. Bits a => a -> a -> a
.|. Word64 -> Word64
Word64Set.bitmapOf Word64
kx
computeBm Word64
_ Word64Map a
Nil = [Char] -> Word64
forall a. HasCallStack => [Char] -> a
error [Char]
"Data.Word64Set.keysSet: Nil"
fromSet :: (Key -> a) -> Word64Set.Word64Set -> Word64Map a
fromSet :: forall a. (Word64 -> a) -> Word64Set -> Word64Map a
fromSet Word64 -> a
_ Word64Set
Word64Set.Nil = Word64Map a
forall a. Word64Map a
Nil
fromSet Word64 -> a
f (Word64Set.Bin Word64
p Word64
m Word64Set
l Word64Set
r) = 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) -> Word64Set -> Word64Map a
forall a. (Word64 -> a) -> Word64Set -> Word64Map a
fromSet Word64 -> a
f Word64Set
l) ((Word64 -> a) -> Word64Set -> Word64Map a
forall a. (Word64 -> a) -> Word64Set -> Word64Map a
fromSet Word64 -> a
f Word64Set
r)
fromSet Word64 -> a
f (Word64Set.Tip Word64
kx Word64
bm) = (Word64 -> a) -> Word64 -> Word64 -> Word64 -> Word64Map a
forall {a}.
(Word64 -> a) -> Word64 -> Word64 -> Word64 -> Word64Map a
buildTree Word64 -> a
f Word64
kx Word64
bm (Word64
Word64Set.suffixBitMask Word64 -> Word64 -> Word64
forall a. Num a => a -> a -> a
+ Word64
1)
where
buildTree :: (Word64 -> a) -> Word64 -> Word64 -> Word64 -> Word64Map a
buildTree Word64 -> a
g !Word64
prefix !Word64
bmask Word64
bits = case Word64
bits of
Word64
0 -> Word64 -> a -> Word64Map a
forall a. Word64 -> a -> Word64Map a
Tip Word64
prefix (Word64 -> a
g Word64
prefix)
Word64
_ -> case Word64 -> Word64
intFromNat ((Word64 -> Word64
natFromInt Word64
bits) Word64 -> Int -> Word64
`shiftRL` Int
1) of
Word64
bits2
| Word64
bmask Word64 -> Word64 -> Word64
forall a. Bits a => a -> a -> a
.&. ((Word64
1 Word64 -> Int -> Word64
`shiftLL` Word64 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word64
bits2) Word64 -> Word64 -> Word64
forall a. Num a => a -> a -> a
- Word64
1) Word64 -> Word64 -> Bool
forall a. Eq a => a -> a -> Bool
== Word64
0 ->
(Word64 -> a) -> Word64 -> Word64 -> Word64 -> Word64Map a
buildTree Word64 -> a
g (Word64
prefix Word64 -> Word64 -> Word64
forall a. Num a => a -> a -> a
+ Word64
bits2) (Word64
bmask Word64 -> Int -> Word64
`shiftRL` Word64 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word64
bits2) Word64
bits2
| (Word64
bmask Word64 -> Int -> Word64
`shiftRL` Word64 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word64
bits2) Word64 -> Word64 -> Word64
forall a. Bits a => a -> a -> a
.&. ((Word64
1 Word64 -> Int -> Word64
`shiftLL` Word64 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word64
bits2) Word64 -> Word64 -> Word64
forall a. Num a => a -> a -> a
- Word64
1) Word64 -> Word64 -> Bool
forall a. Eq a => a -> a -> Bool
== Word64
0 ->
(Word64 -> a) -> Word64 -> Word64 -> Word64 -> Word64Map a
buildTree Word64 -> a
g Word64
prefix Word64
bmask Word64
bits2
| Bool
otherwise ->
Word64 -> Word64 -> Word64Map a -> Word64Map a -> Word64Map a
forall a.
Word64 -> Word64 -> Word64Map a -> Word64Map a -> Word64Map a
Bin Word64
prefix Word64
bits2
((Word64 -> a) -> Word64 -> Word64 -> Word64 -> Word64Map a
buildTree Word64 -> a
g Word64
prefix Word64
bmask Word64
bits2)
((Word64 -> a) -> Word64 -> Word64 -> Word64 -> Word64Map a
buildTree Word64 -> a
g (Word64
prefix Word64 -> Word64 -> Word64
forall a. Num a => a -> a -> a
+ Word64
bits2) (Word64
bmask Word64 -> Int -> Word64
`shiftRL` Word64 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word64
bits2) Word64
bits2)
instance GHCExts.IsList (Word64Map a) where
type Item (Word64Map a) = (Key,a)
fromList :: [Item (Word64Map a)] -> Word64Map a
fromList = [(Word64, a)] -> Word64Map a
[Item (Word64Map a)] -> Word64Map a
forall a. [(Word64, a)] -> Word64Map a
fromList
toList :: Word64Map a -> [Item (Word64Map a)]
toList = Word64Map a -> [(Word64, a)]
Word64Map a -> [Item (Word64Map a)]
forall a. Word64Map a -> [(Word64, a)]
toList
toList :: Word64Map a -> [(Key,a)]
toList :: forall a. Word64Map a -> [(Word64, a)]
toList = Word64Map a -> [(Word64, a)]
forall a. Word64Map a -> [(Word64, a)]
toAscList
toAscList :: Word64Map a -> [(Key,a)]
toAscList :: forall a. Word64Map a -> [(Word64, a)]
toAscList = (Word64 -> a -> [(Word64, a)] -> [(Word64, a)])
-> [(Word64, a)] -> Word64Map a -> [(Word64, a)]
forall a b. (Word64 -> a -> b -> b) -> b -> Word64Map a -> b
foldrWithKey (\Word64
k a
x [(Word64, a)]
xs -> (Word64
k,a
x)(Word64, a) -> [(Word64, a)] -> [(Word64, a)]
forall a. a -> [a] -> [a]
:[(Word64, a)]
xs) []
toDescList :: Word64Map a -> [(Key,a)]
toDescList :: forall a. Word64Map a -> [(Word64, a)]
toDescList = ([(Word64, a)] -> Word64 -> a -> [(Word64, a)])
-> [(Word64, a)] -> Word64Map a -> [(Word64, a)]
forall a b. (a -> Word64 -> b -> a) -> a -> Word64Map b -> a
foldlWithKey (\[(Word64, a)]
xs Word64
k a
x -> (Word64
k,a
x)(Word64, a) -> [(Word64, a)] -> [(Word64, a)]
forall a. a -> [a] -> [a]
:[(Word64, a)]
xs) []
foldrFB :: (Key -> a -> b -> b) -> b -> Word64Map a -> b
foldrFB :: forall a b. (Word64 -> a -> b -> b) -> b -> Word64Map a -> b
foldrFB = (Word64 -> a -> b -> b) -> b -> Word64Map a -> b
forall a b. (Word64 -> a -> b -> b) -> b -> Word64Map a -> b
foldrWithKey
{-# INLINE[0] foldrFB #-}
foldlFB :: (a -> Key -> b -> a) -> a -> Word64Map b -> a
foldlFB :: forall a b. (a -> Word64 -> b -> a) -> a -> Word64Map b -> a
foldlFB = (a -> Word64 -> b -> a) -> a -> Word64Map b -> a
forall a b. (a -> Word64 -> b -> a) -> a -> Word64Map b -> a
foldlWithKey
{-# INLINE[0] foldlFB #-}
{-# INLINE assocs #-}
{-# INLINE toList #-}
{-# NOINLINE[0] elems #-}
{-# NOINLINE[0] keys #-}
{-# NOINLINE[0] toAscList #-}
{-# NOINLINE[0] toDescList #-}
{-# RULES "Word64Map.elems" [~1] forall m . elems m = build (\c n -> foldrFB (\_ x xs -> c x xs) n m) #-}
{-# RULES "Word64Map.elemsBack" [1] foldrFB (\_ x xs -> x : xs) [] = elems #-}
{-# RULES "Word64Map.keys" [~1] forall m . keys m = build (\c n -> foldrFB (\k _ xs -> c k xs) n m) #-}
{-# RULES "Word64Map.keysBack" [1] foldrFB (\k _ xs -> k : xs) [] = keys #-}
{-# RULES "Word64Map.toAscList" [~1] forall m . toAscList m = build (\c n -> foldrFB (\k x xs -> c (k,x) xs) n m) #-}
{-# RULES "Word64Map.toAscListBack" [1] foldrFB (\k x xs -> (k, x) : xs) [] = toAscList #-}
{-# RULES "Word64Map.toDescList" [~1] forall m . toDescList m = build (\c n -> foldlFB (\xs k x -> c (k,x) xs) n m) #-}
{-# RULES "Word64Map.toDescListBack" [1] foldlFB (\xs k x -> (k, x) : xs) [] = toDescList #-}
fromList :: [(Key,a)] -> Word64Map a
fromList :: forall a. [(Word64, a)] -> Word64Map a
fromList [(Word64, a)]
xs
= (Word64Map a -> (Word64, a) -> Word64Map a)
-> Word64Map a -> [(Word64, a)] -> Word64Map a
forall b a. (b -> a -> b) -> b -> [a] -> b
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
Foldable.foldl' Word64Map a -> (Word64, a) -> Word64Map a
forall {a}. Word64Map a -> (Word64, a) -> Word64Map a
ins Word64Map a
forall a. Word64Map a
empty [(Word64, a)]
xs
where
ins :: Word64Map a -> (Word64, a) -> Word64Map a
ins Word64Map a
t (Word64
k,a
x) = Word64 -> a -> Word64Map a -> Word64Map a
forall a. Word64 -> a -> Word64Map a -> Word64Map a
insert Word64
k a
x Word64Map a
t
fromListWith :: (a -> a -> a) -> [(Key,a)] -> Word64Map a
fromListWith :: forall a. (a -> a -> a) -> [(Word64, a)] -> Word64Map a
fromListWith a -> a -> a
f [(Word64, a)]
xs
= (Word64 -> a -> a -> a) -> [(Word64, a)] -> Word64Map a
forall a. (Word64 -> a -> a -> a) -> [(Word64, a)] -> Word64Map a
fromListWithKey (\Word64
_ a
x a
y -> a -> a -> a
f a
x a
y) [(Word64, a)]
xs
fromListWithKey :: (Key -> a -> a -> a) -> [(Key,a)] -> Word64Map a
fromListWithKey :: forall a. (Word64 -> a -> a -> a) -> [(Word64, a)] -> Word64Map a
fromListWithKey Word64 -> a -> a -> a
f [(Word64, a)]
xs
= (Word64Map a -> (Word64, a) -> Word64Map a)
-> Word64Map a -> [(Word64, a)] -> Word64Map a
forall b a. (b -> a -> b) -> b -> [a] -> b
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
Foldable.foldl' Word64Map a -> (Word64, a) -> Word64Map a
ins Word64Map a
forall a. Word64Map a
empty [(Word64, a)]
xs
where
ins :: Word64Map a -> (Word64, a) -> Word64Map a
ins Word64Map a
t (Word64
k,a
x) = (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
t
fromAscList :: [(Key,a)] -> Word64Map a
fromAscList :: forall a. [(Word64, a)] -> Word64Map a
fromAscList = Distinct -> (Word64 -> a -> a -> a) -> [(Word64, a)] -> Word64Map a
forall a.
Distinct -> (Word64 -> a -> a -> a) -> [(Word64, a)] -> Word64Map a
fromMonoListWithKey Distinct
Nondistinct (\Word64
_ a
x a
_ -> a
x)
{-# NOINLINE fromAscList #-}
fromAscListWith :: (a -> a -> a) -> [(Key,a)] -> Word64Map a
fromAscListWith :: forall a. (a -> a -> a) -> [(Word64, a)] -> Word64Map a
fromAscListWith a -> a -> a
f = Distinct -> (Word64 -> a -> a -> a) -> [(Word64, a)] -> Word64Map a
forall a.
Distinct -> (Word64 -> a -> a -> a) -> [(Word64, a)] -> Word64Map a
fromMonoListWithKey Distinct
Nondistinct (\Word64
_ a
x a
y -> a -> a -> a
f a
x a
y)
{-# NOINLINE fromAscListWith #-}
fromAscListWithKey :: (Key -> a -> a -> a) -> [(Key,a)] -> Word64Map a
fromAscListWithKey :: forall a. (Word64 -> a -> a -> a) -> [(Word64, a)] -> Word64Map a
fromAscListWithKey Word64 -> a -> a -> a
f = Distinct -> (Word64 -> a -> a -> a) -> [(Word64, a)] -> Word64Map a
forall a.
Distinct -> (Word64 -> a -> a -> a) -> [(Word64, a)] -> Word64Map a
fromMonoListWithKey Distinct
Nondistinct Word64 -> a -> a -> a
f
{-# NOINLINE fromAscListWithKey #-}
fromDistinctAscList :: [(Key,a)] -> Word64Map a
fromDistinctAscList :: forall a. [(Word64, a)] -> Word64Map a
fromDistinctAscList = Distinct -> (Word64 -> a -> a -> a) -> [(Word64, a)] -> Word64Map a
forall a.
Distinct -> (Word64 -> a -> a -> a) -> [(Word64, a)] -> Word64Map a
fromMonoListWithKey Distinct
Distinct (\Word64
_ a
x a
_ -> a
x)
{-# NOINLINE fromDistinctAscList #-}
fromMonoListWithKey :: Distinct -> (Key -> a -> a -> a) -> [(Key,a)] -> Word64Map a
fromMonoListWithKey :: forall a.
Distinct -> (Word64 -> a -> a -> a) -> [(Word64, a)] -> Word64Map a
fromMonoListWithKey Distinct
distinct Word64 -> a -> a -> a
f = [(Word64, a)] -> Word64Map a
go
where
go :: [(Word64, a)] -> Word64Map a
go [] = Word64Map a
forall a. Word64Map a
Nil
go ((Word64
kx,a
vx) : [(Word64, a)]
zs1) = Word64 -> a -> [(Word64, a)] -> Word64Map a
addAll' Word64
kx a
vx [(Word64, a)]
zs1
addAll' :: Word64 -> a -> [(Word64, a)] -> Word64Map a
addAll' !Word64
kx a
vx []
= Word64 -> a -> Word64Map a
forall a. Word64 -> a -> Word64Map a
Tip Word64
kx a
vx
addAll' !Word64
kx a
vx ((Word64
ky,a
vy) : [(Word64, a)]
zs)
| Distinct
Nondistinct <- Distinct
distinct, Word64
kx Word64 -> Word64 -> Bool
forall a. Eq a => a -> a -> Bool
== Word64
ky
= let v :: a
v = Word64 -> a -> a -> a
f Word64
kx a
vy a
vx in Word64 -> a -> [(Word64, a)] -> Word64Map a
addAll' Word64
ky a
v [(Word64, a)]
zs
| Word64
m <- Word64 -> Word64 -> Word64
branchMask Word64
kx Word64
ky
, Inserted Word64Map a
ty [(Word64, a)]
zs' <- Word64 -> Word64 -> a -> [(Word64, a)] -> Inserted a
addMany' Word64
m Word64
ky a
vy [(Word64, a)]
zs
= Word64 -> Word64Map a -> [(Word64, a)] -> Word64Map a
addAll Word64
kx (Word64 -> Word64 -> Word64Map a -> Word64Map a -> Word64Map a
forall a.
Word64 -> Word64 -> Word64Map a -> Word64Map a -> Word64Map a
linkWithMask Word64
m Word64
ky Word64Map a
ty (Word64 -> a -> Word64Map a
forall a. Word64 -> a -> Word64Map a
Tip Word64
kx a
vx)) [(Word64, a)]
zs'
addAll :: Word64 -> Word64Map a -> [(Word64, a)] -> Word64Map a
addAll !Word64
_kx !Word64Map a
tx []
= Word64Map a
tx
addAll !Word64
kx !Word64Map a
tx ((Word64
ky,a
vy) : [(Word64, a)]
zs)
| Word64
m <- Word64 -> Word64 -> Word64
branchMask Word64
kx Word64
ky
, Inserted Word64Map a
ty [(Word64, a)]
zs' <- Word64 -> Word64 -> a -> [(Word64, a)] -> Inserted a
addMany' Word64
m Word64
ky a
vy [(Word64, a)]
zs
= Word64 -> Word64Map a -> [(Word64, a)] -> Word64Map a
addAll Word64
kx (Word64 -> Word64 -> Word64Map a -> Word64Map a -> Word64Map a
forall a.
Word64 -> Word64 -> Word64Map a -> Word64Map a -> Word64Map a
linkWithMask Word64
m Word64
ky Word64Map a
ty Word64Map a
tx) [(Word64, a)]
zs'
addMany' :: Word64 -> Word64 -> a -> [(Word64, a)] -> Inserted a
addMany' !Word64
_m !Word64
kx a
vx []
= Word64Map a -> [(Word64, a)] -> Inserted a
forall a. Word64Map a -> [(Word64, a)] -> Inserted a
Inserted (Word64 -> a -> Word64Map a
forall a. Word64 -> a -> Word64Map a
Tip Word64
kx a
vx) []
addMany' !Word64
m !Word64
kx a
vx zs0 :: [(Word64, a)]
zs0@((Word64
ky,a
vy) : [(Word64, a)]
zs)
| Distinct
Nondistinct <- Distinct
distinct, Word64
kx Word64 -> Word64 -> Bool
forall a. Eq a => a -> a -> Bool
== Word64
ky
= let v :: a
v = Word64 -> a -> a -> a
f Word64
kx a
vy a
vx in Word64 -> Word64 -> a -> [(Word64, a)] -> Inserted a
addMany' Word64
m Word64
ky a
v [(Word64, a)]
zs
| Word64 -> Word64 -> Word64
mask Word64
kx Word64
m Word64 -> Word64 -> Bool
forall a. Eq a => a -> a -> Bool
/= Word64 -> Word64 -> Word64
mask Word64
ky Word64
m
= Word64Map a -> [(Word64, a)] -> Inserted a
forall a. Word64Map a -> [(Word64, a)] -> Inserted a
Inserted (Word64 -> a -> Word64Map a
forall a. Word64 -> a -> Word64Map a
Tip Word64
kx a
vx) [(Word64, a)]
zs0
| Word64
mxy <- Word64 -> Word64 -> Word64
branchMask Word64
kx Word64
ky
, Inserted Word64Map a
ty [(Word64, a)]
zs' <- Word64 -> Word64 -> a -> [(Word64, a)] -> Inserted a
addMany' Word64
mxy Word64
ky a
vy [(Word64, a)]
zs
= Word64 -> Word64 -> Word64Map a -> [(Word64, a)] -> Inserted a
addMany Word64
m Word64
kx (Word64 -> Word64 -> Word64Map a -> Word64Map a -> Word64Map a
forall a.
Word64 -> Word64 -> Word64Map a -> Word64Map a -> Word64Map a
linkWithMask Word64
mxy Word64
ky Word64Map a
ty (Word64 -> a -> Word64Map a
forall a. Word64 -> a -> Word64Map a
Tip Word64
kx a
vx)) [(Word64, a)]
zs'
addMany :: Word64 -> Word64 -> Word64Map a -> [(Word64, a)] -> Inserted a
addMany !Word64
_m !Word64
_kx Word64Map a
tx []
= Word64Map a -> [(Word64, a)] -> Inserted a
forall a. Word64Map a -> [(Word64, a)] -> Inserted a
Inserted Word64Map a
tx []
addMany !Word64
m !Word64
kx Word64Map a
tx zs0 :: [(Word64, a)]
zs0@((Word64
ky,a
vy) : [(Word64, a)]
zs)
| Word64 -> Word64 -> Word64
mask Word64
kx Word64
m Word64 -> Word64 -> Bool
forall a. Eq a => a -> a -> Bool
/= Word64 -> Word64 -> Word64
mask Word64
ky Word64
m
= Word64Map a -> [(Word64, a)] -> Inserted a
forall a. Word64Map a -> [(Word64, a)] -> Inserted a
Inserted Word64Map a
tx [(Word64, a)]
zs0
| Word64
mxy <- Word64 -> Word64 -> Word64
branchMask Word64
kx Word64
ky
, Inserted Word64Map a
ty [(Word64, a)]
zs' <- Word64 -> Word64 -> a -> [(Word64, a)] -> Inserted a
addMany' Word64
mxy Word64
ky a
vy [(Word64, a)]
zs
= Word64 -> Word64 -> Word64Map a -> [(Word64, a)] -> Inserted a
addMany Word64
m Word64
kx (Word64 -> Word64 -> Word64Map a -> Word64Map a -> Word64Map a
forall a.
Word64 -> Word64 -> Word64Map a -> Word64Map a -> Word64Map a
linkWithMask Word64
mxy Word64
ky Word64Map a
ty Word64Map a
tx) [(Word64, a)]
zs'
{-# INLINE fromMonoListWithKey #-}
data Inserted a = Inserted !(Word64Map a) ![(Key,a)]
data Distinct = Distinct | Nondistinct
instance Eq a => Eq (Word64Map a) where
Word64Map a
t1 == :: Word64Map a -> Word64Map a -> Bool
== Word64Map a
t2 = Word64Map a -> Word64Map a -> Bool
forall a. Eq a => Word64Map a -> Word64Map a -> Bool
equal Word64Map a
t1 Word64Map a
t2
Word64Map a
t1 /= :: Word64Map a -> Word64Map a -> Bool
/= Word64Map a
t2 = Word64Map a -> Word64Map a -> Bool
forall a. Eq a => Word64Map a -> Word64Map a -> Bool
nequal Word64Map a
t1 Word64Map a
t2
equal :: Eq a => Word64Map a -> Word64Map a -> Bool
equal :: forall a. Eq a => Word64Map a -> Word64Map a -> Bool
equal (Bin Word64
p1 Word64
m1 Word64Map a
l1 Word64Map a
r1) (Bin Word64
p2 Word64
m2 Word64Map a
l2 Word64Map a
r2)
= (Word64
m1 Word64 -> Word64 -> Bool
forall a. Eq a => a -> a -> Bool
== Word64
m2) Bool -> Bool -> Bool
&& (Word64
p1 Word64 -> Word64 -> Bool
forall a. Eq a => a -> a -> Bool
== Word64
p2) Bool -> Bool -> Bool
&& (Word64Map a -> Word64Map a -> Bool
forall a. Eq a => Word64Map a -> Word64Map a -> Bool
equal Word64Map a
l1 Word64Map a
l2) Bool -> Bool -> Bool
&& (Word64Map a -> Word64Map a -> Bool
forall a. Eq a => Word64Map a -> Word64Map a -> Bool
equal Word64Map a
r1 Word64Map a
r2)
equal (Tip Word64
kx a
x) (Tip Word64
ky a
y)
= (Word64
kx Word64 -> Word64 -> Bool
forall a. Eq a => a -> a -> Bool
== Word64
ky) Bool -> Bool -> Bool
&& (a
xa -> a -> Bool
forall a. Eq a => a -> a -> Bool
==a
y)
equal Word64Map a
Nil Word64Map a
Nil = Bool
True
equal Word64Map a
_ Word64Map a
_ = Bool
False
nequal :: Eq a => Word64Map a -> Word64Map a -> Bool
nequal :: forall a. Eq a => Word64Map a -> Word64Map a -> Bool
nequal (Bin Word64
p1 Word64
m1 Word64Map a
l1 Word64Map a
r1) (Bin Word64
p2 Word64
m2 Word64Map a
l2 Word64Map a
r2)
= (Word64
m1 Word64 -> Word64 -> Bool
forall a. Eq a => a -> a -> Bool
/= Word64
m2) Bool -> Bool -> Bool
|| (Word64
p1 Word64 -> Word64 -> Bool
forall a. Eq a => a -> a -> Bool
/= Word64
p2) Bool -> Bool -> Bool
|| (Word64Map a -> Word64Map a -> Bool
forall a. Eq a => Word64Map a -> Word64Map a -> Bool
nequal Word64Map a
l1 Word64Map a
l2) Bool -> Bool -> Bool
|| (Word64Map a -> Word64Map a -> Bool
forall a. Eq a => Word64Map a -> Word64Map a -> Bool
nequal Word64Map a
r1 Word64Map a
r2)
nequal (Tip Word64
kx a
x) (Tip Word64
ky a
y)
= (Word64
kx Word64 -> Word64 -> Bool
forall a. Eq a => a -> a -> Bool
/= Word64
ky) Bool -> Bool -> Bool
|| (a
xa -> a -> Bool
forall a. Eq a => a -> a -> Bool
/=a
y)
nequal Word64Map a
Nil Word64Map a
Nil = Bool
False
nequal Word64Map a
_ Word64Map a
_ = Bool
True
instance Eq1 Word64Map where
liftEq :: forall a b. (a -> b -> Bool) -> Word64Map a -> Word64Map b -> Bool
liftEq a -> b -> Bool
eq (Bin Word64
p1 Word64
m1 Word64Map a
l1 Word64Map a
r1) (Bin Word64
p2 Word64
m2 Word64Map b
l2 Word64Map b
r2)
= (Word64
m1 Word64 -> Word64 -> Bool
forall a. Eq a => a -> a -> Bool
== Word64
m2) Bool -> Bool -> Bool
&& (Word64
p1 Word64 -> Word64 -> Bool
forall a. Eq a => a -> a -> Bool
== Word64
p2) Bool -> Bool -> Bool
&& ((a -> b -> Bool) -> Word64Map a -> Word64Map b -> Bool
forall a b. (a -> b -> Bool) -> Word64Map a -> Word64Map b -> Bool
forall (f :: * -> *) a b.
Eq1 f =>
(a -> b -> Bool) -> f a -> f b -> Bool
liftEq a -> b -> Bool
eq Word64Map a
l1 Word64Map b
l2) Bool -> Bool -> Bool
&& ((a -> b -> Bool) -> Word64Map a -> Word64Map b -> Bool
forall a b. (a -> b -> Bool) -> Word64Map a -> Word64Map b -> Bool
forall (f :: * -> *) a b.
Eq1 f =>
(a -> b -> Bool) -> f a -> f b -> Bool
liftEq a -> b -> Bool
eq Word64Map a
r1 Word64Map b
r2)
liftEq a -> b -> Bool
eq (Tip Word64
kx a
x) (Tip Word64
ky b
y)
= (Word64
kx Word64 -> Word64 -> Bool
forall a. Eq a => a -> a -> Bool
== Word64
ky) Bool -> Bool -> Bool
&& (a -> b -> Bool
eq a
x b
y)
liftEq a -> b -> Bool
_eq Word64Map a
Nil Word64Map b
Nil = Bool
True
liftEq a -> b -> Bool
_eq Word64Map a
_ Word64Map b
_ = Bool
False
instance Ord a => Ord (Word64Map a) where
compare :: Word64Map a -> Word64Map a -> Ordering
compare Word64Map a
m1 Word64Map a
m2 = [(Word64, a)] -> [(Word64, a)] -> Ordering
forall a. Ord a => a -> a -> Ordering
compare (Word64Map a -> [(Word64, a)]
forall a. Word64Map a -> [(Word64, a)]
toList Word64Map a
m1) (Word64Map a -> [(Word64, a)]
forall a. Word64Map a -> [(Word64, a)]
toList Word64Map a
m2)
instance Ord1 Word64Map where
liftCompare :: forall a b.
(a -> b -> Ordering) -> Word64Map a -> Word64Map b -> Ordering
liftCompare a -> b -> Ordering
cmp Word64Map a
m Word64Map b
n =
((Word64, a) -> (Word64, b) -> Ordering)
-> [(Word64, a)] -> [(Word64, b)] -> Ordering
forall a b. (a -> b -> Ordering) -> [a] -> [b] -> Ordering
forall (f :: * -> *) a b.
Ord1 f =>
(a -> b -> Ordering) -> f a -> f b -> Ordering
liftCompare ((a -> b -> Ordering) -> (Word64, a) -> (Word64, b) -> Ordering
forall a b.
(a -> b -> Ordering) -> (Word64, a) -> (Word64, b) -> Ordering
forall (f :: * -> *) a b.
Ord1 f =>
(a -> b -> Ordering) -> f a -> f b -> Ordering
liftCompare a -> b -> Ordering
cmp) (Word64Map a -> [(Word64, a)]
forall a. Word64Map a -> [(Word64, a)]
toList Word64Map a
m) (Word64Map b -> [(Word64, b)]
forall a. Word64Map a -> [(Word64, a)]
toList Word64Map b
n)
instance Functor Word64Map where
fmap :: forall a b. (a -> b) -> Word64Map a -> Word64Map b
fmap = (a -> b) -> Word64Map a -> Word64Map b
forall a b. (a -> b) -> Word64Map a -> Word64Map b
map
a
a <$ :: forall a b. a -> Word64Map b -> Word64Map a
<$ Bin Word64
p Word64
m Word64Map b
l Word64Map b
r = Word64 -> Word64 -> Word64Map a -> Word64Map a -> Word64Map a
forall a.
Word64 -> Word64 -> Word64Map a -> Word64Map a -> Word64Map a
Bin Word64
p Word64
m (a
a a -> Word64Map b -> Word64Map a
forall a b. a -> Word64Map b -> Word64Map a
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ Word64Map b
l) (a
a a -> Word64Map b -> Word64Map a
forall a b. a -> Word64Map b -> Word64Map a
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ Word64Map b
r)
a
a <$ Tip Word64
k b
_ = Word64 -> a -> Word64Map a
forall a. Word64 -> a -> Word64Map a
Tip Word64
k a
a
a
_ <$ Word64Map b
Nil = Word64Map a
forall a. Word64Map a
Nil
instance Show a => Show (Word64Map a) where
showsPrec :: Int -> Word64Map a -> [Char] -> [Char]
showsPrec Int
d Word64Map a
m = Bool -> ([Char] -> [Char]) -> [Char] -> [Char]
showParen (Int
d Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
10) (([Char] -> [Char]) -> [Char] -> [Char])
-> ([Char] -> [Char]) -> [Char] -> [Char]
forall a b. (a -> b) -> a -> b
$
[Char] -> [Char] -> [Char]
showString [Char]
"fromList " ([Char] -> [Char]) -> ([Char] -> [Char]) -> [Char] -> [Char]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [(Word64, a)] -> [Char] -> [Char]
forall a. Show a => a -> [Char] -> [Char]
shows (Word64Map a -> [(Word64, a)]
forall a. Word64Map a -> [(Word64, a)]
toList Word64Map a
m)
instance Show1 Word64Map where
liftShowsPrec :: forall a.
(Int -> a -> [Char] -> [Char])
-> ([a] -> [Char] -> [Char])
-> Int
-> Word64Map a
-> [Char]
-> [Char]
liftShowsPrec Int -> a -> [Char] -> [Char]
sp [a] -> [Char] -> [Char]
sl Int
d Word64Map a
m =
(Int -> [(Word64, a)] -> [Char] -> [Char])
-> [Char] -> Int -> [(Word64, a)] -> [Char] -> [Char]
forall a.
(Int -> a -> [Char] -> [Char])
-> [Char] -> Int -> a -> [Char] -> [Char]
showsUnaryWith ((Int -> (Word64, a) -> [Char] -> [Char])
-> ([(Word64, a)] -> [Char] -> [Char])
-> Int
-> [(Word64, a)]
-> [Char]
-> [Char]
forall a.
(Int -> a -> [Char] -> [Char])
-> ([a] -> [Char] -> [Char]) -> Int -> [a] -> [Char] -> [Char]
forall (f :: * -> *) a.
Show1 f =>
(Int -> a -> [Char] -> [Char])
-> ([a] -> [Char] -> [Char]) -> Int -> f a -> [Char] -> [Char]
liftShowsPrec Int -> (Word64, a) -> [Char] -> [Char]
sp' [(Word64, a)] -> [Char] -> [Char]
sl') [Char]
"fromList" Int
d (Word64Map a -> [(Word64, a)]
forall a. Word64Map a -> [(Word64, a)]
toList Word64Map a
m)
where
sp' :: Int -> (Word64, a) -> [Char] -> [Char]
sp' = (Int -> a -> [Char] -> [Char])
-> ([a] -> [Char] -> [Char])
-> Int
-> (Word64, a)
-> [Char]
-> [Char]
forall a.
(Int -> a -> [Char] -> [Char])
-> ([a] -> [Char] -> [Char])
-> Int
-> (Word64, a)
-> [Char]
-> [Char]
forall (f :: * -> *) a.
Show1 f =>
(Int -> a -> [Char] -> [Char])
-> ([a] -> [Char] -> [Char]) -> Int -> f a -> [Char] -> [Char]
liftShowsPrec Int -> a -> [Char] -> [Char]
sp [a] -> [Char] -> [Char]
sl
sl' :: [(Word64, a)] -> [Char] -> [Char]
sl' = (Int -> a -> [Char] -> [Char])
-> ([a] -> [Char] -> [Char]) -> [(Word64, a)] -> [Char] -> [Char]
forall a.
(Int -> a -> [Char] -> [Char])
-> ([a] -> [Char] -> [Char]) -> [(Word64, a)] -> [Char] -> [Char]
forall (f :: * -> *) a.
Show1 f =>
(Int -> a -> [Char] -> [Char])
-> ([a] -> [Char] -> [Char]) -> [f a] -> [Char] -> [Char]
liftShowList Int -> a -> [Char] -> [Char]
sp [a] -> [Char] -> [Char]
sl
instance (Read e) => Read (Word64Map e) where
readPrec :: ReadPrec (Word64Map e)
readPrec = ReadPrec (Word64Map e) -> ReadPrec (Word64Map e)
forall a. ReadPrec a -> ReadPrec a
parens (ReadPrec (Word64Map e) -> ReadPrec (Word64Map e))
-> ReadPrec (Word64Map e) -> ReadPrec (Word64Map e)
forall a b. (a -> b) -> a -> b
$ Int -> ReadPrec (Word64Map e) -> ReadPrec (Word64Map e)
forall a. Int -> ReadPrec a -> ReadPrec a
prec Int
10 (ReadPrec (Word64Map e) -> ReadPrec (Word64Map e))
-> ReadPrec (Word64Map e) -> ReadPrec (Word64Map e)
forall a b. (a -> b) -> a -> b
$ do
Ident "fromList" <- ReadPrec Lexeme
lexP
xs <- readPrec
return (fromList xs)
readListPrec :: ReadPrec [Word64Map e]
readListPrec = ReadPrec [Word64Map e]
forall a. Read a => ReadPrec [a]
readListPrecDefault
instance Read1 Word64Map where
liftReadsPrec :: forall a.
(Int -> ReadS a) -> ReadS [a] -> Int -> ReadS (Word64Map a)
liftReadsPrec Int -> ReadS a
rp ReadS [a]
rl = ([Char] -> ReadS (Word64Map a)) -> Int -> ReadS (Word64Map a)
forall a. ([Char] -> ReadS a) -> Int -> ReadS a
readsData (([Char] -> ReadS (Word64Map a)) -> Int -> ReadS (Word64Map a))
-> ([Char] -> ReadS (Word64Map a)) -> Int -> ReadS (Word64Map a)
forall a b. (a -> b) -> a -> b
$
(Int -> ReadS [(Word64, a)])
-> [Char]
-> ([(Word64, a)] -> Word64Map a)
-> [Char]
-> ReadS (Word64Map a)
forall a t.
(Int -> ReadS a) -> [Char] -> (a -> t) -> [Char] -> ReadS t
readsUnaryWith ((Int -> ReadS (Word64, a))
-> ReadS [(Word64, a)] -> Int -> ReadS [(Word64, a)]
forall a. (Int -> ReadS a) -> ReadS [a] -> Int -> ReadS [a]
forall (f :: * -> *) a.
Read1 f =>
(Int -> ReadS a) -> ReadS [a] -> Int -> ReadS (f a)
liftReadsPrec Int -> ReadS (Word64, a)
rp' ReadS [(Word64, a)]
rl') [Char]
"fromList" [(Word64, a)] -> Word64Map a
forall a. [(Word64, a)] -> Word64Map a
fromList
where
rp' :: Int -> ReadS (Word64, a)
rp' = (Int -> ReadS a) -> ReadS [a] -> Int -> ReadS (Word64, a)
forall a. (Int -> ReadS a) -> ReadS [a] -> Int -> ReadS (Word64, a)
forall (f :: * -> *) a.
Read1 f =>
(Int -> ReadS a) -> ReadS [a] -> Int -> ReadS (f a)
liftReadsPrec Int -> ReadS a
rp ReadS [a]
rl
rl' :: ReadS [(Word64, a)]
rl' = (Int -> ReadS a) -> ReadS [a] -> ReadS [(Word64, a)]
forall a. (Int -> ReadS a) -> ReadS [a] -> ReadS [(Word64, a)]
forall (f :: * -> *) a.
Read1 f =>
(Int -> ReadS a) -> ReadS [a] -> ReadS [f a]
liftReadList Int -> ReadS a
rp ReadS [a]
rl
link :: Prefix -> Word64Map a -> Prefix -> Word64Map a -> Word64Map a
link :: forall a.
Word64 -> Word64Map a -> Word64 -> Word64Map a -> Word64Map a
link Word64
p1 Word64Map a
t1 Word64
p2 Word64Map a
t2 = Word64 -> Word64 -> Word64Map a -> Word64Map a -> Word64Map a
forall a.
Word64 -> Word64 -> Word64Map a -> Word64Map a -> Word64Map a
linkWithMask (Word64 -> Word64 -> Word64
branchMask Word64
p1 Word64
p2) Word64
p1 Word64Map a
t1 Word64Map a
t2
{-# INLINE link #-}
linkWithMask :: Mask -> Prefix -> Word64Map a -> Word64Map a -> Word64Map a
linkWithMask :: forall a.
Word64 -> Word64 -> Word64Map a -> Word64Map a -> Word64Map a
linkWithMask Word64
m Word64
p1 Word64Map a
t1 Word64Map a
t2
| Word64 -> Word64 -> Bool
zero Word64
p1 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 Word64Map a
t1 Word64Map a
t2
| 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
t2 Word64Map a
t1
where
p :: Word64
p = Word64 -> Word64 -> Word64
mask Word64
p1 Word64
m
{-# INLINE linkWithMask #-}
bin :: Prefix -> Mask -> Word64Map a -> Word64Map a -> Word64Map a
bin :: forall a.
Word64 -> Word64 -> Word64Map a -> Word64Map a -> Word64Map a
bin Word64
_ Word64
_ Word64Map a
l Word64Map a
Nil = Word64Map a
l
bin Word64
_ Word64
_ Word64Map a
Nil Word64Map a
r = Word64Map a
r
bin Word64
p Word64
m Word64Map a
l Word64Map a
r = 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
{-# INLINE bin #-}
binCheckLeft :: Prefix -> Mask -> Word64Map a -> Word64Map a -> Word64Map a
binCheckLeft :: forall a.
Word64 -> Word64 -> Word64Map a -> Word64Map a -> Word64Map a
binCheckLeft Word64
_ Word64
_ Word64Map a
Nil Word64Map a
r = Word64Map a
r
binCheckLeft Word64
p Word64
m Word64Map a
l Word64Map a
r = 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
{-# INLINE binCheckLeft #-}
binCheckRight :: Prefix -> Mask -> Word64Map a -> Word64Map a -> Word64Map a
binCheckRight :: forall a.
Word64 -> Word64 -> Word64Map a -> Word64Map a -> Word64Map a
binCheckRight Word64
_ Word64
_ Word64Map a
l Word64Map a
Nil = Word64Map a
l
binCheckRight Word64
p Word64
m Word64Map a
l Word64Map a
r = 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
{-# INLINE binCheckRight #-}
zero :: Key -> Mask -> Bool
zero :: Word64 -> Word64 -> Bool
zero Word64
i Word64
m
= (Word64 -> Word64
natFromInt Word64
i) Word64 -> Word64 -> Word64
forall a. Bits a => a -> a -> a
.&. (Word64 -> Word64
natFromInt Word64
m) Word64 -> Word64 -> Bool
forall a. Eq a => a -> a -> Bool
== Word64
0
{-# INLINE zero #-}
nomatch,match :: Key -> Prefix -> Mask -> Bool
nomatch :: Word64 -> Word64 -> Word64 -> Bool
nomatch Word64
i Word64
p Word64
m
= (Word64 -> Word64 -> Word64
mask Word64
i Word64
m) Word64 -> Word64 -> Bool
forall a. Eq a => a -> a -> Bool
/= Word64
p
{-# INLINE nomatch #-}
match :: Word64 -> Word64 -> Word64 -> Bool
match Word64
i Word64
p Word64
m
= (Word64 -> Word64 -> Word64
mask Word64
i Word64
m) Word64 -> Word64 -> Bool
forall a. Eq a => a -> a -> Bool
== Word64
p
{-# INLINE match #-}
mask :: Key -> Mask -> Prefix
mask :: Word64 -> Word64 -> Word64
mask Word64
i Word64
m
= Word64 -> Word64 -> Word64
maskW (Word64 -> Word64
natFromInt Word64
i) (Word64 -> Word64
natFromInt Word64
m)
{-# INLINE mask #-}
maskW :: Nat -> Nat -> Prefix
maskW :: Word64 -> Word64 -> Word64
maskW Word64
i Word64
m
= Word64 -> Word64
intFromNat (Word64
i Word64 -> Word64 -> Word64
forall a. Bits a => a -> a -> a
.&. ((-Word64
m) Word64 -> Word64 -> Word64
forall a. Bits a => a -> a -> a
`xor` Word64
m))
{-# INLINE maskW #-}
shorter :: Mask -> Mask -> Bool
shorter :: Word64 -> Word64 -> Bool
shorter Word64
m1 Word64
m2
= (Word64 -> Word64
natFromInt Word64
m1) Word64 -> Word64 -> Bool
forall a. Ord a => a -> a -> Bool
> (Word64 -> Word64
natFromInt Word64
m2)
{-# INLINE shorter #-}
branchMask :: Prefix -> Prefix -> Mask
branchMask :: Word64 -> Word64 -> Word64
branchMask Word64
p1 Word64
p2
= Word64 -> Word64
intFromNat (Word64 -> Word64
highestBitMask (Word64 -> Word64
natFromInt Word64
p1 Word64 -> Word64 -> Word64
forall a. Bits a => a -> a -> a
`xor` Word64 -> Word64
natFromInt Word64
p2))
{-# INLINE branchMask #-}
splitRoot :: Word64Map a -> [Word64Map a]
splitRoot :: forall a. Word64Map a -> [Word64Map a]
splitRoot Word64Map a
orig =
case Word64Map a
orig of
Word64Map a
Nil -> []
x :: Word64Map a
x@(Tip Word64
_ a
_) -> [Word64Map a
x]
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
r, Word64Map a
l]
| Bool
otherwise -> [Word64Map a
l, Word64Map a
r]
{-# INLINE splitRoot #-}
showTree :: Show a => Word64Map a -> String
showTree :: forall a. Show a => Word64Map a -> [Char]
showTree Word64Map a
s
= Bool -> Bool -> Word64Map a -> [Char]
forall a. Show a => Bool -> Bool -> Word64Map a -> [Char]
showTreeWith Bool
True Bool
False Word64Map a
s
showTreeWith :: Show a => Bool -> Bool -> Word64Map a -> String
showTreeWith :: forall a. Show a => Bool -> Bool -> Word64Map a -> [Char]
showTreeWith Bool
hang Bool
wide Word64Map a
t
| Bool
hang = (Bool -> [[Char]] -> Word64Map a -> [Char] -> [Char]
forall a.
Show a =>
Bool -> [[Char]] -> Word64Map a -> [Char] -> [Char]
showsTreeHang Bool
wide [] Word64Map a
t) [Char]
""
| Bool
otherwise = (Bool -> [[Char]] -> [[Char]] -> Word64Map a -> [Char] -> [Char]
forall a.
Show a =>
Bool -> [[Char]] -> [[Char]] -> Word64Map a -> [Char] -> [Char]
showsTree Bool
wide [] [] Word64Map a
t) [Char]
""
showsTree :: Show a => Bool -> [String] -> [String] -> Word64Map a -> ShowS
showsTree :: forall a.
Show a =>
Bool -> [[Char]] -> [[Char]] -> Word64Map a -> [Char] -> [Char]
showsTree Bool
wide [[Char]]
lbars [[Char]]
rbars Word64Map a
t = case Word64Map a
t of
Bin Word64
p Word64
m Word64Map a
l Word64Map a
r ->
Bool -> [[Char]] -> [[Char]] -> Word64Map a -> [Char] -> [Char]
forall a.
Show a =>
Bool -> [[Char]] -> [[Char]] -> Word64Map a -> [Char] -> [Char]
showsTree Bool
wide ([[Char]] -> [[Char]]
withBar [[Char]]
rbars) ([[Char]] -> [[Char]]
withEmpty [[Char]]
rbars) Word64Map a
r ([Char] -> [Char]) -> ([Char] -> [Char]) -> [Char] -> [Char]
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
Bool -> [[Char]] -> [Char] -> [Char]
showWide Bool
wide [[Char]]
rbars ([Char] -> [Char]) -> ([Char] -> [Char]) -> [Char] -> [Char]
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
[[Char]] -> [Char] -> [Char]
showsBars [[Char]]
lbars ([Char] -> [Char]) -> ([Char] -> [Char]) -> [Char] -> [Char]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Char] -> [Char] -> [Char]
showString (Word64 -> Word64 -> [Char]
showBin Word64
p Word64
m) ([Char] -> [Char]) -> ([Char] -> [Char]) -> [Char] -> [Char]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Char] -> [Char] -> [Char]
showString [Char]
"\n" ([Char] -> [Char]) -> ([Char] -> [Char]) -> [Char] -> [Char]
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
Bool -> [[Char]] -> [Char] -> [Char]
showWide Bool
wide [[Char]]
lbars ([Char] -> [Char]) -> ([Char] -> [Char]) -> [Char] -> [Char]
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
Bool -> [[Char]] -> [[Char]] -> Word64Map a -> [Char] -> [Char]
forall a.
Show a =>
Bool -> [[Char]] -> [[Char]] -> Word64Map a -> [Char] -> [Char]
showsTree Bool
wide ([[Char]] -> [[Char]]
withEmpty [[Char]]
lbars) ([[Char]] -> [[Char]]
withBar [[Char]]
lbars) Word64Map a
l
Tip Word64
k a
x ->
[[Char]] -> [Char] -> [Char]
showsBars [[Char]]
lbars ([Char] -> [Char]) -> ([Char] -> [Char]) -> [Char] -> [Char]
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
[Char] -> [Char] -> [Char]
showString [Char]
" " ([Char] -> [Char]) -> ([Char] -> [Char]) -> [Char] -> [Char]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word64 -> [Char] -> [Char]
forall a. Show a => a -> [Char] -> [Char]
shows Word64
k ([Char] -> [Char]) -> ([Char] -> [Char]) -> [Char] -> [Char]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Char] -> [Char] -> [Char]
showString [Char]
":=" ([Char] -> [Char]) -> ([Char] -> [Char]) -> [Char] -> [Char]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> [Char] -> [Char]
forall a. Show a => a -> [Char] -> [Char]
shows a
x ([Char] -> [Char]) -> ([Char] -> [Char]) -> [Char] -> [Char]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Char] -> [Char] -> [Char]
showString [Char]
"\n"
Word64Map a
Nil -> [[Char]] -> [Char] -> [Char]
showsBars [[Char]]
lbars ([Char] -> [Char]) -> ([Char] -> [Char]) -> [Char] -> [Char]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Char] -> [Char] -> [Char]
showString [Char]
"|\n"
showsTreeHang :: Show a => Bool -> [String] -> Word64Map a -> ShowS
showsTreeHang :: forall a.
Show a =>
Bool -> [[Char]] -> Word64Map a -> [Char] -> [Char]
showsTreeHang Bool
wide [[Char]]
bars Word64Map a
t = case Word64Map a
t of
Bin Word64
p Word64
m Word64Map a
l Word64Map a
r ->
[[Char]] -> [Char] -> [Char]
showsBars [[Char]]
bars ([Char] -> [Char]) -> ([Char] -> [Char]) -> [Char] -> [Char]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Char] -> [Char] -> [Char]
showString (Word64 -> Word64 -> [Char]
showBin Word64
p Word64
m) ([Char] -> [Char]) -> ([Char] -> [Char]) -> [Char] -> [Char]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Char] -> [Char] -> [Char]
showString [Char]
"\n" ([Char] -> [Char]) -> ([Char] -> [Char]) -> [Char] -> [Char]
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
Bool -> [[Char]] -> [Char] -> [Char]
showWide Bool
wide [[Char]]
bars ([Char] -> [Char]) -> ([Char] -> [Char]) -> [Char] -> [Char]
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
Bool -> [[Char]] -> Word64Map a -> [Char] -> [Char]
forall a.
Show a =>
Bool -> [[Char]] -> Word64Map a -> [Char] -> [Char]
showsTreeHang Bool
wide ([[Char]] -> [[Char]]
withBar [[Char]]
bars) Word64Map a
l ([Char] -> [Char]) -> ([Char] -> [Char]) -> [Char] -> [Char]
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
Bool -> [[Char]] -> [Char] -> [Char]
showWide Bool
wide [[Char]]
bars ([Char] -> [Char]) -> ([Char] -> [Char]) -> [Char] -> [Char]
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
Bool -> [[Char]] -> Word64Map a -> [Char] -> [Char]
forall a.
Show a =>
Bool -> [[Char]] -> Word64Map a -> [Char] -> [Char]
showsTreeHang Bool
wide ([[Char]] -> [[Char]]
withEmpty [[Char]]
bars) Word64Map a
r
Tip Word64
k a
x ->
[[Char]] -> [Char] -> [Char]
showsBars [[Char]]
bars ([Char] -> [Char]) -> ([Char] -> [Char]) -> [Char] -> [Char]
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
[Char] -> [Char] -> [Char]
showString [Char]
" " ([Char] -> [Char]) -> ([Char] -> [Char]) -> [Char] -> [Char]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word64 -> [Char] -> [Char]
forall a. Show a => a -> [Char] -> [Char]
shows Word64
k ([Char] -> [Char]) -> ([Char] -> [Char]) -> [Char] -> [Char]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Char] -> [Char] -> [Char]
showString [Char]
":=" ([Char] -> [Char]) -> ([Char] -> [Char]) -> [Char] -> [Char]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> [Char] -> [Char]
forall a. Show a => a -> [Char] -> [Char]
shows a
x ([Char] -> [Char]) -> ([Char] -> [Char]) -> [Char] -> [Char]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Char] -> [Char] -> [Char]
showString [Char]
"\n"
Word64Map a
Nil -> [[Char]] -> [Char] -> [Char]
showsBars [[Char]]
bars ([Char] -> [Char]) -> ([Char] -> [Char]) -> [Char] -> [Char]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Char] -> [Char] -> [Char]
showString [Char]
"|\n"
showBin :: Prefix -> Mask -> String
showBin :: Word64 -> Word64 -> [Char]
showBin Word64
_ Word64
_
= [Char]
"*"
showWide :: Bool -> [String] -> String -> String
showWide :: Bool -> [[Char]] -> [Char] -> [Char]
showWide Bool
wide [[Char]]
bars
| Bool
wide = [Char] -> [Char] -> [Char]
showString ([[Char]] -> [Char]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat ([[Char]] -> [[Char]]
forall a. [a] -> [a]
reverse [[Char]]
bars)) ([Char] -> [Char]) -> ([Char] -> [Char]) -> [Char] -> [Char]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Char] -> [Char] -> [Char]
showString [Char]
"|\n"
| Bool
otherwise = [Char] -> [Char]
forall a. a -> a
id
showsBars :: [String] -> ShowS
showsBars :: [[Char]] -> [Char] -> [Char]
showsBars [[Char]]
bars
= case [[Char]]
bars of
[] -> [Char] -> [Char]
forall a. a -> a
id
[Char]
_ : [[Char]]
tl -> [Char] -> [Char] -> [Char]
showString ([[Char]] -> [Char]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat ([[Char]] -> [[Char]]
forall a. [a] -> [a]
reverse [[Char]]
tl)) ([Char] -> [Char]) -> ([Char] -> [Char]) -> [Char] -> [Char]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Char] -> [Char] -> [Char]
showString [Char]
node
node :: String
node :: [Char]
node = [Char]
"+--"
withBar, withEmpty :: [String] -> [String]
withBar :: [[Char]] -> [[Char]]
withBar [[Char]]
bars = [Char]
"| "[Char] -> [[Char]] -> [[Char]]
forall a. a -> [a] -> [a]
:[[Char]]
bars
withEmpty :: [[Char]] -> [[Char]]
withEmpty [[Char]]
bars = [Char]
" "[Char] -> [[Char]] -> [[Char]]
forall a. a -> [a] -> [a]
:[[Char]]
bars