{-# LANGUAGE CPP #-}
{-# OPTIONS_GHC -fno-warn-incomplete-uni-patterns #-}
module GHC.Data.Word64Map.Strict.Internal (
#if !defined(TESTING)
Word64Map, Key
#else
Word64Map(..), Key
#endif
, empty
, singleton
, fromSet
, fromList
, fromListWith
, fromListWithKey
, fromAscList
, fromAscListWith
, fromAscListWithKey
, fromDistinctAscList
, insert
, insertWith
, insertWithKey
, insertLookupWithKey
, delete
, adjust
, adjustWithKey
, update
, updateWithKey
, updateLookupWithKey
, alter
, alterF
, lookup
, (!?)
, (!)
, findWithDefault
, member
, notMember
, lookupLT
, lookupGT
, lookupLE
, lookupGE
, null
, size
, union
, unionWith
, unionWithKey
, unions
, unionsWith
, difference
, (\\)
, differenceWith
, differenceWithKey
, intersection
, intersectionWith
, intersectionWithKey
, disjoint
, compose
, mergeWithKey
, map
, mapWithKey
, traverseWithKey
, traverseMaybeWithKey
, mapAccum
, mapAccumWithKey
, mapAccumRWithKey
, mapKeys
, mapKeysWith
, mapKeysMonotonic
, foldr
, foldl
, foldrWithKey
, foldlWithKey
, foldMapWithKey
, foldr'
, foldl'
, foldrWithKey'
, foldlWithKey'
, elems
, keys
, assocs
, keysSet
, toList
, toAscList
, toDescList
, 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
) where
import GHC.Prelude.Basic hiding
(lookup, filter, foldr, foldl, foldl', null, map)
import qualified GHC.Data.Word64Map.Internal as L
import GHC.Data.Word64Map.Internal
( Word64Map (..)
, Key
, mask
, branchMask
, nomatch
, zero
, natFromInt
, intFromNat
, bin
, binCheckLeft
, binCheckRight
, link
, linkWithMask
, (\\)
, (!)
, (!?)
, empty
, assocs
, filter
, filterWithKey
, findMin
, findMax
, foldMapWithKey
, foldr
, foldl
, foldr'
, foldl'
, foldlWithKey
, foldrWithKey
, foldlWithKey'
, foldrWithKey'
, keysSet
, mergeWithKey'
, compose
, delete
, deleteMin
, deleteMax
, deleteFindMax
, deleteFindMin
, difference
, elems
, intersection
, disjoint
, isProperSubmapOf
, isProperSubmapOfBy
, isSubmapOf
, isSubmapOfBy
, lookup
, lookupLE
, lookupGE
, lookupLT
, lookupGT
, lookupMin
, lookupMax
, minView
, maxView
, minViewWithKey
, maxViewWithKey
, keys
, mapKeys
, mapKeysMonotonic
, member
, notMember
, null
, partition
, partitionWithKey
, takeWhileAntitone
, dropWhileAntitone
, spanAntitone
, restrictKeys
, size
, split
, splitLookup
, splitRoot
, toAscList
, toDescList
, toList
, union
, unions
, withoutKeys
)
import qualified GHC.Data.Word64Set.Internal as Word64Set
import GHC.Utils.Containers.Internal.BitUtil
import GHC.Utils.Containers.Internal.StrictPair
import qualified Data.Foldable as Foldable
findWithDefault :: a -> Key -> Word64Map a -> a
findWithDefault :: forall a. a -> Key -> Word64Map a -> a
findWithDefault a
def !Key
k = Word64Map a -> a
go
where
go :: Word64Map a -> a
go (Bin Key
p Key
m Word64Map a
l Word64Map a
r) | Key -> Key -> Key -> Bool
nomatch Key
k Key
p Key
m = a
def
| Key -> Key -> Bool
zero Key
k Key
m = Word64Map a -> a
go Word64Map a
l
| Bool
otherwise = Word64Map a -> a
go Word64Map a
r
go (Tip Key
kx a
x) | Key
k Key -> Key -> Bool
forall a. Eq a => a -> a -> Bool
== Key
kx = a
x
| Bool
otherwise = a
def
go Word64Map a
Nil = a
def
singleton :: Key -> a -> Word64Map a
singleton :: forall a. Key -> a -> Word64Map a
singleton Key
k !a
x
= Key -> a -> Word64Map a
forall a. Key -> a -> Word64Map a
Tip Key
k a
x
{-# INLINE singleton #-}
insert :: Key -> a -> Word64Map a -> Word64Map a
insert :: forall a. Key -> a -> Word64Map a -> Word64Map a
insert !Key
k !a
x Word64Map a
t =
case Word64Map a
t of
Bin Key
p Key
m Word64Map a
l Word64Map a
r
| Key -> Key -> Key -> Bool
nomatch Key
k Key
p Key
m -> Key -> Word64Map a -> Key -> Word64Map a -> Word64Map a
forall a. Key -> Word64Map a -> Key -> Word64Map a -> Word64Map a
link Key
k (Key -> a -> Word64Map a
forall a. Key -> a -> Word64Map a
Tip Key
k a
x) Key
p Word64Map a
t
| Key -> Key -> Bool
zero Key
k Key
m -> Key -> Key -> Word64Map a -> Word64Map a -> Word64Map a
forall a. Key -> Key -> Word64Map a -> Word64Map a -> Word64Map a
Bin Key
p Key
m (Key -> a -> Word64Map a -> Word64Map a
forall a. Key -> a -> Word64Map a -> Word64Map a
insert Key
k a
x Word64Map a
l) Word64Map a
r
| Bool
otherwise -> Key -> Key -> Word64Map a -> Word64Map a -> Word64Map a
forall a. Key -> Key -> Word64Map a -> Word64Map a -> Word64Map a
Bin Key
p Key
m Word64Map a
l (Key -> a -> Word64Map a -> Word64Map a
forall a. Key -> a -> Word64Map a -> Word64Map a
insert Key
k a
x Word64Map a
r)
Tip Key
ky a
_
| Key
kKey -> Key -> Bool
forall a. Eq a => a -> a -> Bool
==Key
ky -> Key -> a -> Word64Map a
forall a. Key -> a -> Word64Map a
Tip Key
k a
x
| Bool
otherwise -> Key -> Word64Map a -> Key -> Word64Map a -> Word64Map a
forall a. Key -> Word64Map a -> Key -> Word64Map a -> Word64Map a
link Key
k (Key -> a -> Word64Map a
forall a. Key -> a -> Word64Map a
Tip Key
k a
x) Key
ky Word64Map a
t
Word64Map a
Nil -> Key -> a -> Word64Map a
forall a. Key -> a -> Word64Map a
Tip Key
k a
x
insertWith :: (a -> a -> a) -> Key -> a -> Word64Map a -> Word64Map a
insertWith :: forall a. (a -> a -> a) -> Key -> a -> Word64Map a -> Word64Map a
insertWith a -> a -> a
f Key
k a
x Word64Map a
t
= (Key -> a -> a -> a) -> Key -> a -> Word64Map a -> Word64Map a
forall a.
(Key -> a -> a -> a) -> Key -> a -> Word64Map a -> Word64Map a
insertWithKey (\Key
_ a
x' a
y' -> a -> a -> a
f a
x' a
y') Key
k a
x Word64Map a
t
insertWithKey :: (Key -> a -> a -> a) -> Key -> a -> Word64Map a -> Word64Map a
insertWithKey :: forall a.
(Key -> a -> a -> a) -> Key -> a -> Word64Map a -> Word64Map a
insertWithKey Key -> a -> a -> a
f !Key
k a
x Word64Map a
t =
case Word64Map a
t of
Bin Key
p Key
m Word64Map a
l Word64Map a
r
| Key -> Key -> Key -> Bool
nomatch Key
k Key
p Key
m -> Key -> Word64Map a -> Key -> Word64Map a -> Word64Map a
forall a. Key -> Word64Map a -> Key -> Word64Map a -> Word64Map a
link Key
k (Key -> a -> Word64Map a
forall a. Key -> a -> Word64Map a
singleton Key
k a
x) Key
p Word64Map a
t
| Key -> Key -> Bool
zero Key
k Key
m -> Key -> Key -> Word64Map a -> Word64Map a -> Word64Map a
forall a. Key -> Key -> Word64Map a -> Word64Map a -> Word64Map a
Bin Key
p Key
m ((Key -> a -> a -> a) -> Key -> a -> Word64Map a -> Word64Map a
forall a.
(Key -> a -> a -> a) -> Key -> a -> Word64Map a -> Word64Map a
insertWithKey Key -> a -> a -> a
f Key
k a
x Word64Map a
l) Word64Map a
r
| Bool
otherwise -> Key -> Key -> Word64Map a -> Word64Map a -> Word64Map a
forall a. Key -> Key -> Word64Map a -> Word64Map a -> Word64Map a
Bin Key
p Key
m Word64Map a
l ((Key -> a -> a -> a) -> Key -> a -> Word64Map a -> Word64Map a
forall a.
(Key -> a -> a -> a) -> Key -> a -> Word64Map a -> Word64Map a
insertWithKey Key -> a -> a -> a
f Key
k a
x Word64Map a
r)
Tip Key
ky a
y
| Key
kKey -> Key -> Bool
forall a. Eq a => a -> a -> Bool
==Key
ky -> Key -> a -> Word64Map a
forall a. Key -> a -> Word64Map a
Tip Key
k (a -> Word64Map a) -> a -> Word64Map a
forall a b. (a -> b) -> a -> b
$! Key -> a -> a -> a
f Key
k a
x a
y
| Bool
otherwise -> Key -> Word64Map a -> Key -> Word64Map a -> Word64Map a
forall a. Key -> Word64Map a -> Key -> Word64Map a -> Word64Map a
link Key
k (Key -> a -> Word64Map a
forall a. Key -> a -> Word64Map a
singleton Key
k a
x) Key
ky Word64Map a
t
Word64Map a
Nil -> Key -> a -> Word64Map a
forall a. Key -> a -> Word64Map a
singleton Key
k a
x
insertLookupWithKey :: (Key -> a -> a -> a) -> Key -> a -> Word64Map a -> (Maybe a, Word64Map a)
insertLookupWithKey :: forall a.
(Key -> a -> a -> a)
-> Key -> a -> Word64Map a -> (Maybe a, Word64Map a)
insertLookupWithKey Key -> a -> a -> a
f0 !Key
k0 a
x0 Word64Map a
t0 = StrictPair (Maybe a) (Word64Map a) -> (Maybe a, Word64Map a)
forall a b. StrictPair a b -> (a, b)
toPair (StrictPair (Maybe a) (Word64Map a) -> (Maybe a, Word64Map a))
-> StrictPair (Maybe a) (Word64Map a) -> (Maybe a, Word64Map a)
forall a b. (a -> b) -> a -> b
$ (Key -> a -> a -> a)
-> Key -> a -> Word64Map a -> StrictPair (Maybe a) (Word64Map a)
forall {t}.
(Key -> t -> t -> t)
-> Key -> t -> Word64Map t -> StrictPair (Maybe t) (Word64Map t)
go Key -> a -> a -> a
f0 Key
k0 a
x0 Word64Map a
t0
where
go :: (Key -> t -> t -> t)
-> Key -> t -> Word64Map t -> StrictPair (Maybe t) (Word64Map t)
go Key -> t -> t -> t
f Key
k t
x Word64Map t
t =
case Word64Map t
t of
Bin Key
p Key
m Word64Map t
l Word64Map t
r
| Key -> Key -> Key -> Bool
nomatch Key
k Key
p Key
m -> Maybe t
forall a. Maybe a
Nothing Maybe t -> Word64Map t -> StrictPair (Maybe t) (Word64Map t)
forall a b. a -> b -> StrictPair a b
:*: Key -> Word64Map t -> Key -> Word64Map t -> Word64Map t
forall a. Key -> Word64Map a -> Key -> Word64Map a -> Word64Map a
link Key
k (Key -> t -> Word64Map t
forall a. Key -> a -> Word64Map a
singleton Key
k t
x) Key
p Word64Map t
t
| Key -> Key -> Bool
zero Key
k Key
m -> let (Maybe t
found :*: Word64Map t
l') = (Key -> t -> t -> t)
-> Key -> t -> Word64Map t -> StrictPair (Maybe t) (Word64Map t)
go Key -> t -> t -> t
f Key
k t
x Word64Map t
l in (Maybe t
found Maybe t -> Word64Map t -> StrictPair (Maybe t) (Word64Map t)
forall a b. a -> b -> StrictPair a b
:*: Key -> Key -> Word64Map t -> Word64Map t -> Word64Map t
forall a. Key -> Key -> Word64Map a -> Word64Map a -> Word64Map a
Bin Key
p Key
m Word64Map t
l' Word64Map t
r)
| Bool
otherwise -> let (Maybe t
found :*: Word64Map t
r') = (Key -> t -> t -> t)
-> Key -> t -> Word64Map t -> StrictPair (Maybe t) (Word64Map t)
go Key -> t -> t -> t
f Key
k t
x Word64Map t
r in (Maybe t
found Maybe t -> Word64Map t -> StrictPair (Maybe t) (Word64Map t)
forall a b. a -> b -> StrictPair a b
:*: Key -> Key -> Word64Map t -> Word64Map t -> Word64Map t
forall a. Key -> Key -> Word64Map a -> Word64Map a -> Word64Map a
Bin Key
p Key
m Word64Map t
l Word64Map t
r')
Tip Key
ky t
y
| Key
kKey -> Key -> Bool
forall a. Eq a => a -> a -> Bool
==Key
ky -> (t -> Maybe t
forall a. a -> Maybe a
Just t
y Maybe t -> Word64Map t -> StrictPair (Maybe t) (Word64Map t)
forall a b. a -> b -> StrictPair a b
:*: (Key -> t -> Word64Map t
forall a. Key -> a -> Word64Map a
Tip Key
k (t -> Word64Map t) -> t -> Word64Map t
forall a b. (a -> b) -> a -> b
$! Key -> t -> t -> t
f Key
k t
x t
y))
| Bool
otherwise -> (Maybe t
forall a. Maybe a
Nothing Maybe t -> Word64Map t -> StrictPair (Maybe t) (Word64Map t)
forall a b. a -> b -> StrictPair a b
:*: Key -> Word64Map t -> Key -> Word64Map t -> Word64Map t
forall a. Key -> Word64Map a -> Key -> Word64Map a -> Word64Map a
link Key
k (Key -> t -> Word64Map t
forall a. Key -> a -> Word64Map a
singleton Key
k t
x) Key
ky Word64Map t
t)
Word64Map t
Nil -> Maybe t
forall a. Maybe a
Nothing Maybe t -> Word64Map t -> StrictPair (Maybe t) (Word64Map t)
forall a b. a -> b -> StrictPair a b
:*: (Key -> t -> Word64Map t
forall a. Key -> a -> Word64Map a
singleton Key
k t
x)
adjust :: (a -> a) -> Key -> Word64Map a -> Word64Map a
adjust :: forall a. (a -> a) -> Key -> Word64Map a -> Word64Map a
adjust a -> a
f Key
k Word64Map a
m
= (Key -> a -> a) -> Key -> Word64Map a -> Word64Map a
forall a. (Key -> a -> a) -> Key -> Word64Map a -> Word64Map a
adjustWithKey (\Key
_ a
x -> a -> a
f a
x) Key
k Word64Map a
m
adjustWithKey :: (Key -> a -> a) -> Key -> Word64Map a -> Word64Map a
adjustWithKey :: forall a. (Key -> a -> a) -> Key -> Word64Map a -> Word64Map a
adjustWithKey Key -> a -> a
f !Key
k Word64Map a
t =
case Word64Map a
t of
Bin Key
p Key
m Word64Map a
l Word64Map a
r
| Key -> Key -> Key -> Bool
nomatch Key
k Key
p Key
m -> Word64Map a
t
| Key -> Key -> Bool
zero Key
k Key
m -> Key -> Key -> Word64Map a -> Word64Map a -> Word64Map a
forall a. Key -> Key -> Word64Map a -> Word64Map a -> Word64Map a
Bin Key
p Key
m ((Key -> a -> a) -> Key -> Word64Map a -> Word64Map a
forall a. (Key -> a -> a) -> Key -> Word64Map a -> Word64Map a
adjustWithKey Key -> a -> a
f Key
k Word64Map a
l) Word64Map a
r
| Bool
otherwise -> Key -> Key -> Word64Map a -> Word64Map a -> Word64Map a
forall a. Key -> Key -> Word64Map a -> Word64Map a -> Word64Map a
Bin Key
p Key
m Word64Map a
l ((Key -> a -> a) -> Key -> Word64Map a -> Word64Map a
forall a. (Key -> a -> a) -> Key -> Word64Map a -> Word64Map a
adjustWithKey Key -> a -> a
f Key
k Word64Map a
r)
Tip Key
ky a
y
| Key
kKey -> Key -> Bool
forall a. Eq a => a -> a -> Bool
==Key
ky -> Key -> a -> Word64Map a
forall a. Key -> a -> Word64Map a
Tip Key
ky (a -> Word64Map a) -> a -> Word64Map a
forall a b. (a -> b) -> a -> b
$! Key -> a -> a
f Key
k a
y
| Bool
otherwise -> Word64Map a
t
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) -> Key -> Word64Map a -> Word64Map a
update a -> Maybe a
f
= (Key -> a -> Maybe a) -> Key -> Word64Map a -> Word64Map a
forall a.
(Key -> a -> Maybe a) -> Key -> Word64Map a -> Word64Map a
updateWithKey (\Key
_ a
x -> a -> Maybe a
f a
x)
updateWithKey :: (Key -> a -> Maybe a) -> Key -> Word64Map a -> Word64Map a
updateWithKey :: forall a.
(Key -> a -> Maybe a) -> Key -> Word64Map a -> Word64Map a
updateWithKey Key -> a -> Maybe a
f !Key
k Word64Map a
t =
case Word64Map a
t of
Bin Key
p Key
m Word64Map a
l Word64Map a
r
| Key -> Key -> Key -> Bool
nomatch Key
k Key
p Key
m -> Word64Map a
t
| Key -> Key -> Bool
zero Key
k Key
m -> Key -> Key -> Word64Map a -> Word64Map a -> Word64Map a
forall a. Key -> Key -> Word64Map a -> Word64Map a -> Word64Map a
binCheckLeft Key
p Key
m ((Key -> a -> Maybe a) -> Key -> Word64Map a -> Word64Map a
forall a.
(Key -> a -> Maybe a) -> Key -> Word64Map a -> Word64Map a
updateWithKey Key -> a -> Maybe a
f Key
k Word64Map a
l) Word64Map a
r
| Bool
otherwise -> Key -> Key -> Word64Map a -> Word64Map a -> Word64Map a
forall a. Key -> Key -> Word64Map a -> Word64Map a -> Word64Map a
binCheckRight Key
p Key
m Word64Map a
l ((Key -> a -> Maybe a) -> Key -> Word64Map a -> Word64Map a
forall a.
(Key -> a -> Maybe a) -> Key -> Word64Map a -> Word64Map a
updateWithKey Key -> a -> Maybe a
f Key
k Word64Map a
r)
Tip Key
ky a
y
| Key
kKey -> Key -> Bool
forall a. Eq a => a -> a -> Bool
==Key
ky -> case Key -> a -> Maybe a
f Key
k a
y of
Just !a
y' -> Key -> a -> Word64Map a
forall a. Key -> a -> Word64Map a
Tip Key
ky a
y'
Maybe a
Nothing -> Word64Map a
forall a. Word64Map a
Nil
| Bool
otherwise -> Word64Map a
t
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.
(Key -> a -> Maybe a)
-> Key -> Word64Map a -> (Maybe a, Word64Map a)
updateLookupWithKey Key -> a -> Maybe a
f0 !Key
k0 Word64Map a
t0 = StrictPair (Maybe a) (Word64Map a) -> (Maybe a, Word64Map a)
forall a b. StrictPair a b -> (a, b)
toPair (StrictPair (Maybe a) (Word64Map a) -> (Maybe a, Word64Map a))
-> StrictPair (Maybe a) (Word64Map a) -> (Maybe a, Word64Map a)
forall a b. (a -> b) -> a -> b
$ (Key -> a -> Maybe a)
-> Key -> Word64Map a -> StrictPair (Maybe a) (Word64Map a)
forall {a}.
(Key -> a -> Maybe a)
-> Key -> Word64Map a -> StrictPair (Maybe a) (Word64Map a)
go Key -> a -> Maybe a
f0 Key
k0 Word64Map a
t0
where
go :: (Key -> a -> Maybe a)
-> Key -> Word64Map a -> StrictPair (Maybe a) (Word64Map a)
go Key -> a -> Maybe a
f Key
k Word64Map a
t =
case Word64Map a
t of
Bin Key
p Key
m Word64Map a
l Word64Map a
r
| Key -> Key -> Key -> Bool
nomatch Key
k Key
p Key
m -> (Maybe a
forall a. Maybe a
Nothing Maybe a -> Word64Map a -> StrictPair (Maybe a) (Word64Map a)
forall a b. a -> b -> StrictPair a b
:*: Word64Map a
t)
| Key -> Key -> Bool
zero Key
k Key
m -> let (Maybe a
found :*: Word64Map a
l') = (Key -> a -> Maybe a)
-> Key -> Word64Map a -> StrictPair (Maybe a) (Word64Map a)
go Key -> a -> Maybe a
f Key
k Word64Map a
l in (Maybe a
found Maybe a -> Word64Map a -> StrictPair (Maybe a) (Word64Map a)
forall a b. a -> b -> StrictPair a b
:*: Key -> Key -> Word64Map a -> Word64Map a -> Word64Map a
forall a. Key -> Key -> Word64Map a -> Word64Map a -> Word64Map a
binCheckLeft Key
p Key
m Word64Map a
l' Word64Map a
r)
| Bool
otherwise -> let (Maybe a
found :*: Word64Map a
r') = (Key -> a -> Maybe a)
-> Key -> Word64Map a -> StrictPair (Maybe a) (Word64Map a)
go Key -> a -> Maybe a
f Key
k Word64Map a
r in (Maybe a
found Maybe a -> Word64Map a -> StrictPair (Maybe a) (Word64Map a)
forall a b. a -> b -> StrictPair a b
:*: Key -> Key -> Word64Map a -> Word64Map a -> Word64Map a
forall a. Key -> Key -> Word64Map a -> Word64Map a -> Word64Map a
binCheckRight Key
p Key
m Word64Map a
l Word64Map a
r')
Tip Key
ky a
y
| Key
kKey -> Key -> Bool
forall a. Eq a => a -> a -> Bool
==Key
ky -> case Key -> a -> Maybe a
f Key
k a
y of
Just !a
y' -> (a -> Maybe a
forall a. a -> Maybe a
Just a
y Maybe a -> Word64Map a -> StrictPair (Maybe a) (Word64Map a)
forall a b. a -> b -> StrictPair a b
:*: Key -> a -> Word64Map a
forall a. Key -> a -> Word64Map a
Tip Key
ky a
y')
Maybe a
Nothing -> (a -> Maybe a
forall a. a -> Maybe a
Just a
y Maybe a -> Word64Map a -> StrictPair (Maybe a) (Word64Map a)
forall a b. a -> b -> StrictPair a b
:*: Word64Map a
forall a. Word64Map a
Nil)
| Bool
otherwise -> (Maybe a
forall a. Maybe a
Nothing Maybe a -> Word64Map a -> StrictPair (Maybe a) (Word64Map a)
forall a b. a -> b -> StrictPair a b
:*: Word64Map a
t)
Word64Map a
Nil -> (Maybe a
forall a. Maybe a
Nothing Maybe a -> Word64Map a -> StrictPair (Maybe a) (Word64Map a)
forall a b. a -> b -> StrictPair a b
:*: Word64Map a
forall a. Word64Map a
Nil)
alter :: (Maybe a -> Maybe a) -> Key -> Word64Map a -> Word64Map a
alter :: forall a. (Maybe a -> Maybe a) -> Key -> Word64Map a -> Word64Map a
alter Maybe a -> Maybe a
f !Key
k Word64Map a
t =
case Word64Map a
t of
Bin Key
p Key
m Word64Map a
l Word64Map a
r
| Key -> Key -> Key -> Bool
nomatch Key
k Key
p Key
m -> case Maybe a -> Maybe a
f Maybe a
forall a. Maybe a
Nothing of
Maybe a
Nothing -> Word64Map a
t
Just !a
x -> Key -> Word64Map a -> Key -> Word64Map a -> Word64Map a
forall a. Key -> Word64Map a -> Key -> Word64Map a -> Word64Map a
link Key
k (Key -> a -> Word64Map a
forall a. Key -> a -> Word64Map a
Tip Key
k a
x) Key
p Word64Map a
t
| Key -> Key -> Bool
zero Key
k Key
m -> Key -> Key -> Word64Map a -> Word64Map a -> Word64Map a
forall a. Key -> Key -> Word64Map a -> Word64Map a -> Word64Map a
binCheckLeft Key
p Key
m ((Maybe a -> Maybe a) -> Key -> Word64Map a -> Word64Map a
forall a. (Maybe a -> Maybe a) -> Key -> Word64Map a -> Word64Map a
alter Maybe a -> Maybe a
f Key
k Word64Map a
l) Word64Map a
r
| Bool
otherwise -> Key -> Key -> Word64Map a -> Word64Map a -> Word64Map a
forall a. Key -> Key -> Word64Map a -> Word64Map a -> Word64Map a
binCheckRight Key
p Key
m Word64Map a
l ((Maybe a -> Maybe a) -> Key -> Word64Map a -> Word64Map a
forall a. (Maybe a -> Maybe a) -> Key -> Word64Map a -> Word64Map a
alter Maybe a -> Maybe a
f Key
k Word64Map a
r)
Tip Key
ky a
y
| Key
kKey -> Key -> Bool
forall a. Eq a => a -> a -> Bool
==Key
ky -> case Maybe a -> Maybe a
f (a -> Maybe a
forall a. a -> Maybe a
Just a
y) of
Just !a
x -> Key -> a -> Word64Map a
forall a. Key -> a -> Word64Map a
Tip Key
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 -> Key -> Word64Map a -> Key -> Word64Map a -> Word64Map a
forall a. Key -> Word64Map a -> Key -> Word64Map a -> Word64Map a
link Key
k (Key -> a -> Word64Map a
forall a. Key -> a -> Word64Map a
Tip Key
k a
x) Key
ky Word64Map a
t
Maybe a
Nothing -> Word64Map a
t
Word64Map a
Nil -> case Maybe a -> Maybe a
f Maybe a
forall a. Maybe a
Nothing of
Just !a
x -> Key -> a -> Word64Map a
forall a. Key -> a -> Word64Map a
Tip Key
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)) -> Key -> Word64Map a -> f (Word64Map a)
alterF Maybe a -> f (Maybe a)
f Key
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 (Key -> Word64Map a -> Word64Map a
forall a. Key -> Word64Map a -> Word64Map a
delete Key
k Word64Map a
m)) Maybe a
mv
Just !a
v' -> Key -> a -> Word64Map a -> Word64Map a
forall a. Key -> a -> Word64Map a -> Word64Map a
insert Key
k a
v' Word64Map a
m
where mv :: Maybe a
mv = Key -> Word64Map a -> Maybe a
forall a. Key -> Word64Map a -> Maybe a
lookup Key
k Word64Map a
m
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
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
= (Key -> a -> a -> a) -> Word64Map a -> Word64Map a -> Word64Map a
forall a.
(Key -> a -> a -> a) -> Word64Map a -> Word64Map a -> Word64Map a
unionWithKey (\Key
_ 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.
(Key -> a -> a -> a) -> Word64Map a -> Word64Map a -> Word64Map a
unionWithKey Key -> a -> a -> a
f Word64Map a
m1 Word64Map a
m2
= (Key -> Key -> 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.
(Key -> Key -> 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' Key -> Key -> Word64Map a -> Word64Map a -> Word64Map a
forall a. Key -> Key -> Word64Map a -> Word64Map a -> Word64Map a
Bin (\(Tip Key
k1 a
x1) (Tip Key
_k2 a
x2) -> Key -> a -> Word64Map a
forall a. Key -> a -> Word64Map a
Tip Key
k1 (a -> Word64Map a) -> a -> Word64Map a
forall a b. (a -> b) -> a -> b
$! Key -> a -> a -> a
f Key
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
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
= (Key -> a -> b -> Maybe a)
-> Word64Map a -> Word64Map b -> Word64Map a
forall a b.
(Key -> a -> b -> Maybe a)
-> Word64Map a -> Word64Map b -> Word64Map a
differenceWithKey (\Key
_ 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.
(Key -> a -> b -> Maybe a)
-> Word64Map a -> Word64Map b -> Word64Map a
differenceWithKey Key -> a -> b -> Maybe a
f Word64Map a
m1 Word64Map b
m2
= (Key -> a -> b -> Maybe a)
-> (Word64Map a -> Word64Map a)
-> (Word64Map b -> Word64Map a)
-> Word64Map a
-> Word64Map b
-> Word64Map a
forall a b c.
(Key -> a -> b -> Maybe c)
-> (Word64Map a -> Word64Map c)
-> (Word64Map b -> Word64Map c)
-> Word64Map a
-> Word64Map b
-> Word64Map c
mergeWithKey Key -> 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
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
= (Key -> a -> b -> c) -> Word64Map a -> Word64Map b -> Word64Map c
forall a b c.
(Key -> a -> b -> c) -> Word64Map a -> Word64Map b -> Word64Map c
intersectionWithKey (\Key
_ 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.
(Key -> a -> b -> c) -> Word64Map a -> Word64Map b -> Word64Map c
intersectionWithKey Key -> a -> b -> c
f Word64Map a
m1 Word64Map b
m2
= (Key -> Key -> 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.
(Key -> Key -> 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' Key -> Key -> Word64Map c -> Word64Map c -> Word64Map c
forall a. Key -> Key -> Word64Map a -> Word64Map a -> Word64Map a
bin (\(Tip Key
k1 a
x1) (Tip Key
_k2 b
x2) -> Key -> c -> Word64Map c
forall a. Key -> a -> Word64Map a
Tip Key
k1 (c -> Word64Map c) -> c -> Word64Map c
forall a b. (a -> b) -> a -> b
$! Key -> a -> b -> c
f Key
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.
(Key -> a -> b -> Maybe c)
-> (Word64Map a -> Word64Map c)
-> (Word64Map b -> Word64Map c)
-> Word64Map a
-> Word64Map b
-> Word64Map c
mergeWithKey Key -> a -> b -> Maybe c
f Word64Map a -> Word64Map c
g1 Word64Map b -> Word64Map c
g2 = (Key -> Key -> 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.
(Key -> Key -> 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' Key -> Key -> Word64Map c -> Word64Map c -> Word64Map c
forall a. Key -> Key -> 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 Key
k1 a
x1) (Tip Key
_k2 b
x2) -> case Key -> a -> b -> Maybe c
f Key
k1 a
x1 b
x2 of Maybe c
Nothing -> Word64Map c
forall a. Word64Map a
Nil
Just !c
x -> Key -> c -> Word64Map c
forall a. Key -> a -> Word64Map a
Tip Key
k1 c
x
{-# INLINE combine #-}
{-# INLINE mergeWithKey #-}
updateMinWithKey :: (Key -> a -> Maybe a) -> Word64Map a -> Word64Map a
updateMinWithKey :: forall a. (Key -> a -> Maybe a) -> Word64Map a -> Word64Map a
updateMinWithKey Key -> a -> Maybe a
f Word64Map a
t =
case Word64Map a
t of Bin Key
p Key
m Word64Map a
l Word64Map a
r | Key
m Key -> Key -> Bool
forall a. Ord a => a -> a -> Bool
< Key
0 -> Key -> Key -> Word64Map a -> Word64Map a -> Word64Map a
forall a. Key -> Key -> Word64Map a -> Word64Map a -> Word64Map a
binCheckRight Key
p Key
m Word64Map a
l ((Key -> a -> Maybe a) -> Word64Map a -> Word64Map a
forall a. (Key -> a -> Maybe a) -> Word64Map a -> Word64Map a
go Key -> a -> Maybe a
f Word64Map a
r)
Word64Map a
_ -> (Key -> a -> Maybe a) -> Word64Map a -> Word64Map a
forall a. (Key -> a -> Maybe a) -> Word64Map a -> Word64Map a
go Key -> a -> Maybe a
f Word64Map a
t
where
go :: (Key -> t -> Maybe t) -> Word64Map t -> Word64Map t
go Key -> t -> Maybe t
f' (Bin Key
p Key
m Word64Map t
l Word64Map t
r) = Key -> Key -> Word64Map t -> Word64Map t -> Word64Map t
forall a. Key -> Key -> Word64Map a -> Word64Map a -> Word64Map a
binCheckLeft Key
p Key
m ((Key -> t -> Maybe t) -> Word64Map t -> Word64Map t
go Key -> t -> Maybe t
f' Word64Map t
l) Word64Map t
r
go Key -> t -> Maybe t
f' (Tip Key
k t
y) = case Key -> t -> Maybe t
f' Key
k t
y of
Just !t
y' -> Key -> t -> Word64Map t
forall a. Key -> a -> Word64Map a
Tip Key
k t
y'
Maybe t
Nothing -> Word64Map t
forall a. Word64Map a
Nil
go Key -> 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. (Key -> a -> Maybe a) -> Word64Map a -> Word64Map a
updateMaxWithKey Key -> a -> Maybe a
f Word64Map a
t =
case Word64Map a
t of Bin Key
p Key
m Word64Map a
l Word64Map a
r | Key
m Key -> Key -> Bool
forall a. Ord a => a -> a -> Bool
< Key
0 -> Key -> Key -> Word64Map a -> Word64Map a -> Word64Map a
forall a. Key -> Key -> Word64Map a -> Word64Map a -> Word64Map a
binCheckLeft Key
p Key
m ((Key -> a -> Maybe a) -> Word64Map a -> Word64Map a
forall a. (Key -> a -> Maybe a) -> Word64Map a -> Word64Map a
go Key -> a -> Maybe a
f Word64Map a
l) Word64Map a
r
Word64Map a
_ -> (Key -> a -> Maybe a) -> Word64Map a -> Word64Map a
forall a. (Key -> a -> Maybe a) -> Word64Map a -> Word64Map a
go Key -> a -> Maybe a
f Word64Map a
t
where
go :: (Key -> t -> Maybe t) -> Word64Map t -> Word64Map t
go Key -> t -> Maybe t
f' (Bin Key
p Key
m Word64Map t
l Word64Map t
r) = Key -> Key -> Word64Map t -> Word64Map t -> Word64Map t
forall a. Key -> Key -> Word64Map a -> Word64Map a -> Word64Map a
binCheckRight Key
p Key
m Word64Map t
l ((Key -> t -> Maybe t) -> Word64Map t -> Word64Map t
go Key -> t -> Maybe t
f' Word64Map t
r)
go Key -> t -> Maybe t
f' (Tip Key
k t
y) = case Key -> t -> Maybe t
f' Key
k t
y of
Just !t
y' -> Key -> t -> Word64Map t
forall a. Key -> a -> Word64Map a
Tip Key
k t
y'
Maybe t
Nothing -> Word64Map t
forall a. Word64Map a
Nil
go Key -> t -> Maybe t
_ Word64Map t
Nil = [Char] -> Word64Map t
forall a. HasCallStack => [Char] -> a
error [Char]
"updateMaxWithKey Nil"
updateMax :: (a -> Maybe a) -> Word64Map a -> Word64Map a
updateMax :: forall a. (a -> Maybe a) -> Word64Map a -> Word64Map a
updateMax a -> Maybe a
f = (Key -> a -> Maybe a) -> Word64Map a -> Word64Map a
forall a. (Key -> a -> Maybe a) -> Word64Map a -> Word64Map a
updateMaxWithKey ((a -> Maybe a) -> Key -> 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 = (Key -> a -> Maybe a) -> Word64Map a -> Word64Map a
forall a. (Key -> a -> Maybe a) -> Word64Map a -> Word64Map a
updateMinWithKey ((a -> Maybe a) -> Key -> a -> Maybe a
forall a b. a -> b -> a
const a -> Maybe a
f)
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 Key
p Key
m Word64Map a
l Word64Map a
r) = Key -> Key -> Word64Map b -> Word64Map b -> Word64Map b
forall a. Key -> Key -> Word64Map a -> Word64Map a -> Word64Map a
Bin Key
p Key
m (Word64Map a -> Word64Map b
go Word64Map a
l) (Word64Map a -> Word64Map b
go Word64Map a
r)
go (Tip Key
k a
x) = Key -> b -> Word64Map b
forall a. Key -> a -> Word64Map a
Tip Key
k (b -> Word64Map b) -> b -> Word64Map b
forall a b. (a -> b) -> a -> b
$! a -> b
f a
x
go Word64Map a
Nil = Word64Map b
forall a. Word64Map a
Nil
#ifdef __GLASGOW_HASKELL__
{-# NOINLINE [1] map #-}
{-# RULES
"map/map" forall f g xs . map f (map g xs) = map (\x -> f $! g x) xs
"map/mapL" forall f g xs . map f (L.map g xs) = map (\x -> f (g x)) xs
#-}
#endif
mapWithKey :: (Key -> a -> b) -> Word64Map a -> Word64Map b
mapWithKey :: forall a b. (Key -> a -> b) -> Word64Map a -> Word64Map b
mapWithKey Key -> a -> b
f Word64Map a
t
= case Word64Map a
t of
Bin Key
p Key
m Word64Map a
l Word64Map a
r -> Key -> Key -> Word64Map b -> Word64Map b -> Word64Map b
forall a. Key -> Key -> Word64Map a -> Word64Map a -> Word64Map a
Bin Key
p Key
m ((Key -> a -> b) -> Word64Map a -> Word64Map b
forall a b. (Key -> a -> b) -> Word64Map a -> Word64Map b
mapWithKey Key -> a -> b
f Word64Map a
l) ((Key -> a -> b) -> Word64Map a -> Word64Map b
forall a b. (Key -> a -> b) -> Word64Map a -> Word64Map b
mapWithKey Key -> a -> b
f Word64Map a
r)
Tip Key
k a
x -> Key -> b -> Word64Map b
forall a. Key -> a -> Word64Map a
Tip Key
k (b -> Word64Map b) -> b -> Word64Map b
forall a b. (a -> b) -> a -> b
$! Key -> a -> b
f Key
k a
x
Word64Map a
Nil -> Word64Map b
forall a. Word64Map a
Nil
#ifdef __GLASGOW_HASKELL__
{-# 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/mapWithKeyL" forall f g xs . mapWithKey f (L.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
"mapWithKey/mapL" forall f g xs . mapWithKey f (L.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
"map/mapWithKeyL" forall f g xs . map f (L.mapWithKey g xs) =
mapWithKey (\k a -> f (g k a)) xs
#-}
#endif
traverseWithKey :: Applicative t => (Key -> a -> t b) -> Word64Map a -> t (Word64Map b)
traverseWithKey :: forall (t :: * -> *) a b.
Applicative t =>
(Key -> a -> t b) -> Word64Map a -> t (Word64Map b)
traverseWithKey Key -> 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 Key
k a
v) = (\ !b
v' -> Key -> b -> Word64Map b
forall a. Key -> a -> Word64Map a
Tip Key
k b
v') (b -> Word64Map b) -> t b -> t (Word64Map b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Key -> a -> t b
f Key
k a
v
go (Bin Key
p Key
m Word64Map a
l Word64Map a
r)
| Key
m Key -> Key -> Bool
forall a. Ord a => a -> a -> Bool
< Key
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 (Key -> Key -> Word64Map b -> Word64Map b -> Word64Map b
forall a. Key -> Key -> Word64Map a -> Word64Map a -> Word64Map a
Bin Key
p Key
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 (Key -> Key -> Word64Map b -> Word64Map b -> Word64Map b
forall a. Key -> Key -> Word64Map a -> Word64Map a -> Word64Map a
Bin Key
p Key
m) (Word64Map a -> t (Word64Map b)
go Word64Map a
l) (Word64Map a -> t (Word64Map b)
go Word64Map a
r)
{-# INLINE traverseWithKey #-}
traverseMaybeWithKey
:: Applicative f => (Key -> a -> f (Maybe b)) -> Word64Map a -> f (Word64Map b)
traverseMaybeWithKey :: forall (f :: * -> *) a b.
Applicative f =>
(Key -> a -> f (Maybe b)) -> Word64Map a -> f (Word64Map b)
traverseMaybeWithKey Key -> 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 Key
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 (Key -> b -> Word64Map b
forall a. Key -> a -> Word64Map a
Tip Key
k $!) (Maybe b -> Word64Map b) -> f (Maybe b) -> f (Word64Map b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Key -> a -> f (Maybe b)
f Key
k a
x
go (Bin Key
p Key
m Word64Map a
l Word64Map a
r)
| Key
m Key -> Key -> Bool
forall a. Ord a => a -> a -> Bool
< Key
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 (Key -> Key -> Word64Map b -> Word64Map b -> Word64Map b
forall a. Key -> Key -> Word64Map a -> Word64Map a -> Word64Map a
bin Key
p Key
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 (Key -> Key -> Word64Map b -> Word64Map b -> Word64Map b
forall a. Key -> Key -> Word64Map a -> Word64Map a -> Word64Map a
bin Key
p Key
m) (Word64Map a -> f (Word64Map b)
go Word64Map a
l) (Word64Map a -> f (Word64Map b)
go Word64Map a
r)
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 -> Key -> b -> (a, c)) -> a -> Word64Map b -> (a, Word64Map c)
forall a b c.
(a -> Key -> b -> (a, c)) -> a -> Word64Map b -> (a, Word64Map c)
mapAccumWithKey (\a
a' Key
_ 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 -> Key -> b -> (a, c)) -> a -> Word64Map b -> (a, Word64Map c)
mapAccumWithKey a -> Key -> b -> (a, c)
f a
a Word64Map b
t
= (a -> Key -> b -> (a, c)) -> a -> Word64Map b -> (a, Word64Map c)
forall a b c.
(a -> Key -> b -> (a, c)) -> a -> Word64Map b -> (a, Word64Map c)
mapAccumL a -> Key -> 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 -> Key -> b -> (a, c)) -> a -> Word64Map b -> (a, Word64Map c)
mapAccumL a -> Key -> b -> (a, c)
f0 a
a0 Word64Map b
t0 = StrictPair a (Word64Map c) -> (a, Word64Map c)
forall a b. StrictPair a b -> (a, b)
toPair (StrictPair a (Word64Map c) -> (a, Word64Map c))
-> StrictPair a (Word64Map c) -> (a, Word64Map c)
forall a b. (a -> b) -> a -> b
$ (a -> Key -> b -> (a, c))
-> a -> Word64Map b -> StrictPair a (Word64Map c)
forall {t} {t} {a}.
(t -> Key -> t -> (t, a))
-> t -> Word64Map t -> StrictPair t (Word64Map a)
go a -> Key -> b -> (a, c)
f0 a
a0 Word64Map b
t0
where
go :: (t -> Key -> t -> (t, a))
-> t -> Word64Map t -> StrictPair t (Word64Map a)
go t -> Key -> t -> (t, a)
f t
a Word64Map t
t
= case Word64Map t
t of
Bin Key
p Key
m Word64Map t
l Word64Map t
r
| Key
m Key -> Key -> Bool
forall a. Ord a => a -> a -> Bool
< Key
0 ->
let (t
a1 :*: Word64Map a
r') = (t -> Key -> t -> (t, a))
-> t -> Word64Map t -> StrictPair t (Word64Map a)
go t -> Key -> t -> (t, a)
f t
a Word64Map t
r
(t
a2 :*: Word64Map a
l') = (t -> Key -> t -> (t, a))
-> t -> Word64Map t -> StrictPair t (Word64Map a)
go t -> Key -> t -> (t, a)
f t
a1 Word64Map t
l
in (t
a2 t -> Word64Map a -> StrictPair t (Word64Map a)
forall a b. a -> b -> StrictPair a b
:*: Key -> Key -> Word64Map a -> Word64Map a -> Word64Map a
forall a. Key -> Key -> Word64Map a -> Word64Map a -> Word64Map a
Bin Key
p Key
m Word64Map a
l' Word64Map a
r')
| Bool
otherwise ->
let (t
a1 :*: Word64Map a
l') = (t -> Key -> t -> (t, a))
-> t -> Word64Map t -> StrictPair t (Word64Map a)
go t -> Key -> t -> (t, a)
f t
a Word64Map t
l
(t
a2 :*: Word64Map a
r') = (t -> Key -> t -> (t, a))
-> t -> Word64Map t -> StrictPair t (Word64Map a)
go t -> Key -> t -> (t, a)
f t
a1 Word64Map t
r
in (t
a2 t -> Word64Map a -> StrictPair t (Word64Map a)
forall a b. a -> b -> StrictPair a b
:*: Key -> Key -> Word64Map a -> Word64Map a -> Word64Map a
forall a. Key -> Key -> Word64Map a -> Word64Map a -> Word64Map a
Bin Key
p Key
m Word64Map a
l' Word64Map a
r')
Tip Key
k t
x -> let !(t
a',!a
x') = t -> Key -> t -> (t, a)
f t
a Key
k t
x in (t
a' t -> Word64Map a -> StrictPair t (Word64Map a)
forall a b. a -> b -> StrictPair a b
:*: Key -> a -> Word64Map a
forall a. Key -> a -> Word64Map a
Tip Key
k a
x')
Word64Map t
Nil -> (t
a t -> Word64Map a -> StrictPair t (Word64Map a)
forall a b. a -> b -> StrictPair a b
:*: Word64Map a
forall a. Word64Map a
Nil)
mapAccumRWithKey :: (a -> Key -> b -> (a,c)) -> a -> Word64Map b -> (a,Word64Map c)
mapAccumRWithKey :: forall a b c.
(a -> Key -> b -> (a, c)) -> a -> Word64Map b -> (a, Word64Map c)
mapAccumRWithKey a -> Key -> b -> (a, c)
f0 a
a0 Word64Map b
t0 = StrictPair a (Word64Map c) -> (a, Word64Map c)
forall a b. StrictPair a b -> (a, b)
toPair (StrictPair a (Word64Map c) -> (a, Word64Map c))
-> StrictPair a (Word64Map c) -> (a, Word64Map c)
forall a b. (a -> b) -> a -> b
$ (a -> Key -> b -> (a, c))
-> a -> Word64Map b -> StrictPair a (Word64Map c)
forall {t} {t} {a}.
(t -> Key -> t -> (t, a))
-> t -> Word64Map t -> StrictPair t (Word64Map a)
go a -> Key -> b -> (a, c)
f0 a
a0 Word64Map b
t0
where
go :: (t -> Key -> t -> (t, a))
-> t -> Word64Map t -> StrictPair t (Word64Map a)
go t -> Key -> t -> (t, a)
f t
a Word64Map t
t
= case Word64Map t
t of
Bin Key
p Key
m Word64Map t
l Word64Map t
r
| Key
m Key -> Key -> Bool
forall a. Ord a => a -> a -> Bool
< Key
0 ->
let (t
a1 :*: Word64Map a
l') = (t -> Key -> t -> (t, a))
-> t -> Word64Map t -> StrictPair t (Word64Map a)
go t -> Key -> t -> (t, a)
f t
a Word64Map t
l
(t
a2 :*: Word64Map a
r') = (t -> Key -> t -> (t, a))
-> t -> Word64Map t -> StrictPair t (Word64Map a)
go t -> Key -> t -> (t, a)
f t
a1 Word64Map t
r
in (t
a2 t -> Word64Map a -> StrictPair t (Word64Map a)
forall a b. a -> b -> StrictPair a b
:*: Key -> Key -> Word64Map a -> Word64Map a -> Word64Map a
forall a. Key -> Key -> Word64Map a -> Word64Map a -> Word64Map a
Bin Key
p Key
m Word64Map a
l' Word64Map a
r')
| Bool
otherwise ->
let (t
a1 :*: Word64Map a
r') = (t -> Key -> t -> (t, a))
-> t -> Word64Map t -> StrictPair t (Word64Map a)
go t -> Key -> t -> (t, a)
f t
a Word64Map t
r
(t
a2 :*: Word64Map a
l') = (t -> Key -> t -> (t, a))
-> t -> Word64Map t -> StrictPair t (Word64Map a)
go t -> Key -> t -> (t, a)
f t
a1 Word64Map t
l
in (t
a2 t -> Word64Map a -> StrictPair t (Word64Map a)
forall a b. a -> b -> StrictPair a b
:*: Key -> Key -> Word64Map a -> Word64Map a -> Word64Map a
forall a. Key -> Key -> Word64Map a -> Word64Map a -> Word64Map a
Bin Key
p Key
m Word64Map a
l' Word64Map a
r')
Tip Key
k t
x -> let !(t
a',!a
x') = t -> Key -> t -> (t, a)
f t
a Key
k t
x in (t
a' t -> Word64Map a -> StrictPair t (Word64Map a)
forall a b. a -> b -> StrictPair a b
:*: Key -> a -> Word64Map a
forall a. Key -> a -> Word64Map a
Tip Key
k a
x')
Word64Map t
Nil -> (t
a t -> Word64Map a -> StrictPair t (Word64Map a)
forall a b. a -> b -> StrictPair a b
:*: Word64Map a
forall a. Word64Map a
Nil)
mapKeysWith :: (a -> a -> a) -> (Key->Key) -> Word64Map a -> Word64Map a
mapKeysWith :: forall a.
(a -> a -> a) -> (Key -> Key) -> Word64Map a -> Word64Map a
mapKeysWith a -> a -> a
c Key -> Key
f = (a -> a -> a) -> [(Key, a)] -> Word64Map a
forall a. (a -> a -> a) -> [(Key, a)] -> Word64Map a
fromListWith a -> a -> a
c ([(Key, a)] -> Word64Map a)
-> (Word64Map a -> [(Key, a)]) -> Word64Map a -> Word64Map a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Key -> a -> [(Key, a)] -> [(Key, a)])
-> [(Key, a)] -> Word64Map a -> [(Key, a)]
forall a b. (Key -> a -> b -> b) -> b -> Word64Map a -> b
foldrWithKey (\Key
k a
x [(Key, a)]
xs -> (Key -> Key
f Key
k, a
x) (Key, a) -> [(Key, a)] -> [(Key, a)]
forall a. a -> [a] -> [a]
: [(Key, a)]
xs) []
mapMaybe :: (a -> Maybe b) -> Word64Map a -> Word64Map b
mapMaybe :: forall a b. (a -> Maybe b) -> Word64Map a -> Word64Map b
mapMaybe a -> Maybe b
f = (Key -> a -> Maybe b) -> Word64Map a -> Word64Map b
forall a b. (Key -> a -> Maybe b) -> Word64Map a -> Word64Map b
mapMaybeWithKey (\Key
_ a
x -> a -> Maybe b
f a
x)
mapMaybeWithKey :: (Key -> a -> Maybe b) -> Word64Map a -> Word64Map b
mapMaybeWithKey :: forall a b. (Key -> a -> Maybe b) -> Word64Map a -> Word64Map b
mapMaybeWithKey Key -> a -> Maybe b
f (Bin Key
p Key
m Word64Map a
l Word64Map a
r)
= Key -> Key -> Word64Map b -> Word64Map b -> Word64Map b
forall a. Key -> Key -> Word64Map a -> Word64Map a -> Word64Map a
bin Key
p Key
m ((Key -> a -> Maybe b) -> Word64Map a -> Word64Map b
forall a b. (Key -> a -> Maybe b) -> Word64Map a -> Word64Map b
mapMaybeWithKey Key -> a -> Maybe b
f Word64Map a
l) ((Key -> a -> Maybe b) -> Word64Map a -> Word64Map b
forall a b. (Key -> a -> Maybe b) -> Word64Map a -> Word64Map b
mapMaybeWithKey Key -> a -> Maybe b
f Word64Map a
r)
mapMaybeWithKey Key -> a -> Maybe b
f (Tip Key
k a
x) = case Key -> a -> Maybe b
f Key
k a
x of
Just !b
y -> Key -> b -> Word64Map b
forall a. Key -> a -> Word64Map a
Tip Key
k b
y
Maybe b
Nothing -> Word64Map b
forall a. Word64Map a
Nil
mapMaybeWithKey Key -> 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
= (Key -> a -> Either b c)
-> Word64Map a -> (Word64Map b, Word64Map c)
forall a b c.
(Key -> a -> Either b c)
-> Word64Map a -> (Word64Map b, Word64Map c)
mapEitherWithKey (\Key
_ 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.
(Key -> a -> Either b c)
-> Word64Map a -> (Word64Map b, Word64Map c)
mapEitherWithKey Key -> 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
$ (Key -> a -> Either b c)
-> Word64Map a -> StrictPair (Word64Map b) (Word64Map c)
forall {t} {a} {a}.
(Key -> t -> Either a a)
-> Word64Map t -> StrictPair (Word64Map a) (Word64Map a)
go Key -> a -> Either b c
f0 Word64Map a
t0
where
go :: (Key -> t -> Either a a)
-> Word64Map t -> StrictPair (Word64Map a) (Word64Map a)
go Key -> t -> Either a a
f (Bin Key
p Key
m Word64Map t
l Word64Map t
r)
= Key -> Key -> Word64Map a -> Word64Map a -> Word64Map a
forall a. Key -> Key -> Word64Map a -> Word64Map a -> Word64Map a
bin Key
p Key
m Word64Map a
l1 Word64Map a
r1 Word64Map a
-> Word64Map a -> StrictPair (Word64Map a) (Word64Map a)
forall a b. a -> b -> StrictPair a b
:*: Key -> Key -> Word64Map a -> Word64Map a -> Word64Map a
forall a. Key -> Key -> Word64Map a -> Word64Map a -> Word64Map a
bin Key
p Key
m Word64Map a
l2 Word64Map a
r2
where
(Word64Map a
l1 :*: Word64Map a
l2) = (Key -> t -> Either a a)
-> Word64Map t -> StrictPair (Word64Map a) (Word64Map a)
go Key -> t -> Either a a
f Word64Map t
l
(Word64Map a
r1 :*: Word64Map a
r2) = (Key -> t -> Either a a)
-> Word64Map t -> StrictPair (Word64Map a) (Word64Map a)
go Key -> t -> Either a a
f Word64Map t
r
go Key -> t -> Either a a
f (Tip Key
k t
x) = case Key -> t -> Either a a
f Key
k t
x of
Left !a
y -> (Key -> a -> Word64Map a
forall a. Key -> a -> Word64Map a
Tip Key
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
:*: Key -> a -> Word64Map a
forall a. Key -> a -> Word64Map a
Tip Key
k a
z)
go Key -> 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)
fromSet :: (Key -> a) -> Word64Set.Word64Set -> Word64Map a
fromSet :: forall a. (Key -> a) -> Word64Set -> Word64Map a
fromSet Key -> a
_ Word64Set
Word64Set.Nil = Word64Map a
forall a. Word64Map a
Nil
fromSet Key -> a
f (Word64Set.Bin Key
p Key
m Word64Set
l Word64Set
r) = Key -> Key -> Word64Map a -> Word64Map a -> Word64Map a
forall a. Key -> Key -> Word64Map a -> Word64Map a -> Word64Map a
Bin Key
p Key
m ((Key -> a) -> Word64Set -> Word64Map a
forall a. (Key -> a) -> Word64Set -> Word64Map a
fromSet Key -> a
f Word64Set
l) ((Key -> a) -> Word64Set -> Word64Map a
forall a. (Key -> a) -> Word64Set -> Word64Map a
fromSet Key -> a
f Word64Set
r)
fromSet Key -> a
f (Word64Set.Tip Key
kx Key
bm) = (Key -> a) -> Key -> Key -> Key -> Word64Map a
forall {a}. (Key -> a) -> Key -> Key -> Key -> Word64Map a
buildTree Key -> a
f Key
kx Key
bm (Key
Word64Set.suffixBitMask Key -> Key -> Key
forall a. Num a => a -> a -> a
+ Key
1)
where
buildTree :: (Key -> a) -> Key -> Key -> Key -> Word64Map a
buildTree Key -> a
g !Key
prefix !Key
bmask Key
bits = case Key
bits of
Key
0 -> Key -> a -> Word64Map a
forall a. Key -> a -> Word64Map a
Tip Key
prefix (a -> Word64Map a) -> a -> Word64Map a
forall a b. (a -> b) -> a -> b
$! Key -> a
g Key
prefix
Key
_ -> case Key -> Key
intFromNat ((Key -> Key
natFromInt Key
bits) Key -> Int -> Key
`shiftRL` Int
1) of
Key
bits2 | Key
bmask Key -> Key -> Key
forall a. Bits a => a -> a -> a
.&. ((Key
1 Key -> Int -> Key
`shiftLL` Key -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Key
bits2) Key -> Key -> Key
forall a. Num a => a -> a -> a
- Key
1) Key -> Key -> Bool
forall a. Eq a => a -> a -> Bool
== Key
0 ->
(Key -> a) -> Key -> Key -> Key -> Word64Map a
buildTree Key -> a
g (Key
prefix Key -> Key -> Key
forall a. Num a => a -> a -> a
+ Key
bits2) (Key
bmask Key -> Int -> Key
`shiftRL` Key -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Key
bits2) Key
bits2
| (Key
bmask Key -> Int -> Key
`shiftRL` Key -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Key
bits2) Key -> Key -> Key
forall a. Bits a => a -> a -> a
.&. ((Key
1 Key -> Int -> Key
`shiftLL` Key -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Key
bits2) Key -> Key -> Key
forall a. Num a => a -> a -> a
- Key
1) Key -> Key -> Bool
forall a. Eq a => a -> a -> Bool
== Key
0 ->
(Key -> a) -> Key -> Key -> Key -> Word64Map a
buildTree Key -> a
g Key
prefix Key
bmask Key
bits2
| Bool
otherwise ->
Key -> Key -> Word64Map a -> Word64Map a -> Word64Map a
forall a. Key -> Key -> Word64Map a -> Word64Map a -> Word64Map a
Bin Key
prefix Key
bits2 ((Key -> a) -> Key -> Key -> Key -> Word64Map a
buildTree Key -> a
g Key
prefix Key
bmask Key
bits2) ((Key -> a) -> Key -> Key -> Key -> Word64Map a
buildTree Key -> a
g (Key
prefix Key -> Key -> Key
forall a. Num a => a -> a -> a
+ Key
bits2) (Key
bmask Key -> Int -> Key
`shiftRL` Key -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Key
bits2) Key
bits2)
fromList :: [(Key,a)] -> Word64Map a
fromList :: forall a. [(Key, a)] -> Word64Map a
fromList [(Key, a)]
xs
= (Word64Map a -> (Key, a) -> Word64Map a)
-> Word64Map a -> [(Key, 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 -> (Key, a) -> Word64Map a
forall {a}. Word64Map a -> (Key, a) -> Word64Map a
ins Word64Map a
forall a. Word64Map a
empty [(Key, a)]
xs
where
ins :: Word64Map a -> (Key, a) -> Word64Map a
ins Word64Map a
t (Key
k,a
x) = Key -> a -> Word64Map a -> Word64Map a
forall a. Key -> a -> Word64Map a -> Word64Map a
insert Key
k a
x Word64Map a
t
fromListWith :: (a -> a -> a) -> [(Key,a)] -> Word64Map a
fromListWith :: forall a. (a -> a -> a) -> [(Key, a)] -> Word64Map a
fromListWith a -> a -> a
f [(Key, a)]
xs
= (Key -> a -> a -> a) -> [(Key, a)] -> Word64Map a
forall a. (Key -> a -> a -> a) -> [(Key, a)] -> Word64Map a
fromListWithKey (\Key
_ a
x a
y -> a -> a -> a
f a
x a
y) [(Key, a)]
xs
fromListWithKey :: (Key -> a -> a -> a) -> [(Key,a)] -> Word64Map a
fromListWithKey :: forall a. (Key -> a -> a -> a) -> [(Key, a)] -> Word64Map a
fromListWithKey Key -> a -> a -> a
f [(Key, a)]
xs
= (Word64Map a -> (Key, a) -> Word64Map a)
-> Word64Map a -> [(Key, 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 -> (Key, a) -> Word64Map a
ins Word64Map a
forall a. Word64Map a
empty [(Key, a)]
xs
where
ins :: Word64Map a -> (Key, a) -> Word64Map a
ins Word64Map a
t (Key
k,a
x) = (Key -> a -> a -> a) -> Key -> a -> Word64Map a -> Word64Map a
forall a.
(Key -> a -> a -> a) -> Key -> a -> Word64Map a -> Word64Map a
insertWithKey Key -> a -> a -> a
f Key
k a
x Word64Map a
t
fromAscList :: [(Key,a)] -> Word64Map a
fromAscList :: forall a. [(Key, a)] -> Word64Map a
fromAscList = Distinct -> (Key -> a -> a -> a) -> [(Key, a)] -> Word64Map a
forall a.
Distinct -> (Key -> a -> a -> a) -> [(Key, a)] -> Word64Map a
fromMonoListWithKey Distinct
Nondistinct (\Key
_ a
x a
_ -> a
x)
{-# NOINLINE fromAscList #-}
fromAscListWith :: (a -> a -> a) -> [(Key,a)] -> Word64Map a
fromAscListWith :: forall a. (a -> a -> a) -> [(Key, a)] -> Word64Map a
fromAscListWith a -> a -> a
f = Distinct -> (Key -> a -> a -> a) -> [(Key, a)] -> Word64Map a
forall a.
Distinct -> (Key -> a -> a -> a) -> [(Key, a)] -> Word64Map a
fromMonoListWithKey Distinct
Nondistinct (\Key
_ 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. (Key -> a -> a -> a) -> [(Key, a)] -> Word64Map a
fromAscListWithKey Key -> a -> a -> a
f = Distinct -> (Key -> a -> a -> a) -> [(Key, a)] -> Word64Map a
forall a.
Distinct -> (Key -> a -> a -> a) -> [(Key, a)] -> Word64Map a
fromMonoListWithKey Distinct
Nondistinct Key -> a -> a -> a
f
{-# NOINLINE fromAscListWithKey #-}
fromDistinctAscList :: [(Key,a)] -> Word64Map a
fromDistinctAscList :: forall a. [(Key, a)] -> Word64Map a
fromDistinctAscList = Distinct -> (Key -> a -> a -> a) -> [(Key, a)] -> Word64Map a
forall a.
Distinct -> (Key -> a -> a -> a) -> [(Key, a)] -> Word64Map a
fromMonoListWithKey Distinct
Distinct (\Key
_ a
x a
_ -> a
x)
{-# NOINLINE fromDistinctAscList #-}
fromMonoListWithKey :: Distinct -> (Key -> a -> a -> a) -> [(Key,a)] -> Word64Map a
fromMonoListWithKey :: forall a.
Distinct -> (Key -> a -> a -> a) -> [(Key, a)] -> Word64Map a
fromMonoListWithKey Distinct
distinct Key -> a -> a -> a
f = [(Key, a)] -> Word64Map a
go
where
go :: [(Key, a)] -> Word64Map a
go [] = Word64Map a
forall a. Word64Map a
Nil
go ((Key
kx,a
vx) : [(Key, a)]
zs1) = Key -> a -> [(Key, a)] -> Word64Map a
addAll' Key
kx a
vx [(Key, a)]
zs1
addAll' :: Key -> a -> [(Key, a)] -> Word64Map a
addAll' !Key
kx a
vx []
= Key -> a -> Word64Map a
forall a. Key -> a -> Word64Map a
Tip Key
kx (a -> Word64Map a) -> a -> Word64Map a
forall a b. (a -> b) -> a -> b
$! a
vx
addAll' !Key
kx a
vx ((Key
ky,a
vy) : [(Key, a)]
zs)
| Distinct
Nondistinct <- Distinct
distinct, Key
kx Key -> Key -> Bool
forall a. Eq a => a -> a -> Bool
== Key
ky
= let !v :: a
v = Key -> a -> a -> a
f Key
kx a
vy a
vx in Key -> a -> [(Key, a)] -> Word64Map a
addAll' Key
ky a
v [(Key, a)]
zs
| Key
m <- Key -> Key -> Key
branchMask Key
kx Key
ky
, Inserted Word64Map a
ty [(Key, a)]
zs' <- Key -> Key -> a -> [(Key, a)] -> Inserted a
addMany' Key
m Key
ky a
vy [(Key, a)]
zs
= Key -> Word64Map a -> [(Key, a)] -> Word64Map a
addAll Key
kx (Key -> Key -> Word64Map a -> Word64Map a -> Word64Map a
forall a. Key -> Key -> Word64Map a -> Word64Map a -> Word64Map a
linkWithMask Key
m Key
ky Word64Map a
ty (Key -> a -> Word64Map a
forall a. Key -> a -> Word64Map a
Tip Key
kx (a -> Word64Map a) -> a -> Word64Map a
forall a b. (a -> b) -> a -> b
$! a
vx)) [(Key, a)]
zs'
addAll :: Key -> Word64Map a -> [(Key, a)] -> Word64Map a
addAll !Key
_kx !Word64Map a
tx []
= Word64Map a
tx
addAll !Key
kx !Word64Map a
tx ((Key
ky,a
vy) : [(Key, a)]
zs)
| Key
m <- Key -> Key -> Key
branchMask Key
kx Key
ky
, Inserted Word64Map a
ty [(Key, a)]
zs' <- Key -> Key -> a -> [(Key, a)] -> Inserted a
addMany' Key
m Key
ky a
vy [(Key, a)]
zs
= Key -> Word64Map a -> [(Key, a)] -> Word64Map a
addAll Key
kx (Key -> Key -> Word64Map a -> Word64Map a -> Word64Map a
forall a. Key -> Key -> Word64Map a -> Word64Map a -> Word64Map a
linkWithMask Key
m Key
ky Word64Map a
ty Word64Map a
tx) [(Key, a)]
zs'
addMany' :: Key -> Key -> a -> [(Key, a)] -> Inserted a
addMany' !Key
_m !Key
kx a
vx []
= Word64Map a -> [(Key, a)] -> Inserted a
forall a. Word64Map a -> [(Key, a)] -> Inserted a
Inserted (Key -> a -> Word64Map a
forall a. Key -> a -> Word64Map a
Tip Key
kx (a -> Word64Map a) -> a -> Word64Map a
forall a b. (a -> b) -> a -> b
$! a
vx) []
addMany' !Key
m !Key
kx a
vx zs0 :: [(Key, a)]
zs0@((Key
ky,a
vy) : [(Key, a)]
zs)
| Distinct
Nondistinct <- Distinct
distinct, Key
kx Key -> Key -> Bool
forall a. Eq a => a -> a -> Bool
== Key
ky
= let !v :: a
v = Key -> a -> a -> a
f Key
kx a
vy a
vx in Key -> Key -> a -> [(Key, a)] -> Inserted a
addMany' Key
m Key
ky a
v [(Key, a)]
zs
| Key -> Key -> Key
mask Key
kx Key
m Key -> Key -> Bool
forall a. Eq a => a -> a -> Bool
/= Key -> Key -> Key
mask Key
ky Key
m
= Word64Map a -> [(Key, a)] -> Inserted a
forall a. Word64Map a -> [(Key, a)] -> Inserted a
Inserted (Key -> a -> Word64Map a
forall a. Key -> a -> Word64Map a
Tip Key
kx (a -> Word64Map a) -> a -> Word64Map a
forall a b. (a -> b) -> a -> b
$! a
vx) [(Key, a)]
zs0
| Key
mxy <- Key -> Key -> Key
branchMask Key
kx Key
ky
, Inserted Word64Map a
ty [(Key, a)]
zs' <- Key -> Key -> a -> [(Key, a)] -> Inserted a
addMany' Key
mxy Key
ky a
vy [(Key, a)]
zs
= Key -> Key -> Word64Map a -> [(Key, a)] -> Inserted a
addMany Key
m Key
kx (Key -> Key -> Word64Map a -> Word64Map a -> Word64Map a
forall a. Key -> Key -> Word64Map a -> Word64Map a -> Word64Map a
linkWithMask Key
mxy Key
ky Word64Map a
ty (Key -> a -> Word64Map a
forall a. Key -> a -> Word64Map a
Tip Key
kx (a -> Word64Map a) -> a -> Word64Map a
forall a b. (a -> b) -> a -> b
$! a
vx)) [(Key, a)]
zs'
addMany :: Key -> Key -> Word64Map a -> [(Key, a)] -> Inserted a
addMany !Key
_m !Key
_kx Word64Map a
tx []
= Word64Map a -> [(Key, a)] -> Inserted a
forall a. Word64Map a -> [(Key, a)] -> Inserted a
Inserted Word64Map a
tx []
addMany !Key
m !Key
kx Word64Map a
tx zs0 :: [(Key, a)]
zs0@((Key
ky,a
vy) : [(Key, a)]
zs)
| Key -> Key -> Key
mask Key
kx Key
m Key -> Key -> Bool
forall a. Eq a => a -> a -> Bool
/= Key -> Key -> Key
mask Key
ky Key
m
= Word64Map a -> [(Key, a)] -> Inserted a
forall a. Word64Map a -> [(Key, a)] -> Inserted a
Inserted Word64Map a
tx [(Key, a)]
zs0
| Key
mxy <- Key -> Key -> Key
branchMask Key
kx Key
ky
, Inserted Word64Map a
ty [(Key, a)]
zs' <- Key -> Key -> a -> [(Key, a)] -> Inserted a
addMany' Key
mxy Key
ky a
vy [(Key, a)]
zs
= Key -> Key -> Word64Map a -> [(Key, a)] -> Inserted a
addMany Key
m Key
kx (Key -> Key -> Word64Map a -> Word64Map a -> Word64Map a
forall a. Key -> Key -> Word64Map a -> Word64Map a -> Word64Map a
linkWithMask Key
mxy Key
ky Word64Map a
ty Word64Map a
tx) [(Key, a)]
zs'
{-# INLINE fromMonoListWithKey #-}
data Inserted a = Inserted !(Word64Map a) ![(Key,a)]
data Distinct = Distinct | Nondistinct