{-# LANGUAGE BangPatterns
, GADTs
, RankNTypes
, ScopedTypeVariables
, UnboxedTuples #-}
module Data.RadixNTree.Word8.Lazy
( LazyRadixTree
, RadixTree (..)
, LazyRadix1Tree
, Radix1Tree (..)
, empty0
, empty1
, singleton0
, singleton1
, map0
, mapWithKey0
, map1
, mapWithKey1
, foldl0
, foldl0'
, foldlWithKey0
, foldlWithKey0'
, Data.RadixNTree.Word8.Lazy.foldl1
, foldl1'
, foldlWithKey1
, foldlWithKey1'
, foldr0
, foldr0'
, foldrWithKey0
, foldrWithKey0'
, Data.RadixNTree.Word8.Lazy.foldr1
, foldr1'
, foldrWithKey1
, foldrWithKey1'
, foldMap0
, foldMapWithKey0
, foldMap1
, foldMapWithKey1
, traverse0
, traverseWithKey0
, traverse1
, traverseWithKey1
, null0
, null1
, size0
, size1
, lookup0
, find0
, member0
, subtree0
, prefix0
, lookup1
, find1
, member1
, subtree1
, prefix1
, Point (..)
, Cursor (..)
, stop
, Location (..)
, locate
, cursor0
, move0
, cursor1
, move1
, lookupL0
, lookupL1
, lookupR0
, lookupR1
, adjustL0
, adjustLWithKey0
, adjustL1
, adjustLWithKey1
, adjustR0
, adjustRWithKey0
, adjustR1
, adjustRWithKey1
, updateL0
, updateLWithKey0
, updateL1
, updateLWithKey1
, updateR0
, updateRWithKey0
, updateR1
, updateRWithKey1
, takeL0
, takeL1
, takeR0
, takeR1
, union0
, union1
, unionL0
, unionL1
, unionWith0
, unionWith1
, unionWithKey0
, unionWithKey1
, difference0
, difference1
, differenceWith0
, differenceWith1
, differenceWithKey0
, differenceWithKey1
, compare0
, Data.RadixNTree.Word8.Lazy.compare1
, disjoint0
, disjoint1
, intersection0
, intersection1
, intersectionL0
, intersectionL1
, intersectionWith0
, intersectionWith1
, intersectionWithKey0
, intersectionWithKey1
, merge0
, merge1
, insert0
, insert1
, insertWith0
, insertWith1
, adjust0
, adjust1
, delete0
, delete1
, prune0
, prune1
, update0
, update1
, alter0
, alter1
, shape0
, shape1
, splitL0
, splitL1
, splitLookup0
, splitLookup1
, filter0
, filterWithKey0
, filter1
, filterWithKey1
, mapMaybe0
, mapMaybeWithKey0
, mapMaybe1
, mapMaybeWithKey1
, partition0
, partitionWithKey0
, partition1
, partitionWithKey1
, mapEither0
, mapEitherWithKey0
, mapEither1
, mapEitherWithKey1
, lookupMin0
, lookupMin1
, unsafeLookupMin1
, lookupMinWithKey0
, lookupMinWithKey1
, unsafeLookupMinWithKey1
, lookupMax0
, lookupMax1
, unsafeLookupMax1
, lookupMaxWithKey0
, lookupMaxWithKey1
, unsafeLookupMaxWithKey1
, deleteMin0
, deleteMin1
, unsafeDeleteMin1
, deleteMax0
, deleteMax1
, unsafeDeleteMax1
, adjustMin0
, adjustMin1
, unsafeAdjustMin1
, adjustMinWithKey0
, adjustMinWithKey1
, unsafeAdjustMinWithKey1
, adjustMax0
, adjustMax1
, unsafeAdjustMax1
, adjustMaxWithKey0
, adjustMaxWithKey1
, unsafeAdjustMaxWithKey1
, updateMin0
, updateMin1
, unsafeUpdateMin1
, updateMinWithKey0
, updateMinWithKey1
, unsafeUpdateMinWithKey1
, updateMax0
, updateMax1
, unsafeUpdateMax1
, updateMaxWithKey0
, updateMaxWithKey1
, unsafeUpdateMaxWithKey1
, ViewL (..)
, ViewL1 (..)
, minView0
, minView1
, unsafeMinView1
, ViewR (..)
, ViewR1 (..)
, maxView0
, maxView1
, unsafeMaxView1
) where
import Data.ByteArray.NonEmpty
import Data.RadixNTree.Word8.Common
import Data.RadixNTree.Word8.Key
import Radix.Common
import Radix.Exception
import Radix.Word8.Common
import Radix.Word8.Foundation
import Control.Applicative
import Control.Exception (throw)
import Control.DeepSeq
import Data.Bits
import Data.Foldable
import Data.Functor.Classes
import Data.Primitive.ByteArray
import Data.Word
import Text.Show
type LazyRadixTree = RadixTree
data RadixTree a = RadixTree
{-# UNPACK #-} !(Maybe a)
(Radix1Tree a)
instance Show a => Show (RadixTree a) where
showsPrec :: Int -> RadixTree a -> ShowS
showsPrec = (Int -> a -> ShowS)
-> ([a] -> ShowS) -> Int -> RadixTree a -> ShowS
forall a.
(Int -> a -> ShowS)
-> ([a] -> ShowS) -> Int -> RadixTree a -> ShowS
forall (f :: * -> *) a.
Show1 f =>
(Int -> a -> ShowS) -> ([a] -> ShowS) -> Int -> f a -> ShowS
liftShowsPrec Int -> a -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec [a] -> ShowS
forall a. Show a => [a] -> ShowS
showList
instance Show1 RadixTree where
liftShowsPrec :: forall a.
(Int -> a -> ShowS)
-> ([a] -> ShowS) -> Int -> RadixTree a -> ShowS
liftShowsPrec Int -> a -> ShowS
showsPrec_ [a] -> ShowS
showList_ Int
d RadixTree a
t =
Bool -> ShowS -> ShowS
showParen (Int
d Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
10) (ShowS -> ShowS) -> ShowS -> ShowS
forall a b. (a -> b) -> a -> b
$
((Build, a) -> ShowS) -> [(Build, a)] -> ShowS
forall a. (a -> ShowS) -> [a] -> ShowS
showListWith ((Int -> a -> ShowS) -> ([a] -> ShowS) -> Int -> (Build, a) -> ShowS
forall a.
(Int -> a -> ShowS) -> ([a] -> ShowS) -> Int -> (Build, a) -> ShowS
forall (f :: * -> *) a.
Show1 f =>
(Int -> a -> ShowS) -> ([a] -> ShowS) -> Int -> f a -> ShowS
liftShowsPrec Int -> a -> ShowS
showsPrec_ [a] -> ShowS
showList_ Int
0) ([(Build, a)] -> ShowS) -> [(Build, a)] -> ShowS
forall a b. (a -> b) -> a -> b
$
(Build -> a -> [(Build, a)] -> [(Build, a)])
-> [(Build, a)] -> RadixTree a -> [(Build, a)]
forall a b. (Build -> a -> b -> b) -> b -> RadixTree a -> b
foldrWithKey0 (\Build
k a
a -> (:) (Build
k, a
a)) [] RadixTree a
t
instance Eq a => Eq (RadixTree a) where
== :: RadixTree a -> RadixTree a -> Bool
(==) = (a -> a -> Bool) -> RadixTree a -> RadixTree a -> Bool
forall a b. (a -> b -> Bool) -> RadixTree a -> RadixTree b -> Bool
forall (f :: * -> *) a b.
Eq1 f =>
(a -> b -> Bool) -> f a -> f b -> Bool
liftEq a -> a -> Bool
forall a. Eq a => a -> a -> Bool
(==)
instance Eq1 RadixTree where
liftEq :: forall a b. (a -> b -> Bool) -> RadixTree a -> RadixTree b -> Bool
liftEq a -> b -> Bool
eq (RadixTree Maybe a
mx Radix1Tree a
l) (RadixTree Maybe b
my Radix1Tree b
r) = (a -> b -> Bool) -> Maybe a -> Maybe b -> Bool
forall a b. (a -> b -> Bool) -> Maybe a -> Maybe b -> Bool
forall (f :: * -> *) a b.
Eq1 f =>
(a -> b -> Bool) -> f a -> f b -> Bool
liftEq a -> b -> Bool
eq Maybe a
mx Maybe b
my Bool -> Bool -> Bool
&& (a -> b -> Bool) -> Radix1Tree a -> Radix1Tree b -> Bool
forall a b.
(a -> b -> Bool) -> Radix1Tree a -> Radix1Tree b -> Bool
forall (f :: * -> *) a b.
Eq1 f =>
(a -> b -> Bool) -> f a -> f b -> Bool
liftEq a -> b -> Bool
eq Radix1Tree a
l Radix1Tree b
r
instance Functor RadixTree where
fmap :: forall a b. (a -> b) -> RadixTree a -> RadixTree b
fmap = (a -> b) -> RadixTree a -> RadixTree b
forall a b. (a -> b) -> RadixTree a -> RadixTree b
map0
instance Foldable RadixTree where
foldl :: forall b a. (b -> a -> b) -> b -> RadixTree a -> b
foldl = (b -> a -> b) -> b -> RadixTree a -> b
forall b a. (b -> a -> b) -> b -> RadixTree a -> b
foldl0
foldr :: forall a b. (a -> b -> b) -> b -> RadixTree a -> b
foldr = (a -> b -> b) -> b -> RadixTree a -> b
forall a b. (a -> b -> b) -> b -> RadixTree a -> b
foldr0
foldMap :: forall m a. Monoid m => (a -> m) -> RadixTree a -> m
foldMap = (a -> m) -> RadixTree a -> m
forall m a. Monoid m => (a -> m) -> RadixTree a -> m
foldMap0
foldl' :: forall b a. (b -> a -> b) -> b -> RadixTree a -> b
foldl' = (b -> a -> b) -> b -> RadixTree a -> b
forall b a. (b -> a -> b) -> b -> RadixTree a -> b
foldl0'
foldr' :: forall a b. (a -> b -> b) -> b -> RadixTree a -> b
foldr' = (a -> b -> b) -> b -> RadixTree a -> b
forall a b. (a -> b -> b) -> b -> RadixTree a -> b
foldr0'
null :: forall a. RadixTree a -> Bool
null = RadixTree a -> Bool
forall a. RadixTree a -> Bool
null0
length :: forall a. RadixTree a -> Int
length = RadixTree a -> Int
forall a. RadixTree a -> Int
size0
instance Traversable RadixTree where
traverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> RadixTree a -> f (RadixTree b)
traverse = (a -> f b) -> RadixTree a -> f (RadixTree b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> RadixTree a -> f (RadixTree b)
traverse0
instance NFData a => NFData (RadixTree a) where
rnf :: RadixTree a -> ()
rnf = (a -> ()) -> RadixTree a -> ()
forall a. (a -> ()) -> RadixTree a -> ()
forall (f :: * -> *) a. NFData1 f => (a -> ()) -> f a -> ()
liftRnf a -> ()
forall a. NFData a => a -> ()
rnf
instance NFData1 RadixTree where
liftRnf :: forall a. (a -> ()) -> RadixTree a -> ()
liftRnf a -> ()
nf (RadixTree Maybe a
mx Radix1Tree a
t) = (a -> ()) -> Maybe a -> ()
forall a. (a -> ()) -> Maybe a -> ()
forall (f :: * -> *) a. NFData1 f => (a -> ()) -> f a -> ()
liftRnf a -> ()
nf Maybe a
mx () -> () -> ()
forall a b. a -> b -> b
`seq` (a -> ()) -> Radix1Tree a -> ()
forall a. (a -> ()) -> Radix1Tree a -> ()
forall (f :: * -> *) a. NFData1 f => (a -> ()) -> f a -> ()
liftRnf a -> ()
nf Radix1Tree a
t
type LazyRadix1Tree = Radix1Tree
data Radix1Tree a = Bin
{-# UNPACK #-} !Prefix
(Radix1Tree a)
(Radix1Tree a)
| Tip
{-# UNPACK #-} !ByteArray
{-# UNPACK #-} !(Maybe a)
(Radix1Tree a)
| Nil
instance Show a => Show (Radix1Tree a) where
showsPrec :: Int -> Radix1Tree a -> ShowS
showsPrec = (Int -> a -> ShowS)
-> ([a] -> ShowS) -> Int -> Radix1Tree a -> ShowS
forall a.
(Int -> a -> ShowS)
-> ([a] -> ShowS) -> Int -> Radix1Tree a -> ShowS
forall (f :: * -> *) a.
Show1 f =>
(Int -> a -> ShowS) -> ([a] -> ShowS) -> Int -> f a -> ShowS
liftShowsPrec Int -> a -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec [a] -> ShowS
forall a. Show a => [a] -> ShowS
showList
instance Show1 Radix1Tree where
liftShowsPrec :: forall a.
(Int -> a -> ShowS)
-> ([a] -> ShowS) -> Int -> Radix1Tree a -> ShowS
liftShowsPrec Int -> a -> ShowS
showsPrec_ [a] -> ShowS
showList_ Int
d Radix1Tree a
t =
Bool -> ShowS -> ShowS
showParen (Int
d Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
10) (ShowS -> ShowS) -> ShowS -> ShowS
forall a b. (a -> b) -> a -> b
$
((Build1, a) -> ShowS) -> [(Build1, a)] -> ShowS
forall a. (a -> ShowS) -> [a] -> ShowS
showListWith ((Int -> a -> ShowS)
-> ([a] -> ShowS) -> Int -> (Build1, a) -> ShowS
forall a.
(Int -> a -> ShowS)
-> ([a] -> ShowS) -> Int -> (Build1, a) -> ShowS
forall (f :: * -> *) a.
Show1 f =>
(Int -> a -> ShowS) -> ([a] -> ShowS) -> Int -> f a -> ShowS
liftShowsPrec Int -> a -> ShowS
showsPrec_ [a] -> ShowS
showList_ Int
0) ([(Build1, a)] -> ShowS) -> [(Build1, a)] -> ShowS
forall a b. (a -> b) -> a -> b
$
(Build1 -> a -> [(Build1, a)] -> [(Build1, a)])
-> [(Build1, a)] -> Radix1Tree a -> [(Build1, a)]
forall a b. (Build1 -> a -> b -> b) -> b -> Radix1Tree a -> b
foldrWithKey1 (\Build1
k a
a -> (:) (Build1
k, a
a)) [] Radix1Tree a
t
instance Eq a => Eq (Radix1Tree a) where
== :: Radix1Tree a -> Radix1Tree a -> Bool
(==) = (a -> a -> Bool) -> Radix1Tree a -> Radix1Tree a -> Bool
forall a b.
(a -> b -> Bool) -> Radix1Tree a -> Radix1Tree b -> Bool
forall (f :: * -> *) a b.
Eq1 f =>
(a -> b -> Bool) -> f a -> f b -> Bool
liftEq a -> a -> Bool
forall a. Eq a => a -> a -> Bool
(==)
instance Eq1 Radix1Tree where
liftEq :: forall a b.
(a -> b -> Bool) -> Radix1Tree a -> Radix1Tree b -> Bool
liftEq a -> b -> Bool
eq = Radix1Tree a -> Radix1Tree b -> Bool
go
where
go :: Radix1Tree a -> Radix1Tree b -> Bool
go Radix1Tree a
l Radix1Tree b
r =
case Radix1Tree a
l of
Bin Prefix
p Radix1Tree a
xl Radix1Tree a
xr ->
case Radix1Tree b
r of
Bin Prefix
q Radix1Tree b
yl Radix1Tree b
yr -> Prefix
p Prefix -> Prefix -> Bool
forall a. Eq a => a -> a -> Bool
== Prefix
q Bool -> Bool -> Bool
&& Radix1Tree a -> Radix1Tree b -> Bool
go Radix1Tree a
xl Radix1Tree b
yl Bool -> Bool -> Bool
&& Radix1Tree a -> Radix1Tree b -> Bool
go Radix1Tree a
xr Radix1Tree b
yr
Radix1Tree b
_ -> Bool
False
Tip ByteArray
arr Maybe a
mx Radix1Tree a
dx ->
case Radix1Tree b
r of
Tip ByteArray
brr Maybe b
my Radix1Tree b
dy -> ByteArray
arr ByteArray -> ByteArray -> Bool
forall a. Eq a => a -> a -> Bool
== ByteArray
brr Bool -> Bool -> Bool
&& (a -> b -> Bool) -> Maybe a -> Maybe b -> Bool
forall a b. (a -> b -> Bool) -> Maybe a -> Maybe b -> Bool
forall (f :: * -> *) a b.
Eq1 f =>
(a -> b -> Bool) -> f a -> f b -> Bool
liftEq a -> b -> Bool
eq Maybe a
mx Maybe b
my Bool -> Bool -> Bool
&& Radix1Tree a -> Radix1Tree b -> Bool
go Radix1Tree a
dx Radix1Tree b
dy
Radix1Tree b
_ -> Bool
False
Radix1Tree a
Nil ->
case Radix1Tree b
r of
Radix1Tree b
Nil -> Bool
True
Radix1Tree b
_ -> Bool
False
instance Functor Radix1Tree where
fmap :: forall a b. (a -> b) -> Radix1Tree a -> Radix1Tree b
fmap = (a -> b) -> Radix1Tree a -> Radix1Tree b
forall a b. (a -> b) -> Radix1Tree a -> Radix1Tree b
map1
instance Foldable Radix1Tree where
foldl :: forall b a. (b -> a -> b) -> b -> Radix1Tree a -> b
foldl = (b -> a -> b) -> b -> Radix1Tree a -> b
forall b a. (b -> a -> b) -> b -> Radix1Tree a -> b
Data.RadixNTree.Word8.Lazy.foldl1
foldr :: forall a b. (a -> b -> b) -> b -> Radix1Tree a -> b
foldr = (a -> b -> b) -> b -> Radix1Tree a -> b
forall a b. (a -> b -> b) -> b -> Radix1Tree a -> b
Data.RadixNTree.Word8.Lazy.foldr1
foldMap :: forall m a. Monoid m => (a -> m) -> Radix1Tree a -> m
foldMap = (a -> m) -> Radix1Tree a -> m
forall m a. Monoid m => (a -> m) -> Radix1Tree a -> m
foldMap1
foldl' :: forall b a. (b -> a -> b) -> b -> Radix1Tree a -> b
foldl' = (b -> a -> b) -> b -> Radix1Tree a -> b
forall b a. (b -> a -> b) -> b -> Radix1Tree a -> b
foldl1'
foldr' :: forall a b. (a -> b -> b) -> b -> Radix1Tree a -> b
foldr' = (a -> b -> b) -> b -> Radix1Tree a -> b
forall a b. (a -> b -> b) -> b -> Radix1Tree a -> b
foldr1'
null :: forall a. Radix1Tree a -> Bool
null = Radix1Tree a -> Bool
forall a. Radix1Tree a -> Bool
null1
length :: forall a. Radix1Tree a -> Int
length = Radix1Tree a -> Int
forall a. Radix1Tree a -> Int
size1
instance Traversable Radix1Tree where
traverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Radix1Tree a -> f (Radix1Tree b)
traverse = (a -> f b) -> Radix1Tree a -> f (Radix1Tree b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Radix1Tree a -> f (Radix1Tree b)
traverse1
instance NFData a => NFData (Radix1Tree a) where
rnf :: Radix1Tree a -> ()
rnf = (a -> ()) -> Radix1Tree a -> ()
forall a. (a -> ()) -> Radix1Tree a -> ()
forall (f :: * -> *) a. NFData1 f => (a -> ()) -> f a -> ()
liftRnf a -> ()
forall a. NFData a => a -> ()
rnf
instance NFData1 Radix1Tree where
liftRnf :: forall a. (a -> ()) -> Radix1Tree a -> ()
liftRnf a -> ()
nf = Radix1Tree a -> ()
go
where
go :: Radix1Tree a -> ()
go Radix1Tree a
t =
case Radix1Tree a
t of
Bin Prefix
_ Radix1Tree a
l Radix1Tree a
r -> Radix1Tree a -> ()
go Radix1Tree a
l () -> () -> ()
forall a b. a -> b -> b
`seq` Radix1Tree a -> ()
go Radix1Tree a
r
Tip ByteArray
_ Maybe a
mx Radix1Tree a
dx -> (a -> ()) -> Maybe a -> ()
forall a. (a -> ()) -> Maybe a -> ()
forall (f :: * -> *) a. NFData1 f => (a -> ()) -> f a -> ()
liftRnf a -> ()
nf Maybe a
mx () -> () -> ()
forall a b. a -> b -> b
`seq` Radix1Tree a -> ()
go Radix1Tree a
dx
Radix1Tree a
Nil -> ()
{-# INLINE join #-}
join :: Prefix -> Radix1Tree a -> Prefix -> Radix1Tree a -> Radix1Tree a
join :: forall a.
Prefix -> Radix1Tree a -> Prefix -> Radix1Tree a -> Radix1Tree a
join Prefix
p0 Radix1Tree a
t0 Prefix
p1 Radix1Tree a
t1 =
let m :: Prefix
m = Prefix -> Prefix -> Prefix
branchingBit Prefix
p0 Prefix
p1
p :: Prefix
p = Prefix -> Prefix -> Prefix
mask Prefix
p0 Prefix
m Prefix -> Prefix -> Prefix
forall a. Bits a => a -> a -> a
.|. Prefix
m
in if Prefix -> Prefix -> Bool
zeroBit Prefix
p0 Prefix
m
then Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
forall a. Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
Bin Prefix
p Radix1Tree a
t0 Radix1Tree a
t1
else Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
forall a. Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
Bin Prefix
p Radix1Tree a
t1 Radix1Tree a
t0
{-# INLINE safeJoin #-}
safeJoin :: Prefix -> Radix1Tree a -> Prefix -> Radix1Tree a -> Radix1Tree a
safeJoin :: forall a.
Prefix -> Radix1Tree a -> Prefix -> Radix1Tree a -> Radix1Tree a
safeJoin Prefix
_ Radix1Tree a
Nil Prefix
_ Radix1Tree a
t1 = Radix1Tree a
t1
safeJoin Prefix
_ Radix1Tree a
t0 Prefix
_ Radix1Tree a
Nil = Radix1Tree a
t0
safeJoin Prefix
p0 Radix1Tree a
t0 Prefix
p1 Radix1Tree a
t1 = Prefix -> Radix1Tree a -> Prefix -> Radix1Tree a -> Radix1Tree a
forall a.
Prefix -> Radix1Tree a -> Prefix -> Radix1Tree a -> Radix1Tree a
join Prefix
p0 Radix1Tree a
t0 Prefix
p1 Radix1Tree a
t1
{-# INLINE retip #-}
retip :: ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
retip :: forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
retip ByteArray
arr Maybe a
mx Radix1Tree a
dx =
case Maybe a
mx of
Just a
_ -> ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
Tip ByteArray
arr Maybe a
mx Radix1Tree a
dx
Maybe a
Nothing ->
case Radix1Tree a
dx of
Bin Prefix
_ Radix1Tree a
_ Radix1Tree a
_ -> ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
Tip ByteArray
arr Maybe a
mx Radix1Tree a
dx
Tip ByteArray
brr Maybe a
my Radix1Tree a
dy -> ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
Tip (ByteArray -> ByteArray -> ByteArray
appendByteArray ByteArray
arr ByteArray
brr) Maybe a
my Radix1Tree a
dy
Radix1Tree a
Nil -> Radix1Tree a
forall a. Radix1Tree a
Nil
{-# INLINE dropTrim #-}
dropTrim :: Int -> ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
dropTrim :: forall a.
Int -> ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
dropTrim Int
n ByteArray
arr Maybe a
mx Radix1Tree a
dx =
case Maybe a
mx of
Just a
_ -> ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
Tip (Int -> ByteArray -> ByteArray
dropByteArray Int
n ByteArray
arr) Maybe a
mx Radix1Tree a
dx
Maybe a
Nothing ->
case Radix1Tree a
dx of
Bin Prefix
_ Radix1Tree a
_ Radix1Tree a
_ -> ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
Tip (Int -> ByteArray -> ByteArray
dropByteArray Int
n ByteArray
arr) Maybe a
mx Radix1Tree a
dx
Tip ByteArray
brr Maybe a
my Radix1Tree a
dy -> ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
Tip (Int -> ByteArray -> ByteArray -> ByteArray
dropAppendByteArray Int
n ByteArray
arr ByteArray
brr) Maybe a
my Radix1Tree a
dy
Radix1Tree a
Nil -> Radix1Tree a
forall a. Radix1Tree a
Nil
{-# INLINE rebin #-}
rebin :: Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
rebin :: forall a. Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
rebin Prefix
p Radix1Tree a
l Radix1Tree a
r =
case Radix1Tree a
l of
Radix1Tree a
Nil -> Radix1Tree a
r
Radix1Tree a
_ -> case Radix1Tree a
r of
Radix1Tree a
Nil -> Radix1Tree a
l
Radix1Tree a
_ -> Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
forall a. Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
Bin Prefix
p Radix1Tree a
l Radix1Tree a
r
{-# INLINE rebinL #-}
rebinL :: Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
rebinL :: forall a. Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
rebinL Prefix
p Radix1Tree a
l Radix1Tree a
r =
case Radix1Tree a
l of
Radix1Tree a
Nil -> Radix1Tree a
r
Radix1Tree a
_ -> Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
forall a. Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
Bin Prefix
p Radix1Tree a
l Radix1Tree a
r
{-# INLINE rebinR #-}
rebinR :: Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
rebinR :: forall a. Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
rebinR Prefix
p Radix1Tree a
l Radix1Tree a
r =
case Radix1Tree a
r of
Radix1Tree a
Nil -> Radix1Tree a
l
Radix1Tree a
_ -> Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
forall a. Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
Bin Prefix
p Radix1Tree a
l Radix1Tree a
r
empty0 :: RadixTree a
empty0 :: forall a. RadixTree a
empty0 = Maybe a -> Radix1Tree a -> RadixTree a
forall a. Maybe a -> Radix1Tree a -> RadixTree a
RadixTree Maybe a
forall a. Maybe a
Nothing Radix1Tree a
forall a. Radix1Tree a
Nil
empty1 :: Radix1Tree a
empty1 :: forall a. Radix1Tree a
empty1 = Radix1Tree a
forall a. Radix1Tree a
Nil
{-# INLINE singleton0 #-}
singleton0 :: Feed -> a -> RadixTree a
singleton0 :: forall a. Feed -> a -> RadixTree a
singleton0 (Feed forall a. (forall x. (x -> Step Prefix x) -> x -> a) -> a
feed) = \a
a ->
(forall x. (x -> Step Prefix x) -> x -> RadixTree a) -> RadixTree a
forall a. (forall x. (x -> Step Prefix x) -> x -> a) -> a
feed ((forall x. (x -> Step Prefix x) -> x -> RadixTree a)
-> RadixTree a)
-> (forall x. (x -> Step Prefix x) -> x -> RadixTree a)
-> RadixTree a
forall a b. (a -> b) -> a -> b
$ \x -> Step Prefix x
step x
s ->
case x -> Step Prefix x
step x
s of
More Prefix
w x
z -> Maybe a -> Radix1Tree a -> RadixTree a
forall a. Maybe a -> Radix1Tree a -> RadixTree a
RadixTree Maybe a
forall a. Maybe a
Nothing (Radix1Tree a -> RadixTree a) -> Radix1Tree a -> RadixTree a
forall a b. (a -> b) -> a -> b
$ Feed1 -> a -> Radix1Tree a
forall a. Feed1 -> a -> Radix1Tree a
singleton1 (Prefix
-> (forall a. (forall x. (x -> Step Prefix x) -> x -> a) -> a)
-> Feed1
Feed1 Prefix
w (\forall x. (x -> Step Prefix x) -> x -> a
g -> (x -> Step Prefix x) -> x -> a
forall x. (x -> Step Prefix x) -> x -> a
g x -> Step Prefix x
step x
z)) a
a
Step Prefix x
Done -> Maybe a -> Radix1Tree a -> RadixTree a
forall a. Maybe a -> Radix1Tree a -> RadixTree a
RadixTree (a -> Maybe a
forall a. a -> Maybe a
Just a
a) Radix1Tree a
forall a. Radix1Tree a
Nil
{-# INLINE singleton1 #-}
singleton1 :: Feed1 -> a -> Radix1Tree a
singleton1 :: forall a. Feed1 -> a -> Radix1Tree a
singleton1 (Feed1 Prefix
w forall a. (forall x. (x -> Step Prefix x) -> x -> a) -> a
feed) = \a
a -> (forall x. (x -> Step Prefix x) -> x -> Radix1Tree a)
-> Radix1Tree a
forall a. (forall x. (x -> Step Prefix x) -> x -> a) -> a
feed ((forall x. (x -> Step Prefix x) -> x -> Radix1Tree a)
-> Radix1Tree a)
-> (forall x. (x -> Step Prefix x) -> x -> Radix1Tree a)
-> Radix1Tree a
forall a b. (a -> b) -> a -> b
$ \x -> Step Prefix x
step x
s -> (x -> Step Prefix x) -> Prefix -> x -> a -> Radix1Tree a
forall b a.
(b -> Step Prefix b) -> Prefix -> b -> a -> Radix1Tree a
singleton_ x -> Step Prefix x
step Prefix
w x
s a
a
{-# INLINE singleton_ #-}
singleton_ :: (b -> Step Word8 b) -> Word8 -> b -> a -> Radix1Tree a
singleton_ :: forall b a.
(b -> Step Prefix b) -> Prefix -> b -> a -> Radix1Tree a
singleton_ b -> Step Prefix b
step Prefix
w b
s = \a
a -> ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
Tip ((b -> Step Prefix b) -> Prefix -> b -> ByteArray
forall x. (x -> Step Prefix x) -> Prefix -> x -> ByteArray
fromStep b -> Step Prefix b
step Prefix
w b
s) (a -> Maybe a
forall a. a -> Maybe a
Just a
a) Radix1Tree a
forall a. Radix1Tree a
Nil
null0 :: RadixTree a -> Bool
null0 :: forall a. RadixTree a -> Bool
null0 (RadixTree Maybe a
Nothing Radix1Tree a
t) = Radix1Tree a -> Bool
forall a. Radix1Tree a -> Bool
null1 Radix1Tree a
t
null0 RadixTree a
_ = Bool
False
null1 :: Radix1Tree a -> Bool
null1 :: forall a. Radix1Tree a -> Bool
null1 Radix1Tree a
Nil = Bool
True
null1 Radix1Tree a
_ = Bool
False
size0 :: RadixTree a -> Int
size0 :: forall a. RadixTree a -> Int
size0 (RadixTree Maybe a
mx Radix1Tree a
t) =
let !n :: Int
n = Radix1Tree a -> Int
forall a. Radix1Tree a -> Int
size1 Radix1Tree a
t
in case Maybe a
mx of
Just a
_ -> Int
n Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1
Maybe a
Nothing -> Int
n
size1 :: Radix1Tree a -> Int
size1 :: forall a. Radix1Tree a -> Int
size1 = Int -> Radix1Tree a -> Int
forall {t} {a}. Num t => t -> Radix1Tree a -> t
go Int
0
where
go :: t -> Radix1Tree a -> t
go t
z Radix1Tree a
t =
case Radix1Tree a
t of
Bin Prefix
_ Radix1Tree a
l Radix1Tree a
r -> let !n :: t
n = t -> Radix1Tree a -> t
go t
z Radix1Tree a
l
in t -> Radix1Tree a -> t
go t
n Radix1Tree a
r
Tip ByteArray
_ Maybe a
mx Radix1Tree a
dx -> case Maybe a
mx of
Maybe a
Nothing -> t -> Radix1Tree a -> t
go t
z Radix1Tree a
dx
Just a
_ -> let !n :: t
n = t -> Radix1Tree a -> t
go t
z Radix1Tree a
dx
in t
n t -> t -> t
forall a. Num a => a -> a -> a
+ t
1
Radix1Tree a
Nil -> t
z
{-# INLINE fmap' #-}
fmap' :: (a -> b) -> Maybe a -> Maybe b
fmap' :: forall a b. (a -> b) -> Maybe a -> Maybe b
fmap' a -> b
f (Just a
x) = b -> Maybe b
forall a. a -> Maybe a
Just (b -> Maybe b) -> b -> Maybe b
forall a b. (a -> b) -> a -> b
$! a -> b
f a
x
fmap' a -> b
_ Maybe a
Nothing = Maybe b
forall a. Maybe a
Nothing
map0 :: (a -> b) -> RadixTree a -> RadixTree b
map0 :: forall a b. (a -> b) -> RadixTree a -> RadixTree b
map0 a -> b
f (RadixTree Maybe a
mx Radix1Tree a
t) = Maybe b -> Radix1Tree b -> RadixTree b
forall a. Maybe a -> Radix1Tree a -> RadixTree a
RadixTree ((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
mx) (Radix1Tree b -> RadixTree b) -> Radix1Tree b -> RadixTree b
forall a b. (a -> b) -> a -> b
$ (a -> b) -> Radix1Tree a -> Radix1Tree b
forall a b. (a -> b) -> Radix1Tree a -> Radix1Tree b
map1 a -> b
f Radix1Tree a
t
map1 :: (a -> b) -> Radix1Tree a -> Radix1Tree b
map1 :: forall a b. (a -> b) -> Radix1Tree a -> Radix1Tree b
map1 a -> b
f = Radix1Tree a -> Radix1Tree b
go
where
go :: Radix1Tree a -> Radix1Tree b
go Radix1Tree a
t =
case Radix1Tree a
t of
Bin Prefix
p Radix1Tree a
l Radix1Tree a
r -> Prefix -> Radix1Tree b -> Radix1Tree b -> Radix1Tree b
forall a. Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
Bin Prefix
p (Radix1Tree a -> Radix1Tree b
go Radix1Tree a
l) (Radix1Tree a -> Radix1Tree b
go Radix1Tree a
r)
Tip ByteArray
arr Maybe a
mx Radix1Tree a
dx -> ByteArray -> Maybe b -> Radix1Tree b -> Radix1Tree b
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
Tip ByteArray
arr ((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
mx) (Radix1Tree a -> Radix1Tree b
go Radix1Tree a
dx)
Radix1Tree a
Nil -> Radix1Tree b
forall a. Radix1Tree a
Nil
mapWithKey0 :: (Build -> a -> b) -> RadixTree a -> RadixTree b
mapWithKey0 :: forall a b. (Build -> a -> b) -> RadixTree a -> RadixTree b
mapWithKey0 Build -> a -> b
f (RadixTree Maybe a
mx Radix1Tree a
t) =
Maybe b -> Radix1Tree b -> RadixTree b
forall a. Maybe a -> Radix1Tree a -> RadixTree a
RadixTree (Build -> a -> b
f (Tsil ByteArray -> Build
Build Tsil ByteArray
forall a. Tsil a
Lin) (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe a
mx) (Radix1Tree b -> RadixTree b) -> Radix1Tree b -> RadixTree b
forall a b. (a -> b) -> a -> b
$
(Tsil ByteArray -> ByteArray -> a -> b)
-> Tsil ByteArray -> Radix1Tree a -> Radix1Tree b
forall a b.
(Tsil ByteArray -> ByteArray -> a -> b)
-> Tsil ByteArray -> Radix1Tree a -> Radix1Tree b
mapWithKey_ (\Tsil ByteArray
b ByteArray
arr -> Build -> a -> b
f (Tsil ByteArray -> Build
Build (Tsil ByteArray -> Build) -> Tsil ByteArray -> Build
forall a b. (a -> b) -> a -> b
$ Tsil ByteArray -> ByteArray -> Tsil ByteArray
forall a. Tsil a -> a -> Tsil a
Snoc Tsil ByteArray
b ByteArray
arr)) Tsil ByteArray
forall a. Tsil a
Lin Radix1Tree a
t
mapWithKey1 :: (Build1 -> a -> b) -> Radix1Tree a -> Radix1Tree b
mapWithKey1 :: forall a b. (Build1 -> a -> b) -> Radix1Tree a -> Radix1Tree b
mapWithKey1 Build1 -> a -> b
f = (Tsil ByteArray -> ByteArray -> a -> b)
-> Tsil ByteArray -> Radix1Tree a -> Radix1Tree b
forall a b.
(Tsil ByteArray -> ByteArray -> a -> b)
-> Tsil ByteArray -> Radix1Tree a -> Radix1Tree b
mapWithKey_ (\Tsil ByteArray
b ByteArray
arr -> Build1 -> a -> b
f (YtpmeNon ByteArray -> Build1
Build1 (YtpmeNon ByteArray -> Build1) -> YtpmeNon ByteArray -> Build1
forall a b. (a -> b) -> a -> b
$ Tsil ByteArray
b Tsil ByteArray -> ByteArray -> YtpmeNon ByteArray
forall a. Tsil a -> a -> YtpmeNon a
:/ ByteArray
arr)) Tsil ByteArray
forall a. Tsil a
Lin
{-# INLINE mapWithKey_ #-}
mapWithKey_
:: (Tsil ByteArray -> ByteArray -> a -> b) -> Tsil ByteArray
-> Radix1Tree a -> Radix1Tree b
mapWithKey_ :: forall a b.
(Tsil ByteArray -> ByteArray -> a -> b)
-> Tsil ByteArray -> Radix1Tree a -> Radix1Tree b
mapWithKey_ Tsil ByteArray -> ByteArray -> a -> b
f = Tsil ByteArray -> Radix1Tree a -> Radix1Tree b
go
where
go :: Tsil ByteArray -> Radix1Tree a -> Radix1Tree b
go Tsil ByteArray
b Radix1Tree a
t =
case Radix1Tree a
t of
Bin Prefix
p Radix1Tree a
l Radix1Tree a
r -> Prefix -> Radix1Tree b -> Radix1Tree b -> Radix1Tree b
forall a. Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
Bin Prefix
p (Tsil ByteArray -> Radix1Tree a -> Radix1Tree b
go Tsil ByteArray
b Radix1Tree a
l) (Tsil ByteArray -> Radix1Tree a -> Radix1Tree b
go Tsil ByteArray
b Radix1Tree a
r)
Tip ByteArray
arr Maybe a
mx Radix1Tree a
dx -> ByteArray -> Maybe b -> Radix1Tree b -> Radix1Tree b
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
Tip ByteArray
arr (Tsil ByteArray -> ByteArray -> a -> b
f Tsil ByteArray
b ByteArray
arr (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe a
mx) (Tsil ByteArray -> Radix1Tree a -> Radix1Tree b
go (Tsil ByteArray -> ByteArray -> Tsil ByteArray
forall a. Tsil a -> a -> Tsil a
Snoc Tsil ByteArray
b ByteArray
arr) Radix1Tree a
dx)
Radix1Tree a
Nil -> Radix1Tree b
forall a. Radix1Tree a
Nil
foldl0 :: (b -> a -> b) -> b -> RadixTree a -> b
foldl0 :: forall b a. (b -> a -> b) -> b -> RadixTree a -> b
foldl0 b -> a -> b
f b
z (RadixTree Maybe a
mx Radix1Tree a
t) =
let z' :: b
z' = case Maybe a
mx of
Just a
x -> b -> a -> b
f b
z a
x
Maybe a
Nothing -> b
z
in (b -> a -> b) -> b -> Radix1Tree a -> b
forall b a. (b -> a -> b) -> b -> Radix1Tree a -> b
Data.RadixNTree.Word8.Lazy.foldl1 b -> a -> b
f b
z' Radix1Tree a
t
foldl1 :: (b -> a -> b) -> b -> Radix1Tree a -> b
foldl1 :: forall b a. (b -> a -> b) -> b -> Radix1Tree a -> b
foldl1 b -> a -> b
f = b -> Radix1Tree a -> b
go
where
go :: b -> Radix1Tree a -> b
go b
z Radix1Tree a
t =
case Radix1Tree a
t of
Bin Prefix
_ Radix1Tree a
l Radix1Tree a
r -> b -> Radix1Tree a -> b
go (b -> Radix1Tree a -> b
go b
z Radix1Tree a
l) Radix1Tree a
r
Tip ByteArray
_ Maybe a
mx Radix1Tree a
dx -> let z' :: b
z' = case Maybe a
mx of
Just a
x -> b -> a -> b
f b
z a
x
Maybe a
Nothing -> b
z
in b -> Radix1Tree a -> b
go b
z' Radix1Tree a
dx
Radix1Tree a
Nil -> b
z
foldl0' :: (b -> a -> b) -> b -> RadixTree a -> b
foldl0' :: forall b a. (b -> a -> b) -> b -> RadixTree a -> b
foldl0' b -> a -> b
f b
z (RadixTree Maybe a
mx Radix1Tree a
t) =
let !z' :: b
z' = case Maybe a
mx of
Just a
x -> b -> a -> b
f b
z a
x
Maybe a
Nothing -> b
z
in (b -> a -> b) -> b -> Radix1Tree a -> b
forall b a. (b -> a -> b) -> b -> Radix1Tree a -> b
Data.RadixNTree.Word8.Lazy.foldl1' b -> a -> b
f b
z' Radix1Tree a
t
foldl1' :: (b -> a -> b) -> b -> Radix1Tree a -> b
foldl1' :: forall b a. (b -> a -> b) -> b -> Radix1Tree a -> b
foldl1' b -> a -> b
f = b -> Radix1Tree a -> b
go
where
go :: b -> Radix1Tree a -> b
go !b
z Radix1Tree a
t =
case Radix1Tree a
t of
Bin Prefix
_ Radix1Tree a
l Radix1Tree a
r -> let !z' :: b
z' = b -> Radix1Tree a -> b
go b
z Radix1Tree a
l
in b -> Radix1Tree a -> b
go b
z' Radix1Tree a
r
Tip ByteArray
_ Maybe a
mx Radix1Tree a
dx -> let !z' :: b
z' = case Maybe a
mx of
Just a
x -> b -> a -> b
f b
z a
x
Maybe a
Nothing -> b
z
in b -> Radix1Tree a -> b
go b
z' Radix1Tree a
dx
Radix1Tree a
Nil -> b
z
foldlWithKey0 :: (b -> Build -> a -> b) -> b -> RadixTree a -> b
foldlWithKey0 :: forall b a. (b -> Build -> a -> b) -> b -> RadixTree a -> b
foldlWithKey0 b -> Build -> a -> b
f b
z (RadixTree Maybe a
mx Radix1Tree a
t) =
let z' :: b
z' = case Maybe a
mx of
Just a
x -> b -> Build -> a -> b
f b
z (Tsil ByteArray -> Build
Build Tsil ByteArray
forall a. Tsil a
Lin) a
x
Maybe a
Nothing -> b
z
in (b -> Tsil ByteArray -> ByteArray -> a -> b)
-> b -> Radix1Tree a -> b
forall b a.
(b -> Tsil ByteArray -> ByteArray -> a -> b)
-> b -> Radix1Tree a -> b
foldlWithKey_ (\b
z'' Tsil ByteArray
b ByteArray
arr -> b -> Build -> a -> b
f b
z'' (Tsil ByteArray -> Build
Build (Tsil ByteArray -> Build) -> Tsil ByteArray -> Build
forall a b. (a -> b) -> a -> b
$ Tsil ByteArray -> ByteArray -> Tsil ByteArray
forall a. Tsil a -> a -> Tsil a
Snoc Tsil ByteArray
b ByteArray
arr)) b
z' Radix1Tree a
t
foldlWithKey1 :: (b -> Build1 -> a -> b) -> b -> Radix1Tree a -> b
foldlWithKey1 :: forall b a. (b -> Build1 -> a -> b) -> b -> Radix1Tree a -> b
foldlWithKey1 b -> Build1 -> a -> b
f = (b -> Tsil ByteArray -> ByteArray -> a -> b)
-> b -> Radix1Tree a -> b
forall b a.
(b -> Tsil ByteArray -> ByteArray -> a -> b)
-> b -> Radix1Tree a -> b
foldlWithKey_ (\b
z Tsil ByteArray
b ByteArray
arr -> b -> Build1 -> a -> b
f b
z (YtpmeNon ByteArray -> Build1
Build1 (YtpmeNon ByteArray -> Build1) -> YtpmeNon ByteArray -> Build1
forall a b. (a -> b) -> a -> b
$ Tsil ByteArray
b Tsil ByteArray -> ByteArray -> YtpmeNon ByteArray
forall a. Tsil a -> a -> YtpmeNon a
:/ ByteArray
arr))
{-# INLINE foldlWithKey_ #-}
foldlWithKey_ :: (b -> Tsil ByteArray -> ByteArray -> a -> b) -> b -> Radix1Tree a -> b
foldlWithKey_ :: forall b a.
(b -> Tsil ByteArray -> ByteArray -> a -> b)
-> b -> Radix1Tree a -> b
foldlWithKey_ b -> Tsil ByteArray -> ByteArray -> a -> b
f = Tsil ByteArray -> b -> Radix1Tree a -> b
go Tsil ByteArray
forall a. Tsil a
Lin
where
go :: Tsil ByteArray -> b -> Radix1Tree a -> b
go Tsil ByteArray
b b
z Radix1Tree a
t =
case Radix1Tree a
t of
Bin Prefix
_ Radix1Tree a
l Radix1Tree a
r -> Tsil ByteArray -> b -> Radix1Tree a -> b
go Tsil ByteArray
b (Tsil ByteArray -> b -> Radix1Tree a -> b
go Tsil ByteArray
b b
z Radix1Tree a
l) Radix1Tree a
r
Tip ByteArray
arr Maybe a
mx Radix1Tree a
dx ->
case Maybe a
mx of
Maybe a
Nothing -> Tsil ByteArray -> b -> Radix1Tree a -> b
go (Tsil ByteArray -> ByteArray -> Tsil ByteArray
forall a. Tsil a -> a -> Tsil a
Snoc Tsil ByteArray
b ByteArray
arr) b
z Radix1Tree a
dx
Just a
a -> Tsil ByteArray -> b -> Radix1Tree a -> b
go (Tsil ByteArray -> ByteArray -> Tsil ByteArray
forall a. Tsil a -> a -> Tsil a
Snoc Tsil ByteArray
b ByteArray
arr) (b -> Tsil ByteArray -> ByteArray -> a -> b
f b
z Tsil ByteArray
b ByteArray
arr a
a) Radix1Tree a
dx
Radix1Tree a
Nil -> b
z
foldlWithKey0' :: (b -> Build -> a -> b) -> b -> RadixTree a -> b
foldlWithKey0' :: forall b a. (b -> Build -> a -> b) -> b -> RadixTree a -> b
foldlWithKey0' b -> Build -> a -> b
f b
z (RadixTree Maybe a
mx Radix1Tree a
t) =
let !z' :: b
z' = case Maybe a
mx of
Just a
x -> b -> Build -> a -> b
f b
z (Tsil ByteArray -> Build
Build Tsil ByteArray
forall a. Tsil a
Lin) a
x
Maybe a
Nothing -> b
z
in (b -> Tsil ByteArray -> ByteArray -> a -> b)
-> b -> Radix1Tree a -> b
forall b a.
(b -> Tsil ByteArray -> ByteArray -> a -> b)
-> b -> Radix1Tree a -> b
foldlWithKey'_ (\b
z'' Tsil ByteArray
b ByteArray
arr -> b -> Build -> a -> b
f b
z'' (Tsil ByteArray -> Build
Build (Tsil ByteArray -> Build) -> Tsil ByteArray -> Build
forall a b. (a -> b) -> a -> b
$ Tsil ByteArray -> ByteArray -> Tsil ByteArray
forall a. Tsil a -> a -> Tsil a
Snoc Tsil ByteArray
b ByteArray
arr)) b
z' Radix1Tree a
t
foldlWithKey1' :: (b -> Build1 -> a -> b) -> b -> Radix1Tree a -> b
foldlWithKey1' :: forall b a. (b -> Build1 -> a -> b) -> b -> Radix1Tree a -> b
foldlWithKey1' b -> Build1 -> a -> b
f = (b -> Tsil ByteArray -> ByteArray -> a -> b)
-> b -> Radix1Tree a -> b
forall b a.
(b -> Tsil ByteArray -> ByteArray -> a -> b)
-> b -> Radix1Tree a -> b
foldlWithKey'_ (\b
z Tsil ByteArray
b ByteArray
arr -> b -> Build1 -> a -> b
f b
z (YtpmeNon ByteArray -> Build1
Build1 (YtpmeNon ByteArray -> Build1) -> YtpmeNon ByteArray -> Build1
forall a b. (a -> b) -> a -> b
$ Tsil ByteArray
b Tsil ByteArray -> ByteArray -> YtpmeNon ByteArray
forall a. Tsil a -> a -> YtpmeNon a
:/ ByteArray
arr))
{-# INLINE foldlWithKey'_ #-}
foldlWithKey'_ :: (b -> Tsil ByteArray -> ByteArray -> a -> b) -> b -> Radix1Tree a -> b
foldlWithKey'_ :: forall b a.
(b -> Tsil ByteArray -> ByteArray -> a -> b)
-> b -> Radix1Tree a -> b
foldlWithKey'_ b -> Tsil ByteArray -> ByteArray -> a -> b
f = Tsil ByteArray -> b -> Radix1Tree a -> b
go Tsil ByteArray
forall a. Tsil a
Lin
where
go :: Tsil ByteArray -> b -> Radix1Tree a -> b
go Tsil ByteArray
b !b
z Radix1Tree a
t =
case Radix1Tree a
t of
Bin Prefix
_ Radix1Tree a
l Radix1Tree a
r -> let !z' :: b
z' = Tsil ByteArray -> b -> Radix1Tree a -> b
go Tsil ByteArray
b b
z Radix1Tree a
l
in Tsil ByteArray -> b -> Radix1Tree a -> b
go Tsil ByteArray
b b
z' Radix1Tree a
r
Tip ByteArray
arr Maybe a
mx Radix1Tree a
dx ->
case Maybe a
mx of
Maybe a
Nothing -> Tsil ByteArray -> b -> Radix1Tree a -> b
go (Tsil ByteArray -> ByteArray -> Tsil ByteArray
forall a. Tsil a -> a -> Tsil a
Snoc Tsil ByteArray
b ByteArray
arr) b
z Radix1Tree a
dx
Just a
a -> let !z' :: b
z' = b -> Tsil ByteArray -> ByteArray -> a -> b
f b
z Tsil ByteArray
b ByteArray
arr a
a
in Tsil ByteArray -> b -> Radix1Tree a -> b
go (Tsil ByteArray -> ByteArray -> Tsil ByteArray
forall a. Tsil a -> a -> Tsil a
Snoc Tsil ByteArray
b ByteArray
arr) b
z' Radix1Tree a
dx
Radix1Tree a
Nil -> b
z
foldr0 :: (a -> b -> b) -> b -> RadixTree a -> b
foldr0 :: forall a b. (a -> b -> b) -> b -> RadixTree a -> b
foldr0 a -> b -> b
f b
z (RadixTree Maybe a
mx Radix1Tree a
t) =
let z' :: b
z' = (a -> b -> b) -> b -> Radix1Tree a -> b
forall a b. (a -> b -> b) -> b -> Radix1Tree a -> b
Data.RadixNTree.Word8.Lazy.foldr1 a -> b -> b
f b
z Radix1Tree a
t
in case Maybe a
mx of
Just a
x -> a -> b -> b
f a
x b
z'
Maybe a
Nothing -> b
z'
foldr1 :: (a -> b -> b) -> b -> Radix1Tree a -> b
foldr1 :: forall a b. (a -> b -> b) -> b -> Radix1Tree a -> b
foldr1 a -> b -> b
f = b -> Radix1Tree a -> b
go
where
go :: b -> Radix1Tree a -> b
go b
z Radix1Tree a
t =
case Radix1Tree a
t of
Bin Prefix
_ Radix1Tree a
l Radix1Tree a
r -> b -> Radix1Tree a -> b
go (b -> Radix1Tree a -> b
go b
z Radix1Tree a
r) Radix1Tree a
l
Tip ByteArray
_ Maybe a
mx Radix1Tree a
dx -> let z' :: b
z' = b -> Radix1Tree a -> b
go b
z Radix1Tree a
dx
in case Maybe a
mx of
Just a
x -> a -> b -> b
f a
x b
z'
Maybe a
Nothing -> b
z'
Radix1Tree a
Nil -> b
z
foldr0' :: (a -> b -> b) -> b -> RadixTree a -> b
foldr0' :: forall a b. (a -> b -> b) -> b -> RadixTree a -> b
foldr0' a -> b -> b
f b
z (RadixTree Maybe a
mx Radix1Tree a
t) =
let !z' :: b
z' = (a -> b -> b) -> b -> Radix1Tree a -> b
forall a b. (a -> b -> b) -> b -> Radix1Tree a -> b
Data.RadixNTree.Word8.Lazy.foldr1' a -> b -> b
f b
z Radix1Tree a
t
in case Maybe a
mx of
Just a
x -> a -> b -> b
f a
x b
z'
Maybe a
Nothing -> b
z'
foldr1' :: (a -> b -> b) -> b -> Radix1Tree a -> b
foldr1' :: forall a b. (a -> b -> b) -> b -> Radix1Tree a -> b
foldr1' a -> b -> b
f = b -> Radix1Tree a -> b
go
where
go :: b -> Radix1Tree a -> b
go !b
z Radix1Tree a
t =
case Radix1Tree a
t of
Bin Prefix
_ Radix1Tree a
l Radix1Tree a
r -> let !z' :: b
z' = b -> Radix1Tree a -> b
go b
z Radix1Tree a
r
in b -> Radix1Tree a -> b
go b
z' Radix1Tree a
l
Tip ByteArray
_ Maybe a
mx Radix1Tree a
dx -> let !z' :: b
z' = b -> Radix1Tree a -> b
go b
z Radix1Tree a
dx
in case Maybe a
mx of
Just a
x -> a -> b -> b
f a
x b
z'
Maybe a
Nothing -> b
z'
Radix1Tree a
Nil -> b
z
foldrWithKey0 :: (Build -> a -> b -> b) -> b -> RadixTree a -> b
foldrWithKey0 :: forall a b. (Build -> a -> b -> b) -> b -> RadixTree a -> b
foldrWithKey0 Build -> a -> b -> b
f b
z (RadixTree Maybe a
mx Radix1Tree a
t) =
let z' :: b
z' = (Tsil ByteArray -> ByteArray -> a -> b -> b)
-> b -> Radix1Tree a -> b
forall a b.
(Tsil ByteArray -> ByteArray -> a -> b -> b)
-> b -> Radix1Tree a -> b
foldrWithKey_ (\Tsil ByteArray
b ByteArray
arr -> Build -> a -> b -> b
f (Tsil ByteArray -> Build
Build (Tsil ByteArray -> Build) -> Tsil ByteArray -> Build
forall a b. (a -> b) -> a -> b
$ Tsil ByteArray -> ByteArray -> Tsil ByteArray
forall a. Tsil a -> a -> Tsil a
Snoc Tsil ByteArray
b ByteArray
arr)) b
z Radix1Tree a
t
in case Maybe a
mx of
Just a
x -> Build -> a -> b -> b
f (Tsil ByteArray -> Build
Build Tsil ByteArray
forall a. Tsil a
Lin) a
x b
z'
Maybe a
Nothing -> b
z'
foldrWithKey1 :: (Build1 -> a -> b -> b) -> b -> Radix1Tree a -> b
foldrWithKey1 :: forall a b. (Build1 -> a -> b -> b) -> b -> Radix1Tree a -> b
foldrWithKey1 Build1 -> a -> b -> b
f = (Tsil ByteArray -> ByteArray -> a -> b -> b)
-> b -> Radix1Tree a -> b
forall a b.
(Tsil ByteArray -> ByteArray -> a -> b -> b)
-> b -> Radix1Tree a -> b
foldrWithKey_ (\Tsil ByteArray
b ByteArray
arr -> Build1 -> a -> b -> b
f (YtpmeNon ByteArray -> Build1
Build1 (YtpmeNon ByteArray -> Build1) -> YtpmeNon ByteArray -> Build1
forall a b. (a -> b) -> a -> b
$ Tsil ByteArray
b Tsil ByteArray -> ByteArray -> YtpmeNon ByteArray
forall a. Tsil a -> a -> YtpmeNon a
:/ ByteArray
arr))
{-# INLINE foldrWithKey_ #-}
foldrWithKey_ :: (Tsil ByteArray -> ByteArray -> a -> b -> b) -> b -> Radix1Tree a -> b
foldrWithKey_ :: forall a b.
(Tsil ByteArray -> ByteArray -> a -> b -> b)
-> b -> Radix1Tree a -> b
foldrWithKey_ Tsil ByteArray -> ByteArray -> a -> b -> b
f = Tsil ByteArray -> b -> Radix1Tree a -> b
go Tsil ByteArray
forall a. Tsil a
Lin
where
go :: Tsil ByteArray -> b -> Radix1Tree a -> b
go Tsil ByteArray
b b
z Radix1Tree a
t =
case Radix1Tree a
t of
Bin Prefix
_ Radix1Tree a
l Radix1Tree a
r -> Tsil ByteArray -> b -> Radix1Tree a -> b
go Tsil ByteArray
b (Tsil ByteArray -> b -> Radix1Tree a -> b
go Tsil ByteArray
b b
z Radix1Tree a
r) Radix1Tree a
l
Tip ByteArray
arr Maybe a
mx Radix1Tree a
dx -> let z' :: b
z' = Tsil ByteArray -> b -> Radix1Tree a -> b
go (Tsil ByteArray -> ByteArray -> Tsil ByteArray
forall a. Tsil a -> a -> Tsil a
Snoc Tsil ByteArray
b ByteArray
arr) b
z Radix1Tree a
dx
in case Maybe a
mx of
Just a
x -> Tsil ByteArray -> ByteArray -> a -> b -> b
f Tsil ByteArray
b ByteArray
arr a
x b
z'
Maybe a
Nothing -> b
z'
Radix1Tree a
Nil -> b
z
foldrWithKey0' :: (Build -> a -> b -> b) -> b -> RadixTree a -> b
foldrWithKey0' :: forall a b. (Build -> a -> b -> b) -> b -> RadixTree a -> b
foldrWithKey0' Build -> a -> b -> b
f b
z (RadixTree Maybe a
mx Radix1Tree a
t) =
let !z' :: b
z' = (Tsil ByteArray -> ByteArray -> a -> b -> b)
-> b -> Radix1Tree a -> b
forall a b.
(Tsil ByteArray -> ByteArray -> a -> b -> b)
-> b -> Radix1Tree a -> b
foldrWithKey'_ (\Tsil ByteArray
b ByteArray
arr -> Build -> a -> b -> b
f (Tsil ByteArray -> Build
Build (Tsil ByteArray -> Build) -> Tsil ByteArray -> Build
forall a b. (a -> b) -> a -> b
$ Tsil ByteArray -> ByteArray -> Tsil ByteArray
forall a. Tsil a -> a -> Tsil a
Snoc Tsil ByteArray
b ByteArray
arr)) b
z Radix1Tree a
t
in case Maybe a
mx of
Just a
x -> Build -> a -> b -> b
f (Tsil ByteArray -> Build
Build Tsil ByteArray
forall a. Tsil a
Lin) a
x b
z'
Maybe a
Nothing -> b
z'
foldrWithKey1' :: (Build1 -> a -> b -> b) -> b -> Radix1Tree a -> b
foldrWithKey1' :: forall a b. (Build1 -> a -> b -> b) -> b -> Radix1Tree a -> b
foldrWithKey1' Build1 -> a -> b -> b
f = (Tsil ByteArray -> ByteArray -> a -> b -> b)
-> b -> Radix1Tree a -> b
forall a b.
(Tsil ByteArray -> ByteArray -> a -> b -> b)
-> b -> Radix1Tree a -> b
foldrWithKey'_ (\Tsil ByteArray
b ByteArray
arr -> Build1 -> a -> b -> b
f (YtpmeNon ByteArray -> Build1
Build1 (YtpmeNon ByteArray -> Build1) -> YtpmeNon ByteArray -> Build1
forall a b. (a -> b) -> a -> b
$ Tsil ByteArray
b Tsil ByteArray -> ByteArray -> YtpmeNon ByteArray
forall a. Tsil a -> a -> YtpmeNon a
:/ ByteArray
arr))
{-# INLINE foldrWithKey'_ #-}
foldrWithKey'_ :: (Tsil ByteArray -> ByteArray -> a -> b -> b) -> b -> Radix1Tree a -> b
foldrWithKey'_ :: forall a b.
(Tsil ByteArray -> ByteArray -> a -> b -> b)
-> b -> Radix1Tree a -> b
foldrWithKey'_ Tsil ByteArray -> ByteArray -> a -> b -> b
f = Tsil ByteArray -> b -> Radix1Tree a -> b
go Tsil ByteArray
forall a. Tsil a
Lin
where
go :: Tsil ByteArray -> b -> Radix1Tree a -> b
go Tsil ByteArray
b !b
z Radix1Tree a
t =
case Radix1Tree a
t of
Bin Prefix
_ Radix1Tree a
l Radix1Tree a
r -> let !z' :: b
z' = Tsil ByteArray -> b -> Radix1Tree a -> b
go Tsil ByteArray
b b
z Radix1Tree a
r
in Tsil ByteArray -> b -> Radix1Tree a -> b
go Tsil ByteArray
b b
z' Radix1Tree a
l
Tip ByteArray
arr Maybe a
mx Radix1Tree a
dx -> let !z' :: b
z' = Tsil ByteArray -> b -> Radix1Tree a -> b
go (Tsil ByteArray -> ByteArray -> Tsil ByteArray
forall a. Tsil a -> a -> Tsil a
Snoc Tsil ByteArray
b ByteArray
arr) b
z Radix1Tree a
dx
in case Maybe a
mx of
Just a
x -> Tsil ByteArray -> ByteArray -> a -> b -> b
f Tsil ByteArray
b ByteArray
arr a
x b
z'
Maybe a
Nothing -> b
z'
Radix1Tree a
Nil -> b
z
foldMap0 :: Monoid m => (a -> m) -> RadixTree a -> m
foldMap0 :: forall m a. Monoid m => (a -> m) -> RadixTree a -> m
foldMap0 a -> m
f (RadixTree Maybe a
mx Radix1Tree a
t) =
let m :: m
m = (a -> m) -> Radix1Tree a -> m
forall m a. Monoid m => (a -> m) -> Radix1Tree a -> m
foldMap1 a -> m
f Radix1Tree a
t
in case Maybe a
mx of
Just a
x -> a -> m
f a
x m -> m -> m
forall a. Semigroup a => a -> a -> a
<> m
m
Maybe a
Nothing -> m
m
foldMap1 :: Monoid m => (a -> m) -> Radix1Tree a -> m
foldMap1 :: forall m a. Monoid m => (a -> m) -> Radix1Tree a -> m
foldMap1 a -> m
f = Radix1Tree a -> m
go
where
go :: Radix1Tree a -> m
go Radix1Tree a
t =
case Radix1Tree a
t of
Bin Prefix
_ Radix1Tree a
l Radix1Tree a
r -> Radix1Tree a -> m
go Radix1Tree a
l m -> m -> m
forall a. Semigroup a => a -> a -> a
<> Radix1Tree a -> m
go Radix1Tree a
r
Tip ByteArray
_ Maybe a
mx Radix1Tree a
dx -> let m :: m
m = Radix1Tree a -> m
go Radix1Tree a
dx
in case Maybe a
mx of
Maybe a
Nothing -> m
m
Just a
a -> a -> m
f a
a m -> m -> m
forall a. Semigroup a => a -> a -> a
<> m
m
Radix1Tree a
Nil -> m
forall a. Monoid a => a
mempty
foldMapWithKey0 :: Monoid m => (Build -> a -> m) -> RadixTree a -> m
foldMapWithKey0 :: forall m a. Monoid m => (Build -> a -> m) -> RadixTree a -> m
foldMapWithKey0 Build -> a -> m
f (RadixTree Maybe a
mx Radix1Tree a
t) =
let m :: m
m = (Tsil ByteArray -> ByteArray -> a -> m) -> Radix1Tree a -> m
forall m a.
Monoid m =>
(Tsil ByteArray -> ByteArray -> a -> m) -> Radix1Tree a -> m
foldMapWithKey_ (\Tsil ByteArray
b ByteArray
arr -> Build -> a -> m
f (Tsil ByteArray -> Build
Build (Tsil ByteArray -> Build) -> Tsil ByteArray -> Build
forall a b. (a -> b) -> a -> b
$ Tsil ByteArray -> ByteArray -> Tsil ByteArray
forall a. Tsil a -> a -> Tsil a
Snoc Tsil ByteArray
b ByteArray
arr)) Radix1Tree a
t
in case Maybe a
mx of
Just a
x -> Build -> a -> m
f (Tsil ByteArray -> Build
Build Tsil ByteArray
forall a. Tsil a
Lin) a
x m -> m -> m
forall a. Semigroup a => a -> a -> a
<> m
m
Maybe a
Nothing -> m
m
foldMapWithKey1 :: Monoid m => (Build1 -> a -> m) -> Radix1Tree a -> m
foldMapWithKey1 :: forall m a. Monoid m => (Build1 -> a -> m) -> Radix1Tree a -> m
foldMapWithKey1 Build1 -> a -> m
f = (Tsil ByteArray -> ByteArray -> a -> m) -> Radix1Tree a -> m
forall m a.
Monoid m =>
(Tsil ByteArray -> ByteArray -> a -> m) -> Radix1Tree a -> m
foldMapWithKey_ (\Tsil ByteArray
b ByteArray
arr -> Build1 -> a -> m
f (YtpmeNon ByteArray -> Build1
Build1 (YtpmeNon ByteArray -> Build1) -> YtpmeNon ByteArray -> Build1
forall a b. (a -> b) -> a -> b
$ Tsil ByteArray
b Tsil ByteArray -> ByteArray -> YtpmeNon ByteArray
forall a. Tsil a -> a -> YtpmeNon a
:/ ByteArray
arr))
{-# INLINE foldMapWithKey_ #-}
foldMapWithKey_
:: Monoid m => (Tsil ByteArray -> ByteArray -> a -> m) -> Radix1Tree a -> m
foldMapWithKey_ :: forall m a.
Monoid m =>
(Tsil ByteArray -> ByteArray -> a -> m) -> Radix1Tree a -> m
foldMapWithKey_ Tsil ByteArray -> ByteArray -> a -> m
f = Tsil ByteArray -> Radix1Tree a -> m
go Tsil ByteArray
forall a. Tsil a
Lin
where
go :: Tsil ByteArray -> Radix1Tree a -> m
go Tsil ByteArray
b Radix1Tree a
t =
case Radix1Tree a
t of
Bin Prefix
_ Radix1Tree a
l Radix1Tree a
r -> Tsil ByteArray -> Radix1Tree a -> m
go Tsil ByteArray
b Radix1Tree a
l m -> m -> m
forall a. Semigroup a => a -> a -> a
<> Tsil ByteArray -> Radix1Tree a -> m
go Tsil ByteArray
b Radix1Tree a
r
Tip ByteArray
arr Maybe a
mx Radix1Tree a
dx ->
let m :: m
m = Tsil ByteArray -> Radix1Tree a -> m
go (Tsil ByteArray -> ByteArray -> Tsil ByteArray
forall a. Tsil a -> a -> Tsil a
Snoc Tsil ByteArray
b ByteArray
arr) Radix1Tree a
dx
in case Maybe a
mx of
Maybe a
Nothing -> m
m
Just a
a -> Tsil ByteArray -> ByteArray -> a -> m
f Tsil ByteArray
b ByteArray
arr a
a m -> m -> m
forall a. Semigroup a => a -> a -> a
<> m
m
Radix1Tree a
Nil -> m
forall a. Monoid a => a
mempty
traverse0 :: Applicative f => (a -> f b) -> RadixTree a -> f (RadixTree b)
traverse0 :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> RadixTree a -> f (RadixTree b)
traverse0 a -> f b
f (RadixTree Maybe a
mx Radix1Tree a
t) =
let dy :: f (Radix1Tree b)
dy = (a -> f b) -> Radix1Tree a -> f (Radix1Tree b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Radix1Tree a -> f (Radix1Tree b)
traverse1 a -> f b
f Radix1Tree a
t
in case Maybe a
mx of
Just a
x -> (Maybe b -> Radix1Tree b -> RadixTree b)
-> f (Maybe b) -> f (Radix1Tree b) -> f (RadixTree 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 Maybe b -> Radix1Tree b -> RadixTree b
forall a. Maybe a -> Radix1Tree a -> RadixTree a
RadixTree (b -> Maybe b
forall a. a -> Maybe a
Just (b -> Maybe b) -> f b -> f (Maybe b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> f b
f a
x) f (Radix1Tree b)
dy
Maybe a
Nothing -> Maybe b -> Radix1Tree b -> RadixTree b
forall a. Maybe a -> Radix1Tree a -> RadixTree a
RadixTree Maybe b
forall a. Maybe a
Nothing (Radix1Tree b -> RadixTree b)
-> f (Radix1Tree b) -> f (RadixTree b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> f (Radix1Tree b)
dy
traverse1 :: Applicative f => (a -> f b) -> Radix1Tree a -> f (Radix1Tree b)
traverse1 :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Radix1Tree a -> f (Radix1Tree b)
traverse1 a -> f b
f = Radix1Tree a -> f (Radix1Tree b)
go
where
go :: Radix1Tree a -> f (Radix1Tree b)
go Radix1Tree a
t =
case Radix1Tree a
t of
Bin Prefix
p Radix1Tree a
l Radix1Tree a
r -> (Radix1Tree b -> Radix1Tree b -> Radix1Tree b)
-> f (Radix1Tree b) -> f (Radix1Tree b) -> f (Radix1Tree 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 (Prefix -> Radix1Tree b -> Radix1Tree b -> Radix1Tree b
forall a. Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
Bin Prefix
p) (Radix1Tree a -> f (Radix1Tree b)
go Radix1Tree a
l) (Radix1Tree a -> f (Radix1Tree b)
go Radix1Tree a
r)
Tip ByteArray
arr Maybe a
mx Radix1Tree a
dx ->
case Maybe a
mx of
Maybe a
Nothing -> ByteArray -> Maybe b -> Radix1Tree b -> Radix1Tree b
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
Tip ByteArray
arr Maybe b
forall a. Maybe a
Nothing (Radix1Tree b -> Radix1Tree b)
-> f (Radix1Tree b) -> f (Radix1Tree b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Radix1Tree a -> f (Radix1Tree b)
go Radix1Tree a
dx
Just a
x -> (b -> Radix1Tree b -> Radix1Tree b)
-> f b -> f (Radix1Tree b) -> f (Radix1Tree 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 (ByteArray -> Maybe b -> Radix1Tree b -> Radix1Tree b
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
Tip ByteArray
arr (Maybe b -> Radix1Tree b -> Radix1Tree b)
-> (b -> Maybe b) -> b -> Radix1Tree b -> Radix1Tree b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. b -> Maybe b
forall a. a -> Maybe a
Just) (a -> f b
f a
x) (Radix1Tree a -> f (Radix1Tree b)
go Radix1Tree a
dx)
Radix1Tree a
Nil -> Radix1Tree b -> f (Radix1Tree b)
forall a. a -> f a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Radix1Tree b
forall a. Radix1Tree a
Nil
traverseWithKey0 :: Applicative f => (Build -> a -> f b) -> RadixTree a -> f (RadixTree b)
traverseWithKey0 :: forall (f :: * -> *) a b.
Applicative f =>
(Build -> a -> f b) -> RadixTree a -> f (RadixTree b)
traverseWithKey0 Build -> a -> f b
f (RadixTree Maybe a
mx Radix1Tree a
t) =
let dy :: f (Radix1Tree b)
dy = (Tsil ByteArray -> ByteArray -> a -> f b)
-> Radix1Tree a -> f (Radix1Tree b)
forall (f :: * -> *) a b.
Applicative f =>
(Tsil ByteArray -> ByteArray -> a -> f b)
-> Radix1Tree a -> f (Radix1Tree b)
traverseWithKey_ (\Tsil ByteArray
b ByteArray
arr -> Build -> a -> f b
f (Tsil ByteArray -> Build
Build (Tsil ByteArray -> Build) -> Tsil ByteArray -> Build
forall a b. (a -> b) -> a -> b
$ Tsil ByteArray -> ByteArray -> Tsil ByteArray
forall a. Tsil a -> a -> Tsil a
Snoc Tsil ByteArray
b ByteArray
arr)) Radix1Tree a
t
in case Maybe a
mx of
Just a
x -> (Maybe b -> Radix1Tree b -> RadixTree b)
-> f (Maybe b) -> f (Radix1Tree b) -> f (RadixTree 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 Maybe b -> Radix1Tree b -> RadixTree b
forall a. Maybe a -> Radix1Tree a -> RadixTree a
RadixTree (b -> Maybe b
forall a. a -> Maybe a
Just (b -> Maybe b) -> f b -> f (Maybe b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Build -> a -> f b
f (Tsil ByteArray -> Build
Build Tsil ByteArray
forall a. Tsil a
Lin) a
x) f (Radix1Tree b)
dy
Maybe a
Nothing -> Maybe b -> Radix1Tree b -> RadixTree b
forall a. Maybe a -> Radix1Tree a -> RadixTree a
RadixTree Maybe b
forall a. Maybe a
Nothing (Radix1Tree b -> RadixTree b)
-> f (Radix1Tree b) -> f (RadixTree b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> f (Radix1Tree b)
dy
traverseWithKey1
:: Applicative f => (Build1 -> a -> f b) -> Radix1Tree a -> f (Radix1Tree b)
traverseWithKey1 :: forall (f :: * -> *) a b.
Applicative f =>
(Build1 -> a -> f b) -> Radix1Tree a -> f (Radix1Tree b)
traverseWithKey1 Build1 -> a -> f b
f = (Tsil ByteArray -> ByteArray -> a -> f b)
-> Radix1Tree a -> f (Radix1Tree b)
forall (f :: * -> *) a b.
Applicative f =>
(Tsil ByteArray -> ByteArray -> a -> f b)
-> Radix1Tree a -> f (Radix1Tree b)
traverseWithKey_ (\Tsil ByteArray
b ByteArray
arr -> Build1 -> a -> f b
f (YtpmeNon ByteArray -> Build1
Build1 (YtpmeNon ByteArray -> Build1) -> YtpmeNon ByteArray -> Build1
forall a b. (a -> b) -> a -> b
$ Tsil ByteArray
b Tsil ByteArray -> ByteArray -> YtpmeNon ByteArray
forall a. Tsil a -> a -> YtpmeNon a
:/ ByteArray
arr))
{-# INLINE traverseWithKey_ #-}
traverseWithKey_
:: Applicative f
=> (Tsil ByteArray -> ByteArray -> a -> f b) -> Radix1Tree a -> f (Radix1Tree b)
traverseWithKey_ :: forall (f :: * -> *) a b.
Applicative f =>
(Tsil ByteArray -> ByteArray -> a -> f b)
-> Radix1Tree a -> f (Radix1Tree b)
traverseWithKey_ Tsil ByteArray -> ByteArray -> a -> f b
f = Tsil ByteArray -> Radix1Tree a -> f (Radix1Tree b)
go Tsil ByteArray
forall a. Tsil a
Lin
where
go :: Tsil ByteArray -> Radix1Tree a -> f (Radix1Tree b)
go Tsil ByteArray
b Radix1Tree a
t =
case Radix1Tree a
t of
Bin Prefix
p Radix1Tree a
l Radix1Tree a
r -> (Radix1Tree b -> Radix1Tree b -> Radix1Tree b)
-> f (Radix1Tree b) -> f (Radix1Tree b) -> f (Radix1Tree 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 (Prefix -> Radix1Tree b -> Radix1Tree b -> Radix1Tree b
forall a. Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
Bin Prefix
p) (Tsil ByteArray -> Radix1Tree a -> f (Radix1Tree b)
go Tsil ByteArray
b Radix1Tree a
l) (Tsil ByteArray -> Radix1Tree a -> f (Radix1Tree b)
go Tsil ByteArray
b Radix1Tree a
r)
Tip ByteArray
arr Maybe a
mx Radix1Tree a
dx ->
let dy :: f (Radix1Tree b)
dy = Tsil ByteArray -> Radix1Tree a -> f (Radix1Tree b)
go (Tsil ByteArray -> ByteArray -> Tsil ByteArray
forall a. Tsil a -> a -> Tsil a
Snoc Tsil ByteArray
b ByteArray
arr) Radix1Tree a
dx
in case Maybe a
mx of
Maybe a
Nothing -> ByteArray -> Maybe b -> Radix1Tree b -> Radix1Tree b
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
Tip ByteArray
arr Maybe b
forall a. Maybe a
Nothing (Radix1Tree b -> Radix1Tree b)
-> f (Radix1Tree b) -> f (Radix1Tree b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> f (Radix1Tree b)
dy
Just a
a -> (b -> Radix1Tree b -> Radix1Tree b)
-> f b -> f (Radix1Tree b) -> f (Radix1Tree 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 (ByteArray -> Maybe b -> Radix1Tree b -> Radix1Tree b
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
Tip ByteArray
arr (Maybe b -> Radix1Tree b -> Radix1Tree b)
-> (b -> Maybe b) -> b -> Radix1Tree b -> Radix1Tree b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. b -> Maybe b
forall a. a -> Maybe a
Just) (Tsil ByteArray -> ByteArray -> a -> f b
f Tsil ByteArray
b ByteArray
arr a
a) f (Radix1Tree b)
dy
Radix1Tree a
Nil -> Radix1Tree b -> f (Radix1Tree b)
forall a. a -> f a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Radix1Tree b
forall a. Radix1Tree a
Nil
{-# INLINE lookup0 #-}
lookup0 :: Feed -> RadixTree a -> Maybe a
lookup0 :: forall a. Feed -> RadixTree a -> Maybe a
lookup0 (Feed forall a. (forall x. (x -> Step Prefix x) -> x -> a) -> a
feed) = \(RadixTree Maybe a
mx Radix1Tree a
t) ->
(forall x. (x -> Step Prefix x) -> x -> Maybe a) -> Maybe a
forall a. (forall x. (x -> Step Prefix x) -> x -> a) -> a
feed ((forall x. (x -> Step Prefix x) -> x -> Maybe a) -> Maybe a)
-> (forall x. (x -> Step Prefix x) -> x -> Maybe a) -> Maybe a
forall a b. (a -> b) -> a -> b
$ \x -> Step Prefix x
step x
s ->
case x -> Step Prefix x
step x
s of
More Prefix
w x
z -> (x -> Step Prefix x) -> Prefix -> x -> Radix1Tree a -> Maybe a
forall x a.
(x -> Step Prefix x) -> Prefix -> x -> Radix1Tree a -> Maybe a
lookup_ x -> Step Prefix x
step Prefix
w x
z Radix1Tree a
t
Step Prefix x
Done -> Maybe a
mx
{-# INLINE lookup1 #-}
lookup1 :: Feed1 -> Radix1Tree a -> Maybe a
lookup1 :: forall a. Feed1 -> Radix1Tree a -> Maybe a
lookup1 (Feed1 Prefix
w forall a. (forall x. (x -> Step Prefix x) -> x -> a) -> a
feed) = (forall x. (x -> Step Prefix x) -> x -> Radix1Tree a -> Maybe a)
-> Radix1Tree a -> Maybe a
forall a. (forall x. (x -> Step Prefix x) -> x -> a) -> a
feed ((forall x. (x -> Step Prefix x) -> x -> Radix1Tree a -> Maybe a)
-> Radix1Tree a -> Maybe a)
-> (forall x. (x -> Step Prefix x) -> x -> Radix1Tree a -> Maybe a)
-> Radix1Tree a
-> Maybe a
forall a b. (a -> b) -> a -> b
$ \x -> Step Prefix x
step -> (x -> Step Prefix x) -> Prefix -> x -> Radix1Tree a -> Maybe a
forall x a.
(x -> Step Prefix x) -> Prefix -> x -> Radix1Tree a -> Maybe a
lookup_ x -> Step Prefix x
step Prefix
w
{-# INLINE lookup_ #-}
lookup_ :: (x -> Step Word8 x) -> Word8 -> x -> Radix1Tree a -> Maybe a
lookup_ :: forall x a.
(x -> Step Prefix x) -> Prefix -> x -> Radix1Tree a -> Maybe a
lookup_ x -> Step Prefix x
step = Prefix -> x -> Radix1Tree a -> Maybe a
go
where
go :: Prefix -> x -> Radix1Tree a -> Maybe a
go Prefix
w x
s Radix1Tree a
t =
case Radix1Tree a
t of
Bin Prefix
p Radix1Tree a
l Radix1Tree a
r ->
Prefix -> x -> Radix1Tree a -> Maybe a
go Prefix
w x
s (Radix1Tree a -> Maybe a) -> Radix1Tree a -> Maybe a
forall a b. (a -> b) -> a -> b
$ if Prefix
w Prefix -> Prefix -> Bool
forall a. Ord a => a -> a -> Bool
< Prefix
p
then Radix1Tree a
l
else Radix1Tree a
r
Tip ByteArray
arr Maybe a
mx Radix1Tree a
dx -> Prefix -> x -> Int -> Maybe a
goarr Prefix
w x
s Int
0
where
goarr :: Prefix -> x -> Int -> Maybe a
goarr Prefix
v x
z Int
n
| Prefix
v Prefix -> Prefix -> Bool
forall a. Eq a => a -> a -> Bool
== ByteArray -> Int -> Prefix
forall a. Prim a => ByteArray -> Int -> a
indexByteArray ByteArray
arr Int
n =
let n' :: Int
n' = Int
n Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1
in if Int
n' Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= ByteArray -> Int
sizeofByteArray ByteArray
arr
then case x -> Step Prefix x
step x
z of
More Prefix
u x
z' -> Prefix -> x -> Radix1Tree a -> Maybe a
go Prefix
u x
z' Radix1Tree a
dx
Step Prefix x
Done -> Maybe a
mx
else case x -> Step Prefix x
step x
z of
More Prefix
u x
z' -> Prefix -> x -> Int -> Maybe a
goarr Prefix
u x
z' Int
n'
Step Prefix x
Done -> Maybe a
forall a. Maybe a
Nothing
| Bool
otherwise = Maybe a
forall a. Maybe a
Nothing
Radix1Tree a
Nil -> Maybe a
forall a. Maybe a
Nothing
{-# INLINE find0 #-}
find0 :: a -> Feed -> RadixTree a -> a
find0 :: forall a. a -> Feed -> RadixTree a -> a
find0 a
d (Feed forall a. (forall x. (x -> Step Prefix x) -> x -> a) -> a
feed) = \(RadixTree Maybe a
mx Radix1Tree a
t) ->
(forall x. (x -> Step Prefix x) -> x -> a) -> a
forall a. (forall x. (x -> Step Prefix x) -> x -> a) -> a
feed ((forall x. (x -> Step Prefix x) -> x -> a) -> a)
-> (forall x. (x -> Step Prefix x) -> x -> a) -> a
forall a b. (a -> b) -> a -> b
$ \x -> Step Prefix x
step x
s ->
case x -> Step Prefix x
step x
s of
More Prefix
w x
z -> a -> (x -> Step Prefix x) -> Prefix -> x -> Radix1Tree a -> a
forall a x.
a -> (x -> Step Prefix x) -> Prefix -> x -> Radix1Tree a -> a
find_ a
d x -> Step Prefix x
step Prefix
w x
z Radix1Tree a
t
Step Prefix x
Done -> case Maybe a
mx of
Just a
x -> a
x
Maybe a
Nothing -> a
d
{-# INLINE find1 #-}
find1 :: a -> Feed1 -> Radix1Tree a -> a
find1 :: forall a. a -> Feed1 -> Radix1Tree a -> a
find1 a
d (Feed1 Prefix
w forall a. (forall x. (x -> Step Prefix x) -> x -> a) -> a
feed) = (forall x. (x -> Step Prefix x) -> x -> Radix1Tree a -> a)
-> Radix1Tree a -> a
forall a. (forall x. (x -> Step Prefix x) -> x -> a) -> a
feed ((forall x. (x -> Step Prefix x) -> x -> Radix1Tree a -> a)
-> Radix1Tree a -> a)
-> (forall x. (x -> Step Prefix x) -> x -> Radix1Tree a -> a)
-> Radix1Tree a
-> a
forall a b. (a -> b) -> a -> b
$ \x -> Step Prefix x
step -> a -> (x -> Step Prefix x) -> Prefix -> x -> Radix1Tree a -> a
forall a x.
a -> (x -> Step Prefix x) -> Prefix -> x -> Radix1Tree a -> a
find_ a
d x -> Step Prefix x
step Prefix
w
{-# INLINE find_ #-}
find_ :: a -> (x -> Step Word8 x) -> Word8 -> x -> Radix1Tree a -> a
find_ :: forall a x.
a -> (x -> Step Prefix x) -> Prefix -> x -> Radix1Tree a -> a
find_ a
d x -> Step Prefix x
step = Prefix -> x -> Radix1Tree a -> a
go
where
go :: Prefix -> x -> Radix1Tree a -> a
go Prefix
w x
s Radix1Tree a
t =
case Radix1Tree a
t of
Bin Prefix
p Radix1Tree a
l Radix1Tree a
r ->
Prefix -> x -> Radix1Tree a -> a
go Prefix
w x
s (Radix1Tree a -> a) -> Radix1Tree a -> a
forall a b. (a -> b) -> a -> b
$ if Prefix
w Prefix -> Prefix -> Bool
forall a. Ord a => a -> a -> Bool
< Prefix
p
then Radix1Tree a
l
else Radix1Tree a
r
Tip ByteArray
arr Maybe a
mx Radix1Tree a
dx -> Prefix -> x -> Int -> a
goarr Prefix
w x
s Int
0
where
goarr :: Prefix -> x -> Int -> a
goarr Prefix
v x
z Int
n
| Prefix
v Prefix -> Prefix -> Bool
forall a. Eq a => a -> a -> Bool
== ByteArray -> Int -> Prefix
forall a. Prim a => ByteArray -> Int -> a
indexByteArray ByteArray
arr Int
n =
let n' :: Int
n' = Int
n Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1
in if Int
n' Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= ByteArray -> Int
sizeofByteArray ByteArray
arr
then case x -> Step Prefix x
step x
z of
More Prefix
u x
z' -> Prefix -> x -> Radix1Tree a -> a
go Prefix
u x
z' Radix1Tree a
dx
Step Prefix x
Done -> case Maybe a
mx of
Just a
x -> a
x
Maybe a
Nothing -> a
d
else case x -> Step Prefix x
step x
z of
More Prefix
u x
z' -> Prefix -> x -> Int -> a
goarr Prefix
u x
z' Int
n'
Step Prefix x
Done -> a
d
| Bool
otherwise = a
d
Radix1Tree a
Nil -> a
d
{-# INLINE member0 #-}
member0 :: Feed -> RadixTree a -> Bool
member0 :: forall a. Feed -> RadixTree a -> Bool
member0 (Feed forall a. (forall x. (x -> Step Prefix x) -> x -> a) -> a
feed) = \(RadixTree Maybe a
mx Radix1Tree a
t) ->
(forall x. (x -> Step Prefix x) -> x -> Bool) -> Bool
forall a. (forall x. (x -> Step Prefix x) -> x -> a) -> a
feed ((forall x. (x -> Step Prefix x) -> x -> Bool) -> Bool)
-> (forall x. (x -> Step Prefix x) -> x -> Bool) -> Bool
forall a b. (a -> b) -> a -> b
$ \x -> Step Prefix x
step x
s ->
case x -> Step Prefix x
step x
s of
More Prefix
w x
z -> (x -> Step Prefix x) -> Prefix -> x -> Radix1Tree a -> Bool
forall x a.
(x -> Step Prefix x) -> Prefix -> x -> Radix1Tree a -> Bool
member_ x -> Step Prefix x
step Prefix
w x
z Radix1Tree a
t
Step Prefix x
Done -> case Maybe a
mx of
Just a
_ -> Bool
True
Maybe a
Nothing -> Bool
False
{-# INLINE member1 #-}
member1 :: Feed1 -> Radix1Tree a -> Bool
member1 :: forall a. Feed1 -> Radix1Tree a -> Bool
member1 (Feed1 Prefix
w forall a. (forall x. (x -> Step Prefix x) -> x -> a) -> a
feed) = (forall x. (x -> Step Prefix x) -> x -> Radix1Tree a -> Bool)
-> Radix1Tree a -> Bool
forall a. (forall x. (x -> Step Prefix x) -> x -> a) -> a
feed ((forall x. (x -> Step Prefix x) -> x -> Radix1Tree a -> Bool)
-> Radix1Tree a -> Bool)
-> (forall x. (x -> Step Prefix x) -> x -> Radix1Tree a -> Bool)
-> Radix1Tree a
-> Bool
forall a b. (a -> b) -> a -> b
$ \x -> Step Prefix x
step -> (x -> Step Prefix x) -> Prefix -> x -> Radix1Tree a -> Bool
forall x a.
(x -> Step Prefix x) -> Prefix -> x -> Radix1Tree a -> Bool
member_ x -> Step Prefix x
step Prefix
w
{-# INLINE member_ #-}
member_ :: (x -> Step Word8 x) -> Word8 -> x -> Radix1Tree a -> Bool
member_ :: forall x a.
(x -> Step Prefix x) -> Prefix -> x -> Radix1Tree a -> Bool
member_ x -> Step Prefix x
step = Prefix -> x -> Radix1Tree a -> Bool
go
where
go :: Prefix -> x -> Radix1Tree a -> Bool
go Prefix
w x
s Radix1Tree a
t =
case Radix1Tree a
t of
Bin Prefix
p Radix1Tree a
l Radix1Tree a
r ->
Prefix -> x -> Radix1Tree a -> Bool
go Prefix
w x
s (Radix1Tree a -> Bool) -> Radix1Tree a -> Bool
forall a b. (a -> b) -> a -> b
$ if Prefix
w Prefix -> Prefix -> Bool
forall a. Ord a => a -> a -> Bool
< Prefix
p
then Radix1Tree a
l
else Radix1Tree a
r
Tip ByteArray
arr Maybe a
mx Radix1Tree a
dx -> Prefix -> x -> Int -> Bool
goarr Prefix
w x
s Int
0
where
goarr :: Prefix -> x -> Int -> Bool
goarr Prefix
v x
z Int
n
| Prefix
v Prefix -> Prefix -> Bool
forall a. Eq a => a -> a -> Bool
== ByteArray -> Int -> Prefix
forall a. Prim a => ByteArray -> Int -> a
indexByteArray ByteArray
arr Int
n =
let n' :: Int
n' = Int
n Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1
in if Int
n' Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= ByteArray -> Int
sizeofByteArray ByteArray
arr
then case x -> Step Prefix x
step x
z of
More Prefix
u x
z' -> Prefix -> x -> Radix1Tree a -> Bool
go Prefix
u x
z' Radix1Tree a
dx
Step Prefix x
Done -> case Maybe a
mx of
Just a
_ -> Bool
True
Maybe a
Nothing -> Bool
False
else case x -> Step Prefix x
step x
z of
More Prefix
u x
z' -> Prefix -> x -> Int -> Bool
goarr Prefix
u x
z' Int
n'
Step Prefix x
Done -> Bool
False
| Bool
otherwise = Bool
False
Radix1Tree a
Nil -> Bool
False
{-# INLINE subtree0 #-}
subtree0 :: Feed -> RadixTree a -> RadixTree a
subtree0 :: forall a. Feed -> RadixTree a -> RadixTree a
subtree0 (Feed forall a. (forall x. (x -> Step Prefix x) -> x -> a) -> a
feed) = \t0 :: RadixTree a
t0@(RadixTree Maybe a
_ Radix1Tree a
t) ->
(forall x. (x -> Step Prefix x) -> x -> RadixTree a) -> RadixTree a
forall a. (forall x. (x -> Step Prefix x) -> x -> a) -> a
feed ((forall x. (x -> Step Prefix x) -> x -> RadixTree a)
-> RadixTree a)
-> (forall x. (x -> Step Prefix x) -> x -> RadixTree a)
-> RadixTree a
forall a b. (a -> b) -> a -> b
$ \x -> Step Prefix x
step x
s ->
case x -> Step Prefix x
step x
s of
More Prefix
w x
z -> (x -> Step Prefix x) -> Prefix -> x -> Radix1Tree a -> RadixTree a
forall x a.
(x -> Step Prefix x) -> Prefix -> x -> Radix1Tree a -> RadixTree a
subtree_ x -> Step Prefix x
step Prefix
w x
z Radix1Tree a
t
Step Prefix x
Done -> RadixTree a
t0
{-# INLINE subtree1 #-}
subtree1 :: Feed1 -> Radix1Tree a -> RadixTree a
subtree1 :: forall a. Feed1 -> Radix1Tree a -> RadixTree a
subtree1 (Feed1 Prefix
w forall a. (forall x. (x -> Step Prefix x) -> x -> a) -> a
feed) = (forall x.
(x -> Step Prefix x) -> x -> Radix1Tree a -> RadixTree a)
-> Radix1Tree a -> RadixTree a
forall a. (forall x. (x -> Step Prefix x) -> x -> a) -> a
feed ((forall x.
(x -> Step Prefix x) -> x -> Radix1Tree a -> RadixTree a)
-> Radix1Tree a -> RadixTree a)
-> (forall x.
(x -> Step Prefix x) -> x -> Radix1Tree a -> RadixTree a)
-> Radix1Tree a
-> RadixTree a
forall a b. (a -> b) -> a -> b
$ \x -> Step Prefix x
step -> (x -> Step Prefix x) -> Prefix -> x -> Radix1Tree a -> RadixTree a
forall x a.
(x -> Step Prefix x) -> Prefix -> x -> Radix1Tree a -> RadixTree a
subtree_ x -> Step Prefix x
step Prefix
w
{-# INLINE subtree_ #-}
subtree_ :: (x -> Step Word8 x) -> Word8 -> x -> Radix1Tree a -> RadixTree a
subtree_ :: forall x a.
(x -> Step Prefix x) -> Prefix -> x -> Radix1Tree a -> RadixTree a
subtree_ x -> Step Prefix x
step = Prefix -> x -> Radix1Tree a -> RadixTree a
go
where
go :: Prefix -> x -> Radix1Tree a -> RadixTree a
go Prefix
w x
s Radix1Tree a
t =
case Radix1Tree a
t of
Bin Prefix
p Radix1Tree a
l Radix1Tree a
r ->
Prefix -> x -> Radix1Tree a -> RadixTree a
go Prefix
w x
s (Radix1Tree a -> RadixTree a) -> Radix1Tree a -> RadixTree a
forall a b. (a -> b) -> a -> b
$ if Prefix
w Prefix -> Prefix -> Bool
forall a. Ord a => a -> a -> Bool
< Prefix
p
then Radix1Tree a
l
else Radix1Tree a
r
Tip ByteArray
arr Maybe a
mx Radix1Tree a
dx -> Prefix -> x -> Int -> RadixTree a
goarr Prefix
w x
s Int
0
where
goarr :: Prefix -> x -> Int -> RadixTree a
goarr Prefix
v x
z Int
n
| Prefix
v Prefix -> Prefix -> Bool
forall a. Eq a => a -> a -> Bool
== ByteArray -> Int -> Prefix
forall a. Prim a => ByteArray -> Int -> a
indexByteArray ByteArray
arr Int
n =
if Int
n Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1 Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= ByteArray -> Int
sizeofByteArray ByteArray
arr
then case x -> Step Prefix x
step x
z of
More Prefix
u x
z' -> Prefix -> x -> Radix1Tree a -> RadixTree a
go Prefix
u x
z' Radix1Tree a
dx
Step Prefix x
Done -> Maybe a -> Radix1Tree a -> RadixTree a
forall a. Maybe a -> Radix1Tree a -> RadixTree a
RadixTree Maybe a
mx Radix1Tree a
dx
else case x -> Step Prefix x
step x
z of
More Prefix
u x
z' -> Prefix -> x -> Int -> RadixTree a
goarr Prefix
u x
z' (Int
n Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1)
Step Prefix x
Done -> let rest :: Radix1Tree a
rest = Int -> ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
forall a.
Int -> ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
dropTrim (Int
n Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1) ByteArray
arr Maybe a
mx Radix1Tree a
dx
in Radix1Tree a
rest Radix1Tree a -> RadixTree a -> RadixTree a
forall a b. a -> b -> b
`seq` Maybe a -> Radix1Tree a -> RadixTree a
forall a. Maybe a -> Radix1Tree a -> RadixTree a
RadixTree Maybe a
forall a. Maybe a
Nothing Radix1Tree a
rest
| Bool
otherwise = Maybe a -> Radix1Tree a -> RadixTree a
forall a. Maybe a -> Radix1Tree a -> RadixTree a
RadixTree Maybe a
forall a. Maybe a
Nothing Radix1Tree a
forall a. Radix1Tree a
Nil
Radix1Tree a
Nil -> Maybe a -> Radix1Tree a -> RadixTree a
forall a. Maybe a -> Radix1Tree a -> RadixTree a
RadixTree Maybe a
forall a. Maybe a
Nothing Radix1Tree a
forall a. Radix1Tree a
Nil
{-# INLINE prefix0 #-}
prefix0 :: Feed -> RadixTree a -> RadixTree a
prefix0 :: forall a. Feed -> RadixTree a -> RadixTree a
prefix0 (Feed forall a. (forall x. (x -> Step Prefix x) -> x -> a) -> a
feed) = \RadixTree a
t ->
(forall x. (x -> Step Prefix x) -> x -> RadixTree a) -> RadixTree a
forall a. (forall x. (x -> Step Prefix x) -> x -> a) -> a
feed ((forall x. (x -> Step Prefix x) -> x -> RadixTree a)
-> RadixTree a)
-> (forall x. (x -> Step Prefix x) -> x -> RadixTree a)
-> RadixTree a
forall a b. (a -> b) -> a -> b
$ \x -> Step Prefix x
step x
s ->
case x -> Step Prefix x
step x
s of
More Prefix
w x
z -> Maybe a -> Radix1Tree a -> RadixTree a
forall a. Maybe a -> Radix1Tree a -> RadixTree a
RadixTree Maybe a
forall a. Maybe a
Nothing (Radix1Tree a -> RadixTree a) -> Radix1Tree a -> RadixTree a
forall a b. (a -> b) -> a -> b
$ (x -> Step Prefix x) -> Prefix -> x -> RadixTree a -> Radix1Tree a
forall x a.
(x -> Step Prefix x) -> Prefix -> x -> RadixTree a -> Radix1Tree a
prefix_ x -> Step Prefix x
step Prefix
w x
z RadixTree a
t
Step Prefix x
Done -> RadixTree a
t
{-# INLINE prefix1 #-}
prefix1 :: Feed1 -> RadixTree a -> Radix1Tree a
prefix1 :: forall a. Feed1 -> RadixTree a -> Radix1Tree a
prefix1 (Feed1 Prefix
w forall a. (forall x. (x -> Step Prefix x) -> x -> a) -> a
feed) =
(forall x.
(x -> Step Prefix x) -> x -> RadixTree a -> Radix1Tree a)
-> RadixTree a -> Radix1Tree a
forall a. (forall x. (x -> Step Prefix x) -> x -> a) -> a
feed ((forall x.
(x -> Step Prefix x) -> x -> RadixTree a -> Radix1Tree a)
-> RadixTree a -> Radix1Tree a)
-> (forall x.
(x -> Step Prefix x) -> x -> RadixTree a -> Radix1Tree a)
-> RadixTree a
-> Radix1Tree a
forall a b. (a -> b) -> a -> b
$ \x -> Step Prefix x
step -> (x -> Step Prefix x) -> Prefix -> x -> RadixTree a -> Radix1Tree a
forall x a.
(x -> Step Prefix x) -> Prefix -> x -> RadixTree a -> Radix1Tree a
prefix_ x -> Step Prefix x
step Prefix
w
{-# INLINE prefix_ #-}
prefix_ :: (x -> Step Word8 x) -> Word8 -> x -> RadixTree a -> Radix1Tree a
prefix_ :: forall x a.
(x -> Step Prefix x) -> Prefix -> x -> RadixTree a -> Radix1Tree a
prefix_ x -> Step Prefix x
step = \Prefix
w x
z (RadixTree Maybe a
mx Radix1Tree a
t) ->
case Maybe a
mx of
Maybe a
Nothing ->
case Radix1Tree a
t of
Bin Prefix
_ Radix1Tree a
_ Radix1Tree a
_ -> ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
Tip ((x -> Step Prefix x) -> Prefix -> x -> ByteArray
forall x. (x -> Step Prefix x) -> Prefix -> x -> ByteArray
fromStep x -> Step Prefix x
step Prefix
w x
z) Maybe a
forall a. Maybe a
Nothing Radix1Tree a
t
Tip ByteArray
arr Maybe a
my Radix1Tree a
dy -> ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
Tip ((x -> Step Prefix x) -> Prefix -> x -> ByteArray -> ByteArray
forall x.
(x -> Step Prefix x) -> Prefix -> x -> ByteArray -> ByteArray
fromStepAppend x -> Step Prefix x
step Prefix
w x
z ByteArray
arr) Maybe a
my Radix1Tree a
dy
Radix1Tree a
Nil -> Radix1Tree a
forall a. Radix1Tree a
Nil
Just a
_ -> ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
Tip ((x -> Step Prefix x) -> Prefix -> x -> ByteArray
forall x. (x -> Step Prefix x) -> Prefix -> x -> ByteArray
fromStep x -> Step Prefix x
step Prefix
w x
z) Maybe a
mx Radix1Tree a
t
data Point =
Seam
| Plane
{-# UNPACK #-} !Int
{-# UNPACK #-} !ByteArray
data Cursor a =
Cursor
{-# UNPACK #-} !Point
{-# UNPACK #-} !(Maybe a)
(Radix1Tree a)
instance Show a => Show (Cursor a) where
showsPrec :: Int -> Cursor a -> ShowS
showsPrec Int
d Cursor a
c =
Bool -> ShowS -> ShowS
showParen (Int
d Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
10) (ShowS -> ShowS) -> ShowS -> ShowS
forall a b. (a -> b) -> a -> b
$
String -> ShowS
showString String
"Cursor " ShowS -> ShowS -> ShowS
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Maybe a -> ShowS
forall a. Show a => Int -> a -> ShowS
showsPrec Int
11 (Cursor a -> Maybe a
forall a. Cursor a -> Maybe a
stop Cursor a
c)
cursor0 :: RadixTree a -> Cursor a
cursor0 :: forall a. RadixTree a -> Cursor a
cursor0 (RadixTree Maybe a
mx Radix1Tree a
t) = Point -> Maybe a -> Radix1Tree a -> Cursor a
forall a. Point -> Maybe a -> Radix1Tree a -> Cursor a
Cursor Point
Seam Maybe a
mx Radix1Tree a
t
cursor1 :: Radix1Tree a -> Cursor a
cursor1 :: forall a. Radix1Tree a -> Cursor a
cursor1 = Point -> Maybe a -> Radix1Tree a -> Cursor a
forall a. Point -> Maybe a -> Radix1Tree a -> Cursor a
Cursor Point
Seam Maybe a
forall a. Maybe a
Nothing
{-# INLINE move0 #-}
move0 :: Feed -> Cursor a -> Cursor a
move0 :: forall a. Feed -> Cursor a -> Cursor a
move0 (Feed forall a. (forall x. (x -> Step Prefix x) -> x -> a) -> a
feed) = \Cursor a
c ->
(forall x. (x -> Step Prefix x) -> x -> Cursor a) -> Cursor a
forall a. (forall x. (x -> Step Prefix x) -> x -> a) -> a
feed ((forall x. (x -> Step Prefix x) -> x -> Cursor a) -> Cursor a)
-> (forall x. (x -> Step Prefix x) -> x -> Cursor a) -> Cursor a
forall a b. (a -> b) -> a -> b
$ \x -> Step Prefix x
step x
s ->
case x -> Step Prefix x
step x
s of
More Prefix
w x
z -> (x -> Step Prefix x) -> Prefix -> x -> Cursor a -> Cursor a
forall x a.
(x -> Step Prefix x) -> Prefix -> x -> Cursor a -> Cursor a
move_ x -> Step Prefix x
step Prefix
w x
z Cursor a
c
Step Prefix x
Done -> Cursor a
c
{-# INLINE move1 #-}
move1 :: Feed1 -> Cursor a -> Cursor a
move1 :: forall a. Feed1 -> Cursor a -> Cursor a
move1 (Feed1 Prefix
w forall a. (forall x. (x -> Step Prefix x) -> x -> a) -> a
feed) = (forall x. (x -> Step Prefix x) -> x -> Cursor a -> Cursor a)
-> Cursor a -> Cursor a
forall a. (forall x. (x -> Step Prefix x) -> x -> a) -> a
feed ((forall x. (x -> Step Prefix x) -> x -> Cursor a -> Cursor a)
-> Cursor a -> Cursor a)
-> (forall x. (x -> Step Prefix x) -> x -> Cursor a -> Cursor a)
-> Cursor a
-> Cursor a
forall a b. (a -> b) -> a -> b
$ \x -> Step Prefix x
step -> (x -> Step Prefix x) -> Prefix -> x -> Cursor a -> Cursor a
forall x a.
(x -> Step Prefix x) -> Prefix -> x -> Cursor a -> Cursor a
move_ x -> Step Prefix x
step Prefix
w
{-# INLINE move_ #-}
move_ :: (x -> Step Word8 x) -> Word8 -> x -> Cursor a -> Cursor a
move_ :: forall x a.
(x -> Step Prefix x) -> Prefix -> x -> Cursor a -> Cursor a
move_ x -> Step Prefix x
step = \Prefix
w x
s (Cursor Point
point Maybe a
mx Radix1Tree a
dx) ->
case Point
point of
Point
Seam -> Prefix -> x -> Radix1Tree a -> Cursor a
go Prefix
w x
s Radix1Tree a
dx
Plane Int
i ByteArray
arr -> ByteArray
-> Maybe a -> Radix1Tree a -> Prefix -> x -> Int -> Cursor a
goarr ByteArray
arr Maybe a
mx Radix1Tree a
dx Prefix
w x
s Int
i
where
go :: Prefix -> x -> Radix1Tree a -> Cursor a
go Prefix
w x
s Radix1Tree a
t =
case Radix1Tree a
t of
Bin Prefix
p Radix1Tree a
l Radix1Tree a
r -> Prefix -> x -> Radix1Tree a -> Cursor a
go Prefix
w x
s (Radix1Tree a -> Cursor a) -> Radix1Tree a -> Cursor a
forall a b. (a -> b) -> a -> b
$ if Prefix
w Prefix -> Prefix -> Bool
forall a. Ord a => a -> a -> Bool
< Prefix
p
then Radix1Tree a
l
else Radix1Tree a
r
Tip ByteArray
brr Maybe a
my Radix1Tree a
dy -> ByteArray
-> Maybe a -> Radix1Tree a -> Prefix -> x -> Int -> Cursor a
goarr ByteArray
brr Maybe a
my Radix1Tree a
dy Prefix
w x
s Int
0
Radix1Tree a
Nil -> Point -> Maybe a -> Radix1Tree a -> Cursor a
forall a. Point -> Maybe a -> Radix1Tree a -> Cursor a
Cursor Point
Seam Maybe a
forall a. Maybe a
Nothing Radix1Tree a
forall a. Radix1Tree a
Nil
goarr :: ByteArray
-> Maybe a -> Radix1Tree a -> Prefix -> x -> Int -> Cursor a
goarr ByteArray
arr Maybe a
mx Radix1Tree a
dx = Prefix -> x -> Int -> Cursor a
goarr_
where
goarr_ :: Prefix -> x -> Int -> Cursor a
goarr_ Prefix
w x
s Int
n
| Prefix
w Prefix -> Prefix -> Bool
forall a. Eq a => a -> a -> Bool
== ByteArray -> Int -> Prefix
forall a. Prim a => ByteArray -> Int -> a
indexByteArray ByteArray
arr Int
n =
let !n' :: Int
n' = Int
n Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1
in case x -> Step Prefix x
step x
s of
More Prefix
v x
z
| Int
n' Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= ByteArray -> Int
sizeofByteArray ByteArray
arr -> Prefix -> x -> Radix1Tree a -> Cursor a
go Prefix
v x
z Radix1Tree a
dx
| Bool
otherwise -> Prefix -> x -> Int -> Cursor a
goarr_ Prefix
v x
z Int
n'
Step Prefix x
Done ->
let !point' :: Point
point'
| Int
n' Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= ByteArray -> Int
sizeofByteArray ByteArray
arr = Point
Seam
| Bool
otherwise = Int -> ByteArray -> Point
Plane Int
n' ByteArray
arr
in Point -> Maybe a -> Radix1Tree a -> Cursor a
forall a. Point -> Maybe a -> Radix1Tree a -> Cursor a
Cursor Point
point' Maybe a
mx Radix1Tree a
dx
| Bool
otherwise = Point -> Maybe a -> Radix1Tree a -> Cursor a
forall a. Point -> Maybe a -> Radix1Tree a -> Cursor a
Cursor Point
Seam Maybe a
forall a. Maybe a
Nothing Radix1Tree a
forall a. Radix1Tree a
Nil
stop :: Cursor a -> Maybe a
stop :: forall a. Cursor a -> Maybe a
stop (Cursor Point
point Maybe a
mx Radix1Tree a
_) =
case Point
point of
Point
Seam -> Maybe a
mx
Point
_ -> Maybe a
forall a. Maybe a
Nothing
locate :: Cursor a -> Location
locate :: forall a. Cursor a -> Location
locate (Cursor Point
_ Maybe a
Nothing Radix1Tree a
Nil) = Location
Outside
locate Cursor a
_ = Location
Inside
{-# INLINE lookupL0 #-}
lookupL0 :: Openness -> Feed -> RadixTree a -> Maybe (Lookup a)
lookupL0 :: forall a. Openness -> Feed -> RadixTree a -> Maybe (Lookup a)
lookupL0 Openness
openness (Feed forall a. (forall x. (x -> Step Prefix x) -> x -> a) -> a
feed) (RadixTree Maybe a
mx Radix1Tree a
t) =
(forall x. (x -> Step Prefix x) -> x -> Maybe (Lookup a))
-> Maybe (Lookup a)
forall a. (forall x. (x -> Step Prefix x) -> x -> a) -> a
feed ((forall x. (x -> Step Prefix x) -> x -> Maybe (Lookup a))
-> Maybe (Lookup a))
-> (forall x. (x -> Step Prefix x) -> x -> Maybe (Lookup a))
-> Maybe (Lookup a)
forall a b. (a -> b) -> a -> b
$ \x -> Step Prefix x
step x
s ->
case x -> Step Prefix x
step x
s of
More Prefix
w x
z ->
let l :: Maybe (Lookup a)
l = (Tsil ByteArray -> ByteArray -> a -> Lookup a)
-> Openness
-> (x -> Step Prefix x)
-> Prefix
-> x
-> Radix1Tree a
-> Maybe (Lookup a)
forall a b x.
(Tsil ByteArray -> ByteArray -> a -> b)
-> Openness
-> (x -> Step Prefix x)
-> Prefix
-> x
-> Radix1Tree a
-> Maybe b
lookupL_ (\Tsil ByteArray
b ByteArray
arr -> Build -> a -> Lookup a
forall a. Build -> a -> Lookup a
Lookup (Tsil ByteArray -> Build
Build (Tsil ByteArray -> Build) -> Tsil ByteArray -> Build
forall a b. (a -> b) -> a -> b
$ Tsil ByteArray -> ByteArray -> Tsil ByteArray
forall a. Tsil a -> a -> Tsil a
Snoc Tsil ByteArray
b ByteArray
arr)) Openness
openness x -> Step Prefix x
step Prefix
w x
z Radix1Tree a
t
in case Maybe (Lookup a)
l of
Just Lookup a
_ -> Maybe (Lookup a)
l
Maybe (Lookup a)
Nothing ->
case Maybe a
mx of
Just a
x -> Lookup a -> Maybe (Lookup a)
forall a. a -> Maybe a
Just (Lookup a -> Maybe (Lookup a)) -> Lookup a -> Maybe (Lookup a)
forall a b. (a -> b) -> a -> b
$ Build -> a -> Lookup a
forall a. Build -> a -> Lookup a
Lookup (Tsil ByteArray -> Build
Build Tsil ByteArray
forall a. Tsil a
Lin) a
x
Maybe a
Nothing -> Maybe (Lookup a)
forall a. Maybe a
Nothing
Step Prefix x
_ ->
case Openness
openness of
Openness
Open -> Maybe (Lookup a)
forall a. Maybe a
Nothing
Openness
Closed -> case Maybe a
mx of
Just a
x -> Lookup a -> Maybe (Lookup a)
forall a. a -> Maybe a
Just (Lookup a -> Maybe (Lookup a)) -> Lookup a -> Maybe (Lookup a)
forall a b. (a -> b) -> a -> b
$ Build -> a -> Lookup a
forall a. Build -> a -> Lookup a
Lookup (Tsil ByteArray -> Build
Build Tsil ByteArray
forall a. Tsil a
Lin) a
x
Maybe a
Nothing -> Maybe (Lookup a)
forall a. Maybe a
Nothing
{-# INLINE lookupL1 #-}
lookupL1 :: Openness -> Feed1 -> Radix1Tree a -> Maybe (Lookup1 a)
lookupL1 :: forall a. Openness -> Feed1 -> Radix1Tree a -> Maybe (Lookup1 a)
lookupL1 Openness
openness (Feed1 Prefix
w forall a. (forall x. (x -> Step Prefix x) -> x -> a) -> a
feed) =
(forall x.
(x -> Step Prefix x) -> x -> Radix1Tree a -> Maybe (Lookup1 a))
-> Radix1Tree a -> Maybe (Lookup1 a)
forall a. (forall x. (x -> Step Prefix x) -> x -> a) -> a
feed ((forall x.
(x -> Step Prefix x) -> x -> Radix1Tree a -> Maybe (Lookup1 a))
-> Radix1Tree a -> Maybe (Lookup1 a))
-> (forall x.
(x -> Step Prefix x) -> x -> Radix1Tree a -> Maybe (Lookup1 a))
-> Radix1Tree a
-> Maybe (Lookup1 a)
forall a b. (a -> b) -> a -> b
$ \x -> Step Prefix x
step -> (Tsil ByteArray -> ByteArray -> a -> Lookup1 a)
-> Openness
-> (x -> Step Prefix x)
-> Prefix
-> x
-> Radix1Tree a
-> Maybe (Lookup1 a)
forall a b x.
(Tsil ByteArray -> ByteArray -> a -> b)
-> Openness
-> (x -> Step Prefix x)
-> Prefix
-> x
-> Radix1Tree a
-> Maybe b
lookupL_ (\Tsil ByteArray
b ByteArray
arr -> Build1 -> a -> Lookup1 a
forall a. Build1 -> a -> Lookup1 a
Lookup1 (YtpmeNon ByteArray -> Build1
Build1 (Tsil ByteArray
b Tsil ByteArray -> ByteArray -> YtpmeNon ByteArray
forall a. Tsil a -> a -> YtpmeNon a
:/ ByteArray
arr))) Openness
openness x -> Step Prefix x
step Prefix
w
{-# INLINE lookupL_ #-}
lookupL_
:: (Tsil ByteArray -> ByteArray -> a -> b)
-> Openness -> (x -> Step Word8 x) -> Word8 -> x -> Radix1Tree a -> Maybe b
lookupL_ :: forall a b x.
(Tsil ByteArray -> ByteArray -> a -> b)
-> Openness
-> (x -> Step Prefix x)
-> Prefix
-> x
-> Radix1Tree a
-> Maybe b
lookupL_ Tsil ByteArray -> ByteArray -> a -> b
f Openness
openness x -> Step Prefix x
step = Tsil ByteArray -> Maybe b -> Prefix -> x -> Radix1Tree a -> Maybe b
go Tsil ByteArray
forall a. Tsil a
Lin Maybe b
forall a. Maybe a
Nothing
where
getMax :: Tsil ByteArray -> Radix1Tree a -> Maybe b
getMax Tsil ByteArray
b Radix1Tree a
t =
let !(# Tsil ByteArray
b', ByteArray
arr, a
a #) = Tsil ByteArray
-> Radix1Tree a -> (# Tsil ByteArray, ByteArray, a #)
forall a.
Tsil ByteArray
-> Radix1Tree a -> (# Tsil ByteArray, ByteArray, a #)
unsafeLookupMaxWithKey_ Tsil ByteArray
b Radix1Tree a
t
in b -> Maybe b
forall a. a -> Maybe a
Just (b -> Maybe b) -> b -> Maybe b
forall a b. (a -> b) -> a -> b
$! Tsil ByteArray -> ByteArray -> a -> b
f Tsil ByteArray
b' ByteArray
arr a
a
go :: Tsil ByteArray -> Maybe b -> Prefix -> x -> Radix1Tree a -> Maybe b
go Tsil ByteArray
b Maybe b
getL !Prefix
w !x
s Radix1Tree a
t =
case Radix1Tree a
t of
Bin Prefix
p Radix1Tree a
l Radix1Tree a
r ->
if Prefix
w Prefix -> Prefix -> Bool
forall a. Ord a => a -> a -> Bool
< Prefix
p
then if Prefix
w Prefix -> Prefix -> Bool
forall a. Ord a => a -> a -> Bool
>= Prefix -> Prefix
lower Prefix
p
then Tsil ByteArray -> Maybe b -> Prefix -> x -> Radix1Tree a -> Maybe b
go Tsil ByteArray
b Maybe b
getL Prefix
w x
s Radix1Tree a
l
else Maybe b
getL
else if Prefix
w Prefix -> Prefix -> Bool
forall a. Ord a => a -> a -> Bool
<= Prefix -> Prefix
upper Prefix
p
then Tsil ByteArray -> Maybe b -> Prefix -> x -> Radix1Tree a -> Maybe b
go Tsil ByteArray
b (Tsil ByteArray -> Radix1Tree a -> Maybe b
getMax Tsil ByteArray
b Radix1Tree a
l) Prefix
w x
s Radix1Tree a
r
else Tsil ByteArray -> Radix1Tree a -> Maybe b
getMax Tsil ByteArray
b Radix1Tree a
r
Tip ByteArray
arr Maybe a
mx Radix1Tree a
dx -> Prefix -> x -> Int -> Maybe b
goarr Prefix
w x
s Int
0
where
getThis :: Maybe b
getThis = Tsil ByteArray -> ByteArray -> a -> b
f Tsil ByteArray
b ByteArray
arr (a -> b) -> Maybe a -> Maybe b
forall a b. (a -> b) -> Maybe a -> Maybe b
`fmap'` Maybe a
mx
goarr :: Prefix -> x -> Int -> Maybe b
goarr Prefix
v x
z Int
n =
let n' :: Int
n' = Int
n Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1
in case ByteArray -> Int -> Prefix
forall a. Prim a => ByteArray -> Int -> a
indexByteArray ByteArray
arr Int
n Prefix -> Prefix -> Ordering
forall a. Ord a => a -> a -> Ordering
`compare` Prefix
v of
Ordering
EQ | Int
n' Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= ByteArray -> Int
sizeofByteArray ByteArray
arr ->
let getL' :: Maybe b
getL' = Maybe b
getThis Maybe b -> Maybe b -> Maybe b
forall a. Maybe a -> Maybe a -> Maybe a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Maybe b
getL
in case x -> Step Prefix x
step x
z of
More Prefix
u x
z' -> Tsil ByteArray -> Maybe b -> Prefix -> x -> Radix1Tree a -> Maybe b
go (Tsil ByteArray -> ByteArray -> Tsil ByteArray
forall a. Tsil a -> a -> Tsil a
Snoc Tsil ByteArray
b ByteArray
arr) Maybe b
getL' Prefix
u x
z' Radix1Tree a
dx
Step Prefix x
Done ->
case Openness
openness of
Openness
Open -> Maybe b
getL
Openness
Closed -> Maybe b
getL'
| Bool
otherwise ->
case x -> Step Prefix x
step x
z of
More Prefix
u x
z' -> Prefix -> x -> Int -> Maybe b
goarr Prefix
u x
z' Int
n'
Step Prefix x
Done -> Maybe b
getL
Ordering
LT -> case Radix1Tree a
dx of
Radix1Tree a
Nil -> Maybe b
getThis
Radix1Tree a
_ -> Tsil ByteArray -> Radix1Tree a -> Maybe b
getMax (Tsil ByteArray -> ByteArray -> Tsil ByteArray
forall a. Tsil a -> a -> Tsil a
Snoc Tsil ByteArray
b ByteArray
arr) Radix1Tree a
dx
Ordering
GT -> Maybe b
getL
Radix1Tree a
Nil -> Maybe b
getL
{-# INLINE lookupR0 #-}
lookupR0 :: Openness -> Feed -> RadixTree a -> Maybe (Lookup a)
lookupR0 :: forall a. Openness -> Feed -> RadixTree a -> Maybe (Lookup a)
lookupR0 Openness
openness (Feed forall a. (forall x. (x -> Step Prefix x) -> x -> a) -> a
feed) = \(RadixTree Maybe a
mx Radix1Tree a
t) ->
(forall x. (x -> Step Prefix x) -> x -> Maybe (Lookup a))
-> Maybe (Lookup a)
forall a. (forall x. (x -> Step Prefix x) -> x -> a) -> a
feed ((forall x. (x -> Step Prefix x) -> x -> Maybe (Lookup a))
-> Maybe (Lookup a))
-> (forall x. (x -> Step Prefix x) -> x -> Maybe (Lookup a))
-> Maybe (Lookup a)
forall a b. (a -> b) -> a -> b
$ \x -> Step Prefix x
step x
s ->
case x -> Step Prefix x
step x
s of
More Prefix
w x
z ->
(Tsil ByteArray -> ByteArray -> a -> Lookup a)
-> Openness
-> (x -> Step Prefix x)
-> Prefix
-> x
-> Radix1Tree a
-> Maybe (Lookup a)
forall a b x.
(Tsil ByteArray -> ByteArray -> a -> b)
-> Openness
-> (x -> Step Prefix x)
-> Prefix
-> x
-> Radix1Tree a
-> Maybe b
lookupR_ (\Tsil ByteArray
b ByteArray
arr -> Build -> a -> Lookup a
forall a. Build -> a -> Lookup a
Lookup (Tsil ByteArray -> Build
Build (Tsil ByteArray -> Build) -> Tsil ByteArray -> Build
forall a b. (a -> b) -> a -> b
$ Tsil ByteArray -> ByteArray -> Tsil ByteArray
forall a. Tsil a -> a -> Tsil a
Snoc Tsil ByteArray
b ByteArray
arr)) Openness
openness x -> Step Prefix x
step Prefix
w x
z Radix1Tree a
t
Step Prefix x
_ ->
case Openness
openness of
Openness
Closed | Just a
x <- Maybe a
mx -> Lookup a -> Maybe (Lookup a)
forall a. a -> Maybe a
Just (Lookup a -> Maybe (Lookup a)) -> Lookup a -> Maybe (Lookup a)
forall a b. (a -> b) -> a -> b
$ Build -> a -> Lookup a
forall a. Build -> a -> Lookup a
Lookup (Tsil ByteArray -> Build
Build Tsil ByteArray
forall a. Tsil a
Lin) a
x
Openness
_ -> case Radix1Tree a
t of
Radix1Tree a
Nil -> Maybe (Lookup a)
forall a. Maybe a
Nothing
Radix1Tree a
_ -> let !(# Tsil ByteArray
b, ByteArray
arr, a
x #) = Tsil ByteArray
-> Radix1Tree a -> (# Tsil ByteArray, ByteArray, a #)
forall a.
Tsil ByteArray
-> Radix1Tree a -> (# Tsil ByteArray, ByteArray, a #)
unsafeLookupMinWithKey_ Tsil ByteArray
forall a. Tsil a
Lin Radix1Tree a
t
in Lookup a -> Maybe (Lookup a)
forall a. a -> Maybe a
Just (Lookup a -> Maybe (Lookup a)) -> Lookup a -> Maybe (Lookup a)
forall a b. (a -> b) -> a -> b
$! Build -> a -> Lookup a
forall a. Build -> a -> Lookup a
Lookup (Tsil ByteArray -> Build
Build (Tsil ByteArray -> Build) -> Tsil ByteArray -> Build
forall a b. (a -> b) -> a -> b
$ Tsil ByteArray -> ByteArray -> Tsil ByteArray
forall a. Tsil a -> a -> Tsil a
Snoc Tsil ByteArray
b ByteArray
arr) a
x
{-# INLINE lookupR1 #-}
lookupR1 :: Openness -> Feed1 -> Radix1Tree a -> Maybe (Lookup1 a)
lookupR1 :: forall a. Openness -> Feed1 -> Radix1Tree a -> Maybe (Lookup1 a)
lookupR1 Openness
openness (Feed1 Prefix
w forall a. (forall x. (x -> Step Prefix x) -> x -> a) -> a
feed) =
(forall x.
(x -> Step Prefix x) -> x -> Radix1Tree a -> Maybe (Lookup1 a))
-> Radix1Tree a -> Maybe (Lookup1 a)
forall a. (forall x. (x -> Step Prefix x) -> x -> a) -> a
feed ((forall x.
(x -> Step Prefix x) -> x -> Radix1Tree a -> Maybe (Lookup1 a))
-> Radix1Tree a -> Maybe (Lookup1 a))
-> (forall x.
(x -> Step Prefix x) -> x -> Radix1Tree a -> Maybe (Lookup1 a))
-> Radix1Tree a
-> Maybe (Lookup1 a)
forall a b. (a -> b) -> a -> b
$ \x -> Step Prefix x
step -> (Tsil ByteArray -> ByteArray -> a -> Lookup1 a)
-> Openness
-> (x -> Step Prefix x)
-> Prefix
-> x
-> Radix1Tree a
-> Maybe (Lookup1 a)
forall a b x.
(Tsil ByteArray -> ByteArray -> a -> b)
-> Openness
-> (x -> Step Prefix x)
-> Prefix
-> x
-> Radix1Tree a
-> Maybe b
lookupR_ (\Tsil ByteArray
b ByteArray
arr -> Build1 -> a -> Lookup1 a
forall a. Build1 -> a -> Lookup1 a
Lookup1 (YtpmeNon ByteArray -> Build1
Build1 (Tsil ByteArray
b Tsil ByteArray -> ByteArray -> YtpmeNon ByteArray
forall a. Tsil a -> a -> YtpmeNon a
:/ ByteArray
arr))) Openness
openness x -> Step Prefix x
step Prefix
w
{-# INLINE lookupR_ #-}
lookupR_
:: (Tsil ByteArray -> ByteArray -> a -> b)
-> Openness -> (x -> Step Word8 x) -> Word8 -> x -> Radix1Tree a -> Maybe b
lookupR_ :: forall a b x.
(Tsil ByteArray -> ByteArray -> a -> b)
-> Openness
-> (x -> Step Prefix x)
-> Prefix
-> x
-> Radix1Tree a
-> Maybe b
lookupR_ Tsil ByteArray -> ByteArray -> a -> b
f Openness
openness x -> Step Prefix x
step = Tsil ByteArray -> Maybe b -> Prefix -> x -> Radix1Tree a -> Maybe b
go Tsil ByteArray
forall a. Tsil a
Lin Maybe b
forall a. Maybe a
Nothing
where
getMin :: Tsil ByteArray -> Radix1Tree a -> Maybe b
getMin Tsil ByteArray
b Radix1Tree a
t =
let !(# Tsil ByteArray
b', ByteArray
arr, a
a #) = Tsil ByteArray
-> Radix1Tree a -> (# Tsil ByteArray, ByteArray, a #)
forall a.
Tsil ByteArray
-> Radix1Tree a -> (# Tsil ByteArray, ByteArray, a #)
unsafeLookupMinWithKey_ Tsil ByteArray
b Radix1Tree a
t
in b -> Maybe b
forall a. a -> Maybe a
Just (b -> Maybe b) -> b -> Maybe b
forall a b. (a -> b) -> a -> b
$! Tsil ByteArray -> ByteArray -> a -> b
f Tsil ByteArray
b' ByteArray
arr a
a
go :: Tsil ByteArray -> Maybe b -> Prefix -> x -> Radix1Tree a -> Maybe b
go Tsil ByteArray
b Maybe b
getR Prefix
w x
s Radix1Tree a
t =
case Radix1Tree a
t of
Bin Prefix
p Radix1Tree a
l Radix1Tree a
r ->
if Prefix
w Prefix -> Prefix -> Bool
forall a. Ord a => a -> a -> Bool
< Prefix
p
then if Prefix
w Prefix -> Prefix -> Bool
forall a. Ord a => a -> a -> Bool
>= Prefix -> Prefix
lower Prefix
p
then Tsil ByteArray -> Maybe b -> Prefix -> x -> Radix1Tree a -> Maybe b
go Tsil ByteArray
b (Tsil ByteArray -> Radix1Tree a -> Maybe b
getMin Tsil ByteArray
b Radix1Tree a
r) Prefix
w x
s Radix1Tree a
l
else Tsil ByteArray -> Radix1Tree a -> Maybe b
getMin Tsil ByteArray
b Radix1Tree a
l
else if Prefix
w Prefix -> Prefix -> Bool
forall a. Ord a => a -> a -> Bool
<= Prefix -> Prefix
upper Prefix
p
then Tsil ByteArray -> Maybe b -> Prefix -> x -> Radix1Tree a -> Maybe b
go Tsil ByteArray
b Maybe b
getR Prefix
w x
s Radix1Tree a
r
else Maybe b
getR
Tip ByteArray
arr Maybe a
mx Radix1Tree a
dx -> Prefix -> x -> Int -> Maybe b
goarr Prefix
w x
s Int
0
where
getThis :: Maybe b
getThis = Tsil ByteArray -> ByteArray -> a -> b
f Tsil ByteArray
b ByteArray
arr (a -> b) -> Maybe a -> Maybe b
forall a b. (a -> b) -> Maybe a -> Maybe b
`fmap'` Maybe a
mx
getBelow :: Maybe b
getBelow =
case Radix1Tree a
dx of
Radix1Tree a
Nil -> Maybe b
forall a. Maybe a
Nothing
Radix1Tree a
_ -> Tsil ByteArray -> Radix1Tree a -> Maybe b
getMin (Tsil ByteArray -> ByteArray -> Tsil ByteArray
forall a. Tsil a -> a -> Tsil a
Snoc Tsil ByteArray
b ByteArray
arr) Radix1Tree a
dx
goarr :: Prefix -> x -> Int -> Maybe b
goarr Prefix
v x
z Int
n =
let n' :: Int
n' = Int
n Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1
in case ByteArray -> Int -> Prefix
forall a. Prim a => ByteArray -> Int -> a
indexByteArray ByteArray
arr Int
n Prefix -> Prefix -> Ordering
forall a. Ord a => a -> a -> Ordering
`compare` Prefix
v of
Ordering
EQ | Int
n' Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= ByteArray -> Int
sizeofByteArray ByteArray
arr ->
case x -> Step Prefix x
step x
z of
More Prefix
u x
z' -> Tsil ByteArray -> Maybe b -> Prefix -> x -> Radix1Tree a -> Maybe b
go (Tsil ByteArray -> ByteArray -> Tsil ByteArray
forall a. Tsil a -> a -> Tsil a
Snoc Tsil ByteArray
b ByteArray
arr) Maybe b
getR Prefix
u x
z' Radix1Tree a
dx
Step Prefix x
Done ->
( case Openness
openness of
Openness
Open -> Maybe b
getBelow
Openness
Closed -> Maybe b
getThis Maybe b -> Maybe b -> Maybe b
forall a. Maybe a -> Maybe a -> Maybe a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Maybe b
getBelow
)
Maybe b -> Maybe b -> Maybe b
forall a. Maybe a -> Maybe a -> Maybe a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Maybe b
getR
| Bool
otherwise ->
case x -> Step Prefix x
step x
z of
More Prefix
u x
z' -> Prefix -> x -> Int -> Maybe b
goarr Prefix
u x
z' Int
n'
Step Prefix x
Done -> (Maybe b
getThis Maybe b -> Maybe b -> Maybe b
forall a. Maybe a -> Maybe a -> Maybe a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Maybe b
getBelow) Maybe b -> Maybe b -> Maybe b
forall a. Maybe a -> Maybe a -> Maybe a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Maybe b
getR
Ordering
GT -> Maybe b
getThis Maybe b -> Maybe b -> Maybe b
forall a. Maybe a -> Maybe a -> Maybe a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Maybe b
getBelow
Ordering
LT -> Maybe b
getR
Radix1Tree a
Nil -> Maybe b
getR
{-# INLINE adjustL0 #-}
adjustL0 :: (a -> a) -> Openness -> Feed -> RadixTree a -> RadixTree a
adjustL0 :: forall a.
(a -> a) -> Openness -> Feed -> RadixTree a -> RadixTree a
adjustL0 a -> a
f Openness
openness (Feed forall a. (forall x. (x -> Step Prefix x) -> x -> a) -> a
feed) = \t0 :: RadixTree a
t0@(RadixTree Maybe a
mx Radix1Tree a
t) ->
(forall x. (x -> Step Prefix x) -> x -> RadixTree a) -> RadixTree a
forall a. (forall x. (x -> Step Prefix x) -> x -> a) -> a
feed ((forall x. (x -> Step Prefix x) -> x -> RadixTree a)
-> RadixTree a)
-> (forall x. (x -> Step Prefix x) -> x -> RadixTree a)
-> RadixTree a
forall a b. (a -> b) -> a -> b
$ \x -> Step Prefix x
step x
s ->
case x -> Step Prefix x
step x
s of
More Prefix
w x
z -> Maybe a -> Radix1Tree a -> RadixTree a
forall a. Maybe a -> Radix1Tree a -> RadixTree a
RadixTree (a -> a
f (a -> a) -> Maybe a -> Maybe a
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe a
mx) (Radix1Tree a -> RadixTree a) -> Radix1Tree a -> RadixTree a
forall a b. (a -> b) -> a -> b
$ (a -> a)
-> Openness
-> (x -> Step Prefix x)
-> Prefix
-> x
-> Radix1Tree a
-> Radix1Tree a
forall a x.
(a -> a)
-> Openness
-> (x -> Step Prefix x)
-> Prefix
-> x
-> Radix1Tree a
-> Radix1Tree a
adjustL_ a -> a
f Openness
openness x -> Step Prefix x
step Prefix
w x
z Radix1Tree a
t
Step Prefix x
Done ->
case Openness
openness of
Openness
Open -> RadixTree a
t0
Openness
Closed -> case Maybe a
mx of
Just a
x -> Maybe a -> Radix1Tree a -> RadixTree a
forall a. Maybe a -> Radix1Tree a -> RadixTree a
RadixTree (a -> Maybe a
forall a. a -> Maybe a
Just (a -> Maybe a) -> a -> Maybe a
forall a b. (a -> b) -> a -> b
$ a -> a
f a
x) Radix1Tree a
t
Maybe a
Nothing -> RadixTree a
t0
{-# INLINE adjustL1 #-}
adjustL1 :: (a -> a) -> Openness -> Feed1 -> Radix1Tree a -> Radix1Tree a
adjustL1 :: forall a.
(a -> a) -> Openness -> Feed1 -> Radix1Tree a -> Radix1Tree a
adjustL1 a -> a
f Openness
openness (Feed1 Prefix
w forall a. (forall x. (x -> Step Prefix x) -> x -> a) -> a
feed) =
(forall x.
(x -> Step Prefix x) -> x -> Radix1Tree a -> Radix1Tree a)
-> Radix1Tree a -> Radix1Tree a
forall a. (forall x. (x -> Step Prefix x) -> x -> a) -> a
feed ((forall x.
(x -> Step Prefix x) -> x -> Radix1Tree a -> Radix1Tree a)
-> Radix1Tree a -> Radix1Tree a)
-> (forall x.
(x -> Step Prefix x) -> x -> Radix1Tree a -> Radix1Tree a)
-> Radix1Tree a
-> Radix1Tree a
forall a b. (a -> b) -> a -> b
$ \x -> Step Prefix x
step -> (a -> a)
-> Openness
-> (x -> Step Prefix x)
-> Prefix
-> x
-> Radix1Tree a
-> Radix1Tree a
forall a x.
(a -> a)
-> Openness
-> (x -> Step Prefix x)
-> Prefix
-> x
-> Radix1Tree a
-> Radix1Tree a
adjustL_ a -> a
f Openness
openness x -> Step Prefix x
step Prefix
w
{-# INLINE adjustL_ #-}
adjustL_
:: (a -> a) -> Openness -> (x -> Step Word8 x)
-> Word8 -> x -> Radix1Tree a -> Radix1Tree a
adjustL_ :: forall a x.
(a -> a)
-> Openness
-> (x -> Step Prefix x)
-> Prefix
-> x
-> Radix1Tree a
-> Radix1Tree a
adjustL_ a -> a
f Openness
openness x -> Step Prefix x
step = Prefix -> x -> Radix1Tree a -> Radix1Tree a
go
where
go :: Prefix -> x -> Radix1Tree a -> Radix1Tree a
go Prefix
w x
s Radix1Tree a
t =
case Radix1Tree a
t of
Bin Prefix
p Radix1Tree a
l Radix1Tree a
r ->
if Prefix
w Prefix -> Prefix -> Bool
forall a. Ord a => a -> a -> Bool
< Prefix
p
then if Prefix
w Prefix -> Prefix -> Bool
forall a. Ord a => a -> a -> Bool
>= Prefix -> Prefix
lower Prefix
p
then Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
forall a. Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
Bin Prefix
p (Prefix -> x -> Radix1Tree a -> Radix1Tree a
go Prefix
w x
s Radix1Tree a
l) Radix1Tree a
r
else Radix1Tree a
t
else if Prefix
w Prefix -> Prefix -> Bool
forall a. Ord a => a -> a -> Bool
<= Prefix -> Prefix
upper Prefix
p
then Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
forall a. Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
Bin Prefix
p ((a -> a) -> Radix1Tree a -> Radix1Tree a
forall a b. (a -> b) -> Radix1Tree a -> Radix1Tree b
map1 a -> a
f Radix1Tree a
l) (Prefix -> x -> Radix1Tree a -> Radix1Tree a
go Prefix
w x
s Radix1Tree a
r)
else (a -> a) -> Radix1Tree a -> Radix1Tree a
forall a b. (a -> b) -> Radix1Tree a -> Radix1Tree b
map1 a -> a
f Radix1Tree a
t
Tip ByteArray
arr Maybe a
mx Radix1Tree a
dx -> Prefix -> x -> Int -> Radix1Tree a
goarr Prefix
w x
s Int
0
where
goarr :: Prefix -> x -> Int -> Radix1Tree a
goarr Prefix
v x
z Int
n =
let n' :: Int
n' = Int
n Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1
in case ByteArray -> Int -> Prefix
forall a. Prim a => ByteArray -> Int -> a
indexByteArray ByteArray
arr Int
n Prefix -> Prefix -> Ordering
forall a. Ord a => a -> a -> Ordering
`compare` Prefix
v of
Ordering
EQ | Int
n' Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= ByteArray -> Int
sizeofByteArray ByteArray
arr ->
case x -> Step Prefix x
step x
z of
More Prefix
u x
z' -> ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
Tip ByteArray
arr (a -> a
f (a -> a) -> Maybe a -> Maybe a
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe a
mx) (Radix1Tree a -> Radix1Tree a) -> Radix1Tree a -> Radix1Tree a
forall a b. (a -> b) -> a -> b
$ Prefix -> x -> Radix1Tree a -> Radix1Tree a
go Prefix
u x
z' Radix1Tree a
dx
Step Prefix x
Done ->
let my :: Maybe a
my = case Openness
openness of
Openness
Open -> Maybe a
mx
Openness
Closed -> a -> a
f (a -> a) -> Maybe a -> Maybe a
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe a
mx
in ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
Tip ByteArray
arr Maybe a
my Radix1Tree a
dx
| Bool
otherwise ->
case x -> Step Prefix x
step x
z of
More Prefix
u x
z' -> Prefix -> x -> Int -> Radix1Tree a
goarr Prefix
u x
z' Int
n'
Step Prefix x
Done -> Radix1Tree a
t
Ordering
LT -> (a -> a) -> Radix1Tree a -> Radix1Tree a
forall a b. (a -> b) -> Radix1Tree a -> Radix1Tree b
map1 a -> a
f Radix1Tree a
t
Ordering
GT -> Radix1Tree a
t
Radix1Tree a
Nil -> Radix1Tree a
forall a. Radix1Tree a
Nil
{-# INLINE adjustLWithKey0 #-}
adjustLWithKey0 :: (Build -> a -> a) -> Openness -> Feed -> RadixTree a -> RadixTree a
adjustLWithKey0 :: forall a.
(Build -> a -> a) -> Openness -> Feed -> RadixTree a -> RadixTree a
adjustLWithKey0 Build -> a -> a
f Openness
openness (Feed forall a. (forall x. (x -> Step Prefix x) -> x -> a) -> a
feed) = \t0 :: RadixTree a
t0@(RadixTree Maybe a
mx Radix1Tree a
t) ->
(forall x. (x -> Step Prefix x) -> x -> RadixTree a) -> RadixTree a
forall a. (forall x. (x -> Step Prefix x) -> x -> a) -> a
feed ((forall x. (x -> Step Prefix x) -> x -> RadixTree a)
-> RadixTree a)
-> (forall x. (x -> Step Prefix x) -> x -> RadixTree a)
-> RadixTree a
forall a b. (a -> b) -> a -> b
$ \x -> Step Prefix x
step x
s ->
case x -> Step Prefix x
step x
s of
More Prefix
w x
z -> Maybe a -> Radix1Tree a -> RadixTree a
forall a. Maybe a -> Radix1Tree a -> RadixTree a
RadixTree (Build -> a -> a
f (Tsil ByteArray -> Build
Build Tsil ByteArray
forall a. Tsil a
Lin) (a -> a) -> Maybe a -> Maybe a
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe a
mx) (Radix1Tree a -> RadixTree a) -> Radix1Tree a -> RadixTree a
forall a b. (a -> b) -> a -> b
$
(Tsil ByteArray -> ByteArray -> a -> a)
-> Openness
-> (x -> Step Prefix x)
-> Prefix
-> x
-> Radix1Tree a
-> Radix1Tree a
forall a x.
(Tsil ByteArray -> ByteArray -> a -> a)
-> Openness
-> (x -> Step Prefix x)
-> Prefix
-> x
-> Radix1Tree a
-> Radix1Tree a
adjustLWithKey_ (\Tsil ByteArray
b ByteArray
arr -> Build -> a -> a
f (Tsil ByteArray -> Build
Build (Tsil ByteArray -> Build) -> Tsil ByteArray -> Build
forall a b. (a -> b) -> a -> b
$ Tsil ByteArray -> ByteArray -> Tsil ByteArray
forall a. Tsil a -> a -> Tsil a
Snoc Tsil ByteArray
b ByteArray
arr)) Openness
openness x -> Step Prefix x
step Prefix
w x
z Radix1Tree a
t
Step Prefix x
Done ->
case Openness
openness of
Openness
Open -> RadixTree a
t0
Openness
Closed -> Maybe a -> Radix1Tree a -> RadixTree a
forall a. Maybe a -> Radix1Tree a -> RadixTree a
RadixTree (Build -> a -> a
f (Tsil ByteArray -> Build
Build Tsil ByteArray
forall a. Tsil a
Lin) (a -> a) -> Maybe a -> Maybe a
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe a
mx) Radix1Tree a
t
{-# INLINE adjustLWithKey1 #-}
adjustLWithKey1 :: (Build1 -> a -> a) -> Openness -> Feed1 -> Radix1Tree a -> Radix1Tree a
adjustLWithKey1 :: forall a.
(Build1 -> a -> a)
-> Openness -> Feed1 -> Radix1Tree a -> Radix1Tree a
adjustLWithKey1 Build1 -> a -> a
f Openness
openness (Feed1 Prefix
w forall a. (forall x. (x -> Step Prefix x) -> x -> a) -> a
feed) =
(forall x.
(x -> Step Prefix x) -> x -> Radix1Tree a -> Radix1Tree a)
-> Radix1Tree a -> Radix1Tree a
forall a. (forall x. (x -> Step Prefix x) -> x -> a) -> a
feed ((forall x.
(x -> Step Prefix x) -> x -> Radix1Tree a -> Radix1Tree a)
-> Radix1Tree a -> Radix1Tree a)
-> (forall x.
(x -> Step Prefix x) -> x -> Radix1Tree a -> Radix1Tree a)
-> Radix1Tree a
-> Radix1Tree a
forall a b. (a -> b) -> a -> b
$ \x -> Step Prefix x
step -> (Tsil ByteArray -> ByteArray -> a -> a)
-> Openness
-> (x -> Step Prefix x)
-> Prefix
-> x
-> Radix1Tree a
-> Radix1Tree a
forall a x.
(Tsil ByteArray -> ByteArray -> a -> a)
-> Openness
-> (x -> Step Prefix x)
-> Prefix
-> x
-> Radix1Tree a
-> Radix1Tree a
adjustLWithKey_ (\Tsil ByteArray
b ByteArray
arr -> Build1 -> a -> a
f (YtpmeNon ByteArray -> Build1
Build1 (YtpmeNon ByteArray -> Build1) -> YtpmeNon ByteArray -> Build1
forall a b. (a -> b) -> a -> b
$ Tsil ByteArray
b Tsil ByteArray -> ByteArray -> YtpmeNon ByteArray
forall a. Tsil a -> a -> YtpmeNon a
:/ ByteArray
arr)) Openness
openness x -> Step Prefix x
step Prefix
w
{-# INLINE adjustLWithKey_ #-}
adjustLWithKey_
:: (Tsil ByteArray -> ByteArray -> a -> a) -> Openness -> (x -> Step Word8 x)
-> Word8 -> x -> Radix1Tree a -> Radix1Tree a
adjustLWithKey_ :: forall a x.
(Tsil ByteArray -> ByteArray -> a -> a)
-> Openness
-> (x -> Step Prefix x)
-> Prefix
-> x
-> Radix1Tree a
-> Radix1Tree a
adjustLWithKey_ Tsil ByteArray -> ByteArray -> a -> a
f Openness
openness x -> Step Prefix x
step = Tsil ByteArray -> Prefix -> x -> Radix1Tree a -> Radix1Tree a
go Tsil ByteArray
forall a. Tsil a
Lin
where
go :: Tsil ByteArray -> Prefix -> x -> Radix1Tree a -> Radix1Tree a
go Tsil ByteArray
b Prefix
w x
s Radix1Tree a
t =
case Radix1Tree a
t of
Bin Prefix
p Radix1Tree a
l Radix1Tree a
r ->
if Prefix
w Prefix -> Prefix -> Bool
forall a. Ord a => a -> a -> Bool
< Prefix
p
then if Prefix
w Prefix -> Prefix -> Bool
forall a. Ord a => a -> a -> Bool
>= Prefix -> Prefix
lower Prefix
p
then Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
forall a. Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
Bin Prefix
p (Tsil ByteArray -> Prefix -> x -> Radix1Tree a -> Radix1Tree a
go Tsil ByteArray
b Prefix
w x
s Radix1Tree a
l) Radix1Tree a
r
else Radix1Tree a
t
else if Prefix
w Prefix -> Prefix -> Bool
forall a. Ord a => a -> a -> Bool
<= Prefix -> Prefix
upper Prefix
p
then Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
forall a. Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
Bin Prefix
p ((Tsil ByteArray -> ByteArray -> a -> a)
-> Tsil ByteArray -> Radix1Tree a -> Radix1Tree a
forall a b.
(Tsil ByteArray -> ByteArray -> a -> b)
-> Tsil ByteArray -> Radix1Tree a -> Radix1Tree b
mapWithKey_ Tsil ByteArray -> ByteArray -> a -> a
f Tsil ByteArray
b Radix1Tree a
l) (Tsil ByteArray -> Prefix -> x -> Radix1Tree a -> Radix1Tree a
go Tsil ByteArray
b Prefix
w x
s Radix1Tree a
r)
else (Tsil ByteArray -> ByteArray -> a -> a)
-> Tsil ByteArray -> Radix1Tree a -> Radix1Tree a
forall a b.
(Tsil ByteArray -> ByteArray -> a -> b)
-> Tsil ByteArray -> Radix1Tree a -> Radix1Tree b
mapWithKey_ Tsil ByteArray -> ByteArray -> a -> a
f Tsil ByteArray
b Radix1Tree a
t
Tip ByteArray
arr Maybe a
mx Radix1Tree a
dx -> Prefix -> x -> Int -> Radix1Tree a
goarr Prefix
w x
s Int
0
where
goarr :: Prefix -> x -> Int -> Radix1Tree a
goarr Prefix
v x
z Int
n =
let n' :: Int
n' = Int
n Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1
in case ByteArray -> Int -> Prefix
forall a. Prim a => ByteArray -> Int -> a
indexByteArray ByteArray
arr Int
n Prefix -> Prefix -> Ordering
forall a. Ord a => a -> a -> Ordering
`compare` Prefix
v of
Ordering
EQ | Int
n' Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= ByteArray -> Int
sizeofByteArray ByteArray
arr ->
case x -> Step Prefix x
step x
z of
More Prefix
u x
z' -> ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
Tip ByteArray
arr (Tsil ByteArray -> ByteArray -> a -> a
f Tsil ByteArray
b ByteArray
arr (a -> a) -> Maybe a -> Maybe a
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe a
mx) (Radix1Tree a -> Radix1Tree a) -> Radix1Tree a -> Radix1Tree a
forall a b. (a -> b) -> a -> b
$
Tsil ByteArray -> Prefix -> x -> Radix1Tree a -> Radix1Tree a
go (Tsil ByteArray -> ByteArray -> Tsil ByteArray
forall a. Tsil a -> a -> Tsil a
Snoc Tsil ByteArray
b ByteArray
arr) Prefix
u x
z' Radix1Tree a
dx
Step Prefix x
Done ->
let my :: Maybe a
my = case Openness
openness of
Openness
Open -> Maybe a
mx
Openness
Closed -> Tsil ByteArray -> ByteArray -> a -> a
f Tsil ByteArray
b ByteArray
arr (a -> a) -> Maybe a -> Maybe a
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe a
mx
in ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
Tip ByteArray
arr Maybe a
my Radix1Tree a
dx
| Bool
otherwise ->
case x -> Step Prefix x
step x
z of
More Prefix
u x
z' -> Prefix -> x -> Int -> Radix1Tree a
goarr Prefix
u x
z' Int
n'
Step Prefix x
Done -> Radix1Tree a
t
Ordering
LT -> (Tsil ByteArray -> ByteArray -> a -> a)
-> Tsil ByteArray -> Radix1Tree a -> Radix1Tree a
forall a b.
(Tsil ByteArray -> ByteArray -> a -> b)
-> Tsil ByteArray -> Radix1Tree a -> Radix1Tree b
mapWithKey_ Tsil ByteArray -> ByteArray -> a -> a
f Tsil ByteArray
b Radix1Tree a
t
Ordering
GT -> Radix1Tree a
t
Radix1Tree a
Nil -> Radix1Tree a
forall a. Radix1Tree a
Nil
{-# INLINE adjustR0 #-}
adjustR0 :: (a -> a) -> Openness -> Feed -> RadixTree a -> RadixTree a
adjustR0 :: forall a.
(a -> a) -> Openness -> Feed -> RadixTree a -> RadixTree a
adjustR0 a -> a
f Openness
openness (Feed forall a. (forall x. (x -> Step Prefix x) -> x -> a) -> a
feed) = \(RadixTree Maybe a
mx Radix1Tree a
t) ->
(forall x. (x -> Step Prefix x) -> x -> RadixTree a) -> RadixTree a
forall a. (forall x. (x -> Step Prefix x) -> x -> a) -> a
feed ((forall x. (x -> Step Prefix x) -> x -> RadixTree a)
-> RadixTree a)
-> (forall x. (x -> Step Prefix x) -> x -> RadixTree a)
-> RadixTree a
forall a b. (a -> b) -> a -> b
$ \x -> Step Prefix x
step x
s ->
case x -> Step Prefix x
step x
s of
More Prefix
w x
z -> Maybe a -> Radix1Tree a -> RadixTree a
forall a. Maybe a -> Radix1Tree a -> RadixTree a
RadixTree Maybe a
mx (Radix1Tree a -> RadixTree a) -> Radix1Tree a -> RadixTree a
forall a b. (a -> b) -> a -> b
$ (a -> a)
-> Openness
-> (x -> Step Prefix x)
-> Prefix
-> x
-> Radix1Tree a
-> Radix1Tree a
forall a x.
(a -> a)
-> Openness
-> (x -> Step Prefix x)
-> Prefix
-> x
-> Radix1Tree a
-> Radix1Tree a
adjustR_ a -> a
f Openness
openness x -> Step Prefix x
step Prefix
w x
z Radix1Tree a
t
Step Prefix x
Done ->
let my :: Maybe a
my = case Openness
openness of
Openness
Open -> Maybe a
mx
Openness
Closed -> a -> a
f (a -> a) -> Maybe a -> Maybe a
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe a
mx
in Maybe a -> Radix1Tree a -> RadixTree a
forall a. Maybe a -> Radix1Tree a -> RadixTree a
RadixTree Maybe a
my ((a -> a) -> Radix1Tree a -> Radix1Tree a
forall a b. (a -> b) -> Radix1Tree a -> Radix1Tree b
map1 a -> a
f Radix1Tree a
t)
{-# INLINE adjustR1 #-}
adjustR1 :: (a -> a) -> Openness -> Feed1 -> Radix1Tree a -> Radix1Tree a
adjustR1 :: forall a.
(a -> a) -> Openness -> Feed1 -> Radix1Tree a -> Radix1Tree a
adjustR1 a -> a
f Openness
openness (Feed1 Prefix
w forall a. (forall x. (x -> Step Prefix x) -> x -> a) -> a
feed) =
(forall x.
(x -> Step Prefix x) -> x -> Radix1Tree a -> Radix1Tree a)
-> Radix1Tree a -> Radix1Tree a
forall a. (forall x. (x -> Step Prefix x) -> x -> a) -> a
feed ((forall x.
(x -> Step Prefix x) -> x -> Radix1Tree a -> Radix1Tree a)
-> Radix1Tree a -> Radix1Tree a)
-> (forall x.
(x -> Step Prefix x) -> x -> Radix1Tree a -> Radix1Tree a)
-> Radix1Tree a
-> Radix1Tree a
forall a b. (a -> b) -> a -> b
$ \x -> Step Prefix x
step -> (a -> a)
-> Openness
-> (x -> Step Prefix x)
-> Prefix
-> x
-> Radix1Tree a
-> Radix1Tree a
forall a x.
(a -> a)
-> Openness
-> (x -> Step Prefix x)
-> Prefix
-> x
-> Radix1Tree a
-> Radix1Tree a
adjustR_ a -> a
f Openness
openness x -> Step Prefix x
step Prefix
w
{-# INLINE adjustR_ #-}
adjustR_
:: (a -> a) -> Openness -> (x -> Step Word8 x)
-> Word8 -> x -> Radix1Tree a -> Radix1Tree a
adjustR_ :: forall a x.
(a -> a)
-> Openness
-> (x -> Step Prefix x)
-> Prefix
-> x
-> Radix1Tree a
-> Radix1Tree a
adjustR_ a -> a
f Openness
openness x -> Step Prefix x
step = Prefix -> x -> Radix1Tree a -> Radix1Tree a
go
where
go :: Prefix -> x -> Radix1Tree a -> Radix1Tree a
go Prefix
w x
s Radix1Tree a
t =
case Radix1Tree a
t of
Bin Prefix
p Radix1Tree a
l Radix1Tree a
r ->
if Prefix
w Prefix -> Prefix -> Bool
forall a. Ord a => a -> a -> Bool
< Prefix
p
then if Prefix
w Prefix -> Prefix -> Bool
forall a. Ord a => a -> a -> Bool
>= Prefix -> Prefix
lower Prefix
p
then Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
forall a. Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
Bin Prefix
p (Prefix -> x -> Radix1Tree a -> Radix1Tree a
go Prefix
w x
s Radix1Tree a
l) ((a -> a) -> Radix1Tree a -> Radix1Tree a
forall a b. (a -> b) -> Radix1Tree a -> Radix1Tree b
map1 a -> a
f Radix1Tree a
r)
else (a -> a) -> Radix1Tree a -> Radix1Tree a
forall a b. (a -> b) -> Radix1Tree a -> Radix1Tree b
map1 a -> a
f Radix1Tree a
t
else if Prefix
w Prefix -> Prefix -> Bool
forall a. Ord a => a -> a -> Bool
<= Prefix -> Prefix
upper Prefix
p
then Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
forall a. Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
Bin Prefix
p Radix1Tree a
l (Prefix -> x -> Radix1Tree a -> Radix1Tree a
go Prefix
w x
s Radix1Tree a
r)
else Radix1Tree a
t
Tip ByteArray
arr Maybe a
mx Radix1Tree a
dx -> Prefix -> x -> Int -> Radix1Tree a
goarr Prefix
w x
s Int
0
where
goarr :: Prefix -> x -> Int -> Radix1Tree a
goarr Prefix
v x
z Int
n =
let n' :: Int
n' = Int
n Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1
in case ByteArray -> Int -> Prefix
forall a. Prim a => ByteArray -> Int -> a
indexByteArray ByteArray
arr Int
n Prefix -> Prefix -> Ordering
forall a. Ord a => a -> a -> Ordering
`compare` Prefix
v of
Ordering
EQ | Int
n' Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= ByteArray -> Int
sizeofByteArray ByteArray
arr ->
case x -> Step Prefix x
step x
z of
More Prefix
u x
z' -> ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
Tip ByteArray
arr Maybe a
mx (Radix1Tree a -> Radix1Tree a) -> Radix1Tree a -> Radix1Tree a
forall a b. (a -> b) -> a -> b
$ Prefix -> x -> Radix1Tree a -> Radix1Tree a
go Prefix
u x
z' Radix1Tree a
dx
Step Prefix x
Done ->
let my :: Maybe a
my = case Openness
openness of
Openness
Open -> Maybe a
mx
Openness
Closed -> a -> a
f (a -> a) -> Maybe a -> Maybe a
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe a
mx
in ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
Tip ByteArray
arr Maybe a
my (Radix1Tree a -> Radix1Tree a) -> Radix1Tree a -> Radix1Tree a
forall a b. (a -> b) -> a -> b
$ (a -> a) -> Radix1Tree a -> Radix1Tree a
forall a b. (a -> b) -> Radix1Tree a -> Radix1Tree b
map1 a -> a
f Radix1Tree a
dx
| Bool
otherwise ->
case x -> Step Prefix x
step x
z of
More Prefix
u x
z' -> Prefix -> x -> Int -> Radix1Tree a
goarr Prefix
u x
z' Int
n'
Step Prefix x
Done -> (a -> a) -> Radix1Tree a -> Radix1Tree a
forall a b. (a -> b) -> Radix1Tree a -> Radix1Tree b
map1 a -> a
f Radix1Tree a
t
Ordering
GT -> (a -> a) -> Radix1Tree a -> Radix1Tree a
forall a b. (a -> b) -> Radix1Tree a -> Radix1Tree b
map1 a -> a
f Radix1Tree a
t
Ordering
LT -> Radix1Tree a
t
Radix1Tree a
Nil -> Radix1Tree a
forall a. Radix1Tree a
Nil
{-# INLINE adjustRWithKey0 #-}
adjustRWithKey0 :: (Build -> a -> a) -> Openness -> Feed -> RadixTree a -> RadixTree a
adjustRWithKey0 :: forall a.
(Build -> a -> a) -> Openness -> Feed -> RadixTree a -> RadixTree a
adjustRWithKey0 Build -> a -> a
f Openness
openness (Feed forall a. (forall x. (x -> Step Prefix x) -> x -> a) -> a
feed) = \(RadixTree Maybe a
mx Radix1Tree a
t) ->
(forall x. (x -> Step Prefix x) -> x -> RadixTree a) -> RadixTree a
forall a. (forall x. (x -> Step Prefix x) -> x -> a) -> a
feed ((forall x. (x -> Step Prefix x) -> x -> RadixTree a)
-> RadixTree a)
-> (forall x. (x -> Step Prefix x) -> x -> RadixTree a)
-> RadixTree a
forall a b. (a -> b) -> a -> b
$ \x -> Step Prefix x
step x
s ->
case x -> Step Prefix x
step x
s of
More Prefix
w x
z ->
Maybe a -> Radix1Tree a -> RadixTree a
forall a. Maybe a -> Radix1Tree a -> RadixTree a
RadixTree Maybe a
mx (Radix1Tree a -> RadixTree a) -> Radix1Tree a -> RadixTree a
forall a b. (a -> b) -> a -> b
$
(Tsil ByteArray -> ByteArray -> a -> a)
-> Openness
-> (x -> Step Prefix x)
-> Prefix
-> x
-> Radix1Tree a
-> Radix1Tree a
forall a x.
(Tsil ByteArray -> ByteArray -> a -> a)
-> Openness
-> (x -> Step Prefix x)
-> Prefix
-> x
-> Radix1Tree a
-> Radix1Tree a
adjustRWithKey_ (\Tsil ByteArray
b ByteArray
arr -> Build -> a -> a
f (Tsil ByteArray -> Build
Build (Tsil ByteArray -> Build) -> Tsil ByteArray -> Build
forall a b. (a -> b) -> a -> b
$ Tsil ByteArray -> ByteArray -> Tsil ByteArray
forall a. Tsil a -> a -> Tsil a
Snoc Tsil ByteArray
b ByteArray
arr)) Openness
openness x -> Step Prefix x
step Prefix
w x
z Radix1Tree a
t
Step Prefix x
Done ->
let my :: Maybe a
my = case Openness
openness of
Openness
Open -> Maybe a
mx
Openness
Closed -> Build -> a -> a
f (Tsil ByteArray -> Build
Build Tsil ByteArray
forall a. Tsil a
Lin) (a -> a) -> Maybe a -> Maybe a
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe a
mx
in Maybe a -> Radix1Tree a -> RadixTree a
forall a. Maybe a -> Radix1Tree a -> RadixTree a
RadixTree Maybe a
my (Radix1Tree a -> RadixTree a) -> Radix1Tree a -> RadixTree a
forall a b. (a -> b) -> a -> b
$ (Tsil ByteArray -> ByteArray -> a -> a)
-> Tsil ByteArray -> Radix1Tree a -> Radix1Tree a
forall a b.
(Tsil ByteArray -> ByteArray -> a -> b)
-> Tsil ByteArray -> Radix1Tree a -> Radix1Tree b
mapWithKey_ (\Tsil ByteArray
b ByteArray
arr -> Build -> a -> a
f (Tsil ByteArray -> Build
Build (Tsil ByteArray -> Build) -> Tsil ByteArray -> Build
forall a b. (a -> b) -> a -> b
$ Tsil ByteArray -> ByteArray -> Tsil ByteArray
forall a. Tsil a -> a -> Tsil a
Snoc Tsil ByteArray
b ByteArray
arr)) Tsil ByteArray
forall a. Tsil a
Lin Radix1Tree a
t
{-# INLINE adjustRWithKey1 #-}
adjustRWithKey1 :: (Build1 -> a -> a) -> Openness -> Feed1 -> Radix1Tree a -> Radix1Tree a
adjustRWithKey1 :: forall a.
(Build1 -> a -> a)
-> Openness -> Feed1 -> Radix1Tree a -> Radix1Tree a
adjustRWithKey1 Build1 -> a -> a
f Openness
openness (Feed1 Prefix
w forall a. (forall x. (x -> Step Prefix x) -> x -> a) -> a
feed) =
(forall x.
(x -> Step Prefix x) -> x -> Radix1Tree a -> Radix1Tree a)
-> Radix1Tree a -> Radix1Tree a
forall a. (forall x. (x -> Step Prefix x) -> x -> a) -> a
feed ((forall x.
(x -> Step Prefix x) -> x -> Radix1Tree a -> Radix1Tree a)
-> Radix1Tree a -> Radix1Tree a)
-> (forall x.
(x -> Step Prefix x) -> x -> Radix1Tree a -> Radix1Tree a)
-> Radix1Tree a
-> Radix1Tree a
forall a b. (a -> b) -> a -> b
$ \x -> Step Prefix x
step -> (Tsil ByteArray -> ByteArray -> a -> a)
-> Openness
-> (x -> Step Prefix x)
-> Prefix
-> x
-> Radix1Tree a
-> Radix1Tree a
forall a x.
(Tsil ByteArray -> ByteArray -> a -> a)
-> Openness
-> (x -> Step Prefix x)
-> Prefix
-> x
-> Radix1Tree a
-> Radix1Tree a
adjustRWithKey_ (\Tsil ByteArray
b ByteArray
arr -> Build1 -> a -> a
f (YtpmeNon ByteArray -> Build1
Build1 (YtpmeNon ByteArray -> Build1) -> YtpmeNon ByteArray -> Build1
forall a b. (a -> b) -> a -> b
$ Tsil ByteArray
b Tsil ByteArray -> ByteArray -> YtpmeNon ByteArray
forall a. Tsil a -> a -> YtpmeNon a
:/ ByteArray
arr)) Openness
openness x -> Step Prefix x
step Prefix
w
{-# INLINE adjustRWithKey_ #-}
adjustRWithKey_
:: (Tsil ByteArray -> ByteArray -> a -> a) -> Openness -> (x -> Step Word8 x)
-> Word8 -> x -> Radix1Tree a -> Radix1Tree a
adjustRWithKey_ :: forall a x.
(Tsil ByteArray -> ByteArray -> a -> a)
-> Openness
-> (x -> Step Prefix x)
-> Prefix
-> x
-> Radix1Tree a
-> Radix1Tree a
adjustRWithKey_ Tsil ByteArray -> ByteArray -> a -> a
f Openness
openness x -> Step Prefix x
step = Tsil ByteArray -> Prefix -> x -> Radix1Tree a -> Radix1Tree a
go Tsil ByteArray
forall a. Tsil a
Lin
where
go :: Tsil ByteArray -> Prefix -> x -> Radix1Tree a -> Radix1Tree a
go Tsil ByteArray
b Prefix
w x
s Radix1Tree a
t =
case Radix1Tree a
t of
Bin Prefix
p Radix1Tree a
l Radix1Tree a
r ->
if Prefix
w Prefix -> Prefix -> Bool
forall a. Ord a => a -> a -> Bool
< Prefix
p
then if Prefix
w Prefix -> Prefix -> Bool
forall a. Ord a => a -> a -> Bool
>= Prefix -> Prefix
lower Prefix
p
then Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
forall a. Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
Bin Prefix
p (Tsil ByteArray -> Prefix -> x -> Radix1Tree a -> Radix1Tree a
go Tsil ByteArray
b Prefix
w x
s Radix1Tree a
l) ((Tsil ByteArray -> ByteArray -> a -> a)
-> Tsil ByteArray -> Radix1Tree a -> Radix1Tree a
forall a b.
(Tsil ByteArray -> ByteArray -> a -> b)
-> Tsil ByteArray -> Radix1Tree a -> Radix1Tree b
mapWithKey_ Tsil ByteArray -> ByteArray -> a -> a
f Tsil ByteArray
b Radix1Tree a
r)
else (Tsil ByteArray -> ByteArray -> a -> a)
-> Tsil ByteArray -> Radix1Tree a -> Radix1Tree a
forall a b.
(Tsil ByteArray -> ByteArray -> a -> b)
-> Tsil ByteArray -> Radix1Tree a -> Radix1Tree b
mapWithKey_ Tsil ByteArray -> ByteArray -> a -> a
f Tsil ByteArray
b Radix1Tree a
t
else if Prefix
w Prefix -> Prefix -> Bool
forall a. Ord a => a -> a -> Bool
<= Prefix -> Prefix
upper Prefix
p
then Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
forall a. Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
Bin Prefix
p Radix1Tree a
l (Tsil ByteArray -> Prefix -> x -> Radix1Tree a -> Radix1Tree a
go Tsil ByteArray
b Prefix
w x
s Radix1Tree a
r)
else Radix1Tree a
t
Tip ByteArray
arr Maybe a
mx Radix1Tree a
dx -> Prefix -> x -> Int -> Radix1Tree a
goarr Prefix
w x
s Int
0
where
goarr :: Prefix -> x -> Int -> Radix1Tree a
goarr Prefix
v x
z Int
n =
let n' :: Int
n' = Int
n Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1
in case ByteArray -> Int -> Prefix
forall a. Prim a => ByteArray -> Int -> a
indexByteArray ByteArray
arr Int
n Prefix -> Prefix -> Ordering
forall a. Ord a => a -> a -> Ordering
`compare` Prefix
v of
Ordering
EQ | Int
n' Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= ByteArray -> Int
sizeofByteArray ByteArray
arr ->
case x -> Step Prefix x
step x
z of
More Prefix
u x
z' -> ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
Tip ByteArray
arr Maybe a
mx (Radix1Tree a -> Radix1Tree a) -> Radix1Tree a -> Radix1Tree a
forall a b. (a -> b) -> a -> b
$ Tsil ByteArray -> Prefix -> x -> Radix1Tree a -> Radix1Tree a
go (Tsil ByteArray -> ByteArray -> Tsil ByteArray
forall a. Tsil a -> a -> Tsil a
Snoc Tsil ByteArray
b ByteArray
arr) Prefix
u x
z' Radix1Tree a
dx
Step Prefix x
Done ->
let my :: Maybe a
my = case Openness
openness of
Openness
Open -> Maybe a
mx
Openness
Closed -> Tsil ByteArray -> ByteArray -> a -> a
f Tsil ByteArray
b ByteArray
arr (a -> a) -> Maybe a -> Maybe a
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe a
mx
in ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
Tip ByteArray
arr Maybe a
my (Radix1Tree a -> Radix1Tree a) -> Radix1Tree a -> Radix1Tree a
forall a b. (a -> b) -> a -> b
$ (Tsil ByteArray -> ByteArray -> a -> a)
-> Tsil ByteArray -> Radix1Tree a -> Radix1Tree a
forall a b.
(Tsil ByteArray -> ByteArray -> a -> b)
-> Tsil ByteArray -> Radix1Tree a -> Radix1Tree b
mapWithKey_ Tsil ByteArray -> ByteArray -> a -> a
f (Tsil ByteArray -> ByteArray -> Tsil ByteArray
forall a. Tsil a -> a -> Tsil a
Snoc Tsil ByteArray
b ByteArray
arr) Radix1Tree a
dx
| Bool
otherwise ->
case x -> Step Prefix x
step x
z of
More Prefix
u x
z' -> Prefix -> x -> Int -> Radix1Tree a
goarr Prefix
u x
z' Int
n'
Step Prefix x
Done -> (Tsil ByteArray -> ByteArray -> a -> a)
-> Tsil ByteArray -> Radix1Tree a -> Radix1Tree a
forall a b.
(Tsil ByteArray -> ByteArray -> a -> b)
-> Tsil ByteArray -> Radix1Tree a -> Radix1Tree b
mapWithKey_ Tsil ByteArray -> ByteArray -> a -> a
f Tsil ByteArray
b Radix1Tree a
t
Ordering
GT -> (Tsil ByteArray -> ByteArray -> a -> a)
-> Tsil ByteArray -> Radix1Tree a -> Radix1Tree a
forall a b.
(Tsil ByteArray -> ByteArray -> a -> b)
-> Tsil ByteArray -> Radix1Tree a -> Radix1Tree b
mapWithKey_ Tsil ByteArray -> ByteArray -> a -> a
f Tsil ByteArray
b Radix1Tree a
t
Ordering
LT -> Radix1Tree a
t
Radix1Tree a
Nil -> Radix1Tree a
forall a. Radix1Tree a
Nil
{-# INLINE updateL0 #-}
updateL0 :: (a -> Maybe a) -> Openness -> Feed -> RadixTree a -> RadixTree a
updateL0 :: forall a.
(a -> Maybe a) -> Openness -> Feed -> RadixTree a -> RadixTree a
updateL0 a -> Maybe a
f Openness
openness (Feed forall a. (forall x. (x -> Step Prefix x) -> x -> a) -> a
feed) = \t0 :: RadixTree a
t0@(RadixTree Maybe a
mx Radix1Tree a
t) ->
(forall x. (x -> Step Prefix x) -> x -> RadixTree a) -> RadixTree a
forall a. (forall x. (x -> Step Prefix x) -> x -> a) -> a
feed ((forall x. (x -> Step Prefix x) -> x -> RadixTree a)
-> RadixTree a)
-> (forall x. (x -> Step Prefix x) -> x -> RadixTree a)
-> RadixTree a
forall a b. (a -> b) -> a -> b
$ \x -> Step Prefix x
step x
s ->
case x -> Step Prefix x
step x
s of
More Prefix
w x
z -> Maybe a -> Radix1Tree a -> RadixTree a
forall a. Maybe a -> Radix1Tree a -> RadixTree a
RadixTree (a -> Maybe a
f (a -> Maybe a) -> Maybe a -> Maybe a
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Maybe a
mx) (Radix1Tree a -> RadixTree a) -> Radix1Tree a -> RadixTree a
forall a b. (a -> b) -> a -> b
$ (a -> Maybe a)
-> Openness
-> (x -> Step Prefix x)
-> Prefix
-> x
-> Radix1Tree a
-> Radix1Tree a
forall a x.
(a -> Maybe a)
-> Openness
-> (x -> Step Prefix x)
-> Prefix
-> x
-> Radix1Tree a
-> Radix1Tree a
updateL_ a -> Maybe a
f Openness
openness x -> Step Prefix x
step Prefix
w x
z Radix1Tree a
t
Step Prefix x
Done ->
case Openness
openness of
Openness
Open -> RadixTree a
t0
Openness
Closed -> Maybe a -> Radix1Tree a -> RadixTree a
forall a. Maybe a -> Radix1Tree a -> RadixTree a
RadixTree (a -> Maybe a
f (a -> Maybe a) -> Maybe a -> Maybe a
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Maybe a
mx) Radix1Tree a
t
{-# INLINE updateL1 #-}
updateL1 :: (a -> Maybe a) -> Openness -> Feed1 -> Radix1Tree a -> Radix1Tree a
updateL1 :: forall a.
(a -> Maybe a) -> Openness -> Feed1 -> Radix1Tree a -> Radix1Tree a
updateL1 a -> Maybe a
f Openness
openness (Feed1 Prefix
w forall a. (forall x. (x -> Step Prefix x) -> x -> a) -> a
feed) =
(forall x.
(x -> Step Prefix x) -> x -> Radix1Tree a -> Radix1Tree a)
-> Radix1Tree a -> Radix1Tree a
forall a. (forall x. (x -> Step Prefix x) -> x -> a) -> a
feed ((forall x.
(x -> Step Prefix x) -> x -> Radix1Tree a -> Radix1Tree a)
-> Radix1Tree a -> Radix1Tree a)
-> (forall x.
(x -> Step Prefix x) -> x -> Radix1Tree a -> Radix1Tree a)
-> Radix1Tree a
-> Radix1Tree a
forall a b. (a -> b) -> a -> b
$ \x -> Step Prefix x
step -> (a -> Maybe a)
-> Openness
-> (x -> Step Prefix x)
-> Prefix
-> x
-> Radix1Tree a
-> Radix1Tree a
forall a x.
(a -> Maybe a)
-> Openness
-> (x -> Step Prefix x)
-> Prefix
-> x
-> Radix1Tree a
-> Radix1Tree a
updateL_ a -> Maybe a
f Openness
openness x -> Step Prefix x
step Prefix
w
{-# INLINE updateL_ #-}
updateL_
:: (a -> Maybe a) -> Openness -> (x -> Step Word8 x)
-> Word8 -> x -> Radix1Tree a -> Radix1Tree a
updateL_ :: forall a x.
(a -> Maybe a)
-> Openness
-> (x -> Step Prefix x)
-> Prefix
-> x
-> Radix1Tree a
-> Radix1Tree a
updateL_ a -> Maybe a
f Openness
openness x -> Step Prefix x
step = Prefix -> x -> Radix1Tree a -> Radix1Tree a
go
where
go :: Prefix -> x -> Radix1Tree a -> Radix1Tree a
go Prefix
w x
s Radix1Tree a
t =
case Radix1Tree a
t of
Bin Prefix
p Radix1Tree a
l Radix1Tree a
r ->
if Prefix
w Prefix -> Prefix -> Bool
forall a. Ord a => a -> a -> Bool
< Prefix
p
then if Prefix
w Prefix -> Prefix -> Bool
forall a. Ord a => a -> a -> Bool
>= Prefix -> Prefix
lower Prefix
p
then Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
forall a. Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
rebinL Prefix
p (Prefix -> x -> Radix1Tree a -> Radix1Tree a
go Prefix
w x
s Radix1Tree a
l) Radix1Tree a
r
else Radix1Tree a
t
else if Prefix
w Prefix -> Prefix -> Bool
forall a. Ord a => a -> a -> Bool
<= Prefix -> Prefix
upper Prefix
p
then Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
forall a. Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
rebin Prefix
p ((a -> Maybe a) -> Radix1Tree a -> Radix1Tree a
forall a b. (a -> Maybe b) -> Radix1Tree a -> Radix1Tree b
mapMaybe1 a -> Maybe a
f Radix1Tree a
l) (Prefix -> x -> Radix1Tree a -> Radix1Tree a
go Prefix
w x
s Radix1Tree a
r)
else (a -> Maybe a) -> Radix1Tree a -> Radix1Tree a
forall a b. (a -> Maybe b) -> Radix1Tree a -> Radix1Tree b
mapMaybe1 a -> Maybe a
f Radix1Tree a
t
Tip ByteArray
arr Maybe a
mx Radix1Tree a
dx -> Prefix -> x -> Int -> Radix1Tree a
goarr Prefix
w x
s Int
0
where
goarr :: Prefix -> x -> Int -> Radix1Tree a
goarr Prefix
v x
z Int
n =
let n' :: Int
n' = Int
n Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1
in case ByteArray -> Int -> Prefix
forall a. Prim a => ByteArray -> Int -> a
indexByteArray ByteArray
arr Int
n Prefix -> Prefix -> Ordering
forall a. Ord a => a -> a -> Ordering
`compare` Prefix
v of
Ordering
EQ | Int
n' Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= ByteArray -> Int
sizeofByteArray ByteArray
arr ->
case x -> Step Prefix x
step x
z of
More Prefix
u x
z' -> ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
retip ByteArray
arr (a -> Maybe a
f (a -> Maybe a) -> Maybe a -> Maybe a
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Maybe a
mx) (Radix1Tree a -> Radix1Tree a) -> Radix1Tree a -> Radix1Tree a
forall a b. (a -> b) -> a -> b
$ Prefix -> x -> Radix1Tree a -> Radix1Tree a
go Prefix
u x
z' Radix1Tree a
dx
Step Prefix x
Done ->
let my :: Maybe a
my = case Openness
openness of
Openness
Open -> Maybe a
mx
Openness
Closed -> a -> Maybe a
f (a -> Maybe a) -> Maybe a -> Maybe a
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Maybe a
mx
in ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
retip ByteArray
arr Maybe a
my Radix1Tree a
dx
| Bool
otherwise ->
case x -> Step Prefix x
step x
z of
More Prefix
u x
z' -> Prefix -> x -> Int -> Radix1Tree a
goarr Prefix
u x
z' Int
n'
Step Prefix x
Done -> Radix1Tree a
t
Ordering
LT -> (a -> Maybe a) -> Radix1Tree a -> Radix1Tree a
forall a b. (a -> Maybe b) -> Radix1Tree a -> Radix1Tree b
mapMaybe1 a -> Maybe a
f Radix1Tree a
t
Ordering
GT -> Radix1Tree a
t
Radix1Tree a
Nil -> Radix1Tree a
forall a. Radix1Tree a
Nil
{-# INLINE updateLWithKey0 #-}
updateLWithKey0
:: (Build -> a -> Maybe a) -> Openness -> Feed -> RadixTree a -> RadixTree a
updateLWithKey0 :: forall a.
(Build -> a -> Maybe a)
-> Openness -> Feed -> RadixTree a -> RadixTree a
updateLWithKey0 Build -> a -> Maybe a
f Openness
openness (Feed forall a. (forall x. (x -> Step Prefix x) -> x -> a) -> a
feed) = \t0 :: RadixTree a
t0@(RadixTree Maybe a
mx Radix1Tree a
t) ->
(forall x. (x -> Step Prefix x) -> x -> RadixTree a) -> RadixTree a
forall a. (forall x. (x -> Step Prefix x) -> x -> a) -> a
feed ((forall x. (x -> Step Prefix x) -> x -> RadixTree a)
-> RadixTree a)
-> (forall x. (x -> Step Prefix x) -> x -> RadixTree a)
-> RadixTree a
forall a b. (a -> b) -> a -> b
$ \x -> Step Prefix x
step x
s ->
case x -> Step Prefix x
step x
s of
More Prefix
w x
z ->
Maybe a -> Radix1Tree a -> RadixTree a
forall a. Maybe a -> Radix1Tree a -> RadixTree a
RadixTree (Build -> a -> Maybe a
f (Tsil ByteArray -> Build
Build Tsil ByteArray
forall a. Tsil a
Lin) (a -> Maybe a) -> Maybe a -> Maybe a
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Maybe a
mx) (Radix1Tree a -> RadixTree a) -> Radix1Tree a -> RadixTree a
forall a b. (a -> b) -> a -> b
$
(Tsil ByteArray -> ByteArray -> a -> Maybe a)
-> Openness
-> (x -> Step Prefix x)
-> Prefix
-> x
-> Radix1Tree a
-> Radix1Tree a
forall a x.
(Tsil ByteArray -> ByteArray -> a -> Maybe a)
-> Openness
-> (x -> Step Prefix x)
-> Prefix
-> x
-> Radix1Tree a
-> Radix1Tree a
updateLWithKey_ (\Tsil ByteArray
b ByteArray
arr -> Build -> a -> Maybe a
f (Tsil ByteArray -> Build
Build (Tsil ByteArray -> Build) -> Tsil ByteArray -> Build
forall a b. (a -> b) -> a -> b
$ Tsil ByteArray -> ByteArray -> Tsil ByteArray
forall a. Tsil a -> a -> Tsil a
Snoc Tsil ByteArray
b ByteArray
arr)) Openness
openness x -> Step Prefix x
step Prefix
w x
z Radix1Tree a
t
Step Prefix x
Done ->
case Openness
openness of
Openness
Open -> RadixTree a
t0
Openness
Closed -> Maybe a -> Radix1Tree a -> RadixTree a
forall a. Maybe a -> Radix1Tree a -> RadixTree a
RadixTree (Build -> a -> Maybe a
f (Tsil ByteArray -> Build
Build Tsil ByteArray
forall a. Tsil a
Lin) (a -> Maybe a) -> Maybe a -> Maybe a
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Maybe a
mx) Radix1Tree a
t
{-# INLINE updateLWithKey1 #-}
updateLWithKey1
:: (Build1 -> a -> Maybe a) -> Openness -> Feed1 -> Radix1Tree a -> Radix1Tree a
updateLWithKey1 :: forall a.
(Build1 -> a -> Maybe a)
-> Openness -> Feed1 -> Radix1Tree a -> Radix1Tree a
updateLWithKey1 Build1 -> a -> Maybe a
f Openness
openness (Feed1 Prefix
w forall a. (forall x. (x -> Step Prefix x) -> x -> a) -> a
feed) =
(forall x.
(x -> Step Prefix x) -> x -> Radix1Tree a -> Radix1Tree a)
-> Radix1Tree a -> Radix1Tree a
forall a. (forall x. (x -> Step Prefix x) -> x -> a) -> a
feed ((forall x.
(x -> Step Prefix x) -> x -> Radix1Tree a -> Radix1Tree a)
-> Radix1Tree a -> Radix1Tree a)
-> (forall x.
(x -> Step Prefix x) -> x -> Radix1Tree a -> Radix1Tree a)
-> Radix1Tree a
-> Radix1Tree a
forall a b. (a -> b) -> a -> b
$ \x -> Step Prefix x
step -> (Tsil ByteArray -> ByteArray -> a -> Maybe a)
-> Openness
-> (x -> Step Prefix x)
-> Prefix
-> x
-> Radix1Tree a
-> Radix1Tree a
forall a x.
(Tsil ByteArray -> ByteArray -> a -> Maybe a)
-> Openness
-> (x -> Step Prefix x)
-> Prefix
-> x
-> Radix1Tree a
-> Radix1Tree a
updateLWithKey_ (\Tsil ByteArray
b ByteArray
arr -> Build1 -> a -> Maybe a
f (YtpmeNon ByteArray -> Build1
Build1 (YtpmeNon ByteArray -> Build1) -> YtpmeNon ByteArray -> Build1
forall a b. (a -> b) -> a -> b
$ Tsil ByteArray
b Tsil ByteArray -> ByteArray -> YtpmeNon ByteArray
forall a. Tsil a -> a -> YtpmeNon a
:/ ByteArray
arr)) Openness
openness x -> Step Prefix x
step Prefix
w
{-# INLINE updateLWithKey_ #-}
updateLWithKey_
:: (Tsil ByteArray -> ByteArray -> a -> Maybe a) -> Openness -> (x -> Step Word8 x)
-> Word8 -> x -> Radix1Tree a -> Radix1Tree a
updateLWithKey_ :: forall a x.
(Tsil ByteArray -> ByteArray -> a -> Maybe a)
-> Openness
-> (x -> Step Prefix x)
-> Prefix
-> x
-> Radix1Tree a
-> Radix1Tree a
updateLWithKey_ Tsil ByteArray -> ByteArray -> a -> Maybe a
f Openness
openness x -> Step Prefix x
step = Tsil ByteArray -> Prefix -> x -> Radix1Tree a -> Radix1Tree a
go Tsil ByteArray
forall a. Tsil a
Lin
where
go :: Tsil ByteArray -> Prefix -> x -> Radix1Tree a -> Radix1Tree a
go Tsil ByteArray
b Prefix
w x
s Radix1Tree a
t =
case Radix1Tree a
t of
Bin Prefix
p Radix1Tree a
l Radix1Tree a
r ->
if Prefix
w Prefix -> Prefix -> Bool
forall a. Ord a => a -> a -> Bool
< Prefix
p
then if Prefix
w Prefix -> Prefix -> Bool
forall a. Ord a => a -> a -> Bool
>= Prefix -> Prefix
lower Prefix
p
then Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
forall a. Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
rebinL Prefix
p (Tsil ByteArray -> Prefix -> x -> Radix1Tree a -> Radix1Tree a
go Tsil ByteArray
b Prefix
w x
s Radix1Tree a
l) Radix1Tree a
r
else Radix1Tree a
t
else if Prefix
w Prefix -> Prefix -> Bool
forall a. Ord a => a -> a -> Bool
<= Prefix -> Prefix
upper Prefix
p
then Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
forall a. Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
rebin Prefix
p ((Tsil ByteArray -> ByteArray -> a -> Maybe a)
-> Tsil ByteArray -> Radix1Tree a -> Radix1Tree a
forall a b.
(Tsil ByteArray -> ByteArray -> a -> Maybe b)
-> Tsil ByteArray -> Radix1Tree a -> Radix1Tree b
mapMaybeWithKey_ Tsil ByteArray -> ByteArray -> a -> Maybe a
f Tsil ByteArray
b Radix1Tree a
l) (Tsil ByteArray -> Prefix -> x -> Radix1Tree a -> Radix1Tree a
go Tsil ByteArray
b Prefix
w x
s Radix1Tree a
r)
else (Tsil ByteArray -> ByteArray -> a -> Maybe a)
-> Tsil ByteArray -> Radix1Tree a -> Radix1Tree a
forall a b.
(Tsil ByteArray -> ByteArray -> a -> Maybe b)
-> Tsil ByteArray -> Radix1Tree a -> Radix1Tree b
mapMaybeWithKey_ Tsil ByteArray -> ByteArray -> a -> Maybe a
f Tsil ByteArray
b Radix1Tree a
t
Tip ByteArray
arr Maybe a
mx Radix1Tree a
dx -> Prefix -> x -> Int -> Radix1Tree a
goarr Prefix
w x
s Int
0
where
goarr :: Prefix -> x -> Int -> Radix1Tree a
goarr Prefix
v x
z Int
n =
let n' :: Int
n' = Int
n Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1
in case ByteArray -> Int -> Prefix
forall a. Prim a => ByteArray -> Int -> a
indexByteArray ByteArray
arr Int
n Prefix -> Prefix -> Ordering
forall a. Ord a => a -> a -> Ordering
`compare` Prefix
v of
Ordering
EQ | Int
n' Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= ByteArray -> Int
sizeofByteArray ByteArray
arr ->
case x -> Step Prefix x
step x
z of
More Prefix
u x
z' -> ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
retip ByteArray
arr (Tsil ByteArray -> ByteArray -> a -> Maybe a
f Tsil ByteArray
b ByteArray
arr (a -> Maybe a) -> Maybe a -> Maybe a
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Maybe a
mx) (Radix1Tree a -> Radix1Tree a) -> Radix1Tree a -> Radix1Tree a
forall a b. (a -> b) -> a -> b
$
Tsil ByteArray -> Prefix -> x -> Radix1Tree a -> Radix1Tree a
go (Tsil ByteArray -> ByteArray -> Tsil ByteArray
forall a. Tsil a -> a -> Tsil a
Snoc Tsil ByteArray
b ByteArray
arr) Prefix
u x
z' Radix1Tree a
dx
Step Prefix x
Done ->
let my :: Maybe a
my = case Openness
openness of
Openness
Open -> Maybe a
mx
Openness
Closed -> Tsil ByteArray -> ByteArray -> a -> Maybe a
f Tsil ByteArray
b ByteArray
arr (a -> Maybe a) -> Maybe a -> Maybe a
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Maybe a
mx
in ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
retip ByteArray
arr Maybe a
my Radix1Tree a
dx
| Bool
otherwise ->
case x -> Step Prefix x
step x
z of
More Prefix
u x
z' -> Prefix -> x -> Int -> Radix1Tree a
goarr Prefix
u x
z' Int
n'
Step Prefix x
Done -> Radix1Tree a
t
Ordering
LT -> (Tsil ByteArray -> ByteArray -> a -> Maybe a)
-> Tsil ByteArray -> Radix1Tree a -> Radix1Tree a
forall a b.
(Tsil ByteArray -> ByteArray -> a -> Maybe b)
-> Tsil ByteArray -> Radix1Tree a -> Radix1Tree b
mapMaybeWithKey_ Tsil ByteArray -> ByteArray -> a -> Maybe a
f Tsil ByteArray
b Radix1Tree a
t
Ordering
GT -> Radix1Tree a
t
Radix1Tree a
Nil -> Radix1Tree a
forall a. Radix1Tree a
Nil
{-# INLINE updateR0 #-}
updateR0 :: (a -> Maybe a) -> Openness -> Feed -> RadixTree a -> RadixTree a
updateR0 :: forall a.
(a -> Maybe a) -> Openness -> Feed -> RadixTree a -> RadixTree a
updateR0 a -> Maybe a
f Openness
openness (Feed forall a. (forall x. (x -> Step Prefix x) -> x -> a) -> a
feed) (RadixTree Maybe a
mx Radix1Tree a
t) =
(forall x. (x -> Step Prefix x) -> x -> RadixTree a) -> RadixTree a
forall a. (forall x. (x -> Step Prefix x) -> x -> a) -> a
feed ((forall x. (x -> Step Prefix x) -> x -> RadixTree a)
-> RadixTree a)
-> (forall x. (x -> Step Prefix x) -> x -> RadixTree a)
-> RadixTree a
forall a b. (a -> b) -> a -> b
$ \x -> Step Prefix x
step x
s ->
case x -> Step Prefix x
step x
s of
More Prefix
w x
z -> Maybe a -> Radix1Tree a -> RadixTree a
forall a. Maybe a -> Radix1Tree a -> RadixTree a
RadixTree Maybe a
mx (Radix1Tree a -> RadixTree a) -> Radix1Tree a -> RadixTree a
forall a b. (a -> b) -> a -> b
$ (a -> Maybe a)
-> Openness
-> (x -> Step Prefix x)
-> Prefix
-> x
-> Radix1Tree a
-> Radix1Tree a
forall a x.
(a -> Maybe a)
-> Openness
-> (x -> Step Prefix x)
-> Prefix
-> x
-> Radix1Tree a
-> Radix1Tree a
updateR_ a -> Maybe a
f Openness
openness x -> Step Prefix x
step Prefix
w x
z Radix1Tree a
t
Step Prefix x
Done ->
let my :: Maybe a
my = case Openness
openness of
Openness
Open -> Maybe a
mx
Openness
Closed -> a -> Maybe a
f (a -> Maybe a) -> Maybe a -> Maybe a
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Maybe a
mx
in Maybe a -> Radix1Tree a -> RadixTree a
forall a. Maybe a -> Radix1Tree a -> RadixTree a
RadixTree Maybe a
my ((a -> Maybe a) -> Radix1Tree a -> Radix1Tree a
forall a b. (a -> Maybe b) -> Radix1Tree a -> Radix1Tree b
mapMaybe1 a -> Maybe a
f Radix1Tree a
t)
{-# INLINE updateR1 #-}
updateR1 :: (a -> Maybe a) -> Openness -> Feed1 -> Radix1Tree a -> Radix1Tree a
updateR1 :: forall a.
(a -> Maybe a) -> Openness -> Feed1 -> Radix1Tree a -> Radix1Tree a
updateR1 a -> Maybe a
f Openness
openness (Feed1 Prefix
w forall a. (forall x. (x -> Step Prefix x) -> x -> a) -> a
feed) =
(forall x.
(x -> Step Prefix x) -> x -> Radix1Tree a -> Radix1Tree a)
-> Radix1Tree a -> Radix1Tree a
forall a. (forall x. (x -> Step Prefix x) -> x -> a) -> a
feed ((forall x.
(x -> Step Prefix x) -> x -> Radix1Tree a -> Radix1Tree a)
-> Radix1Tree a -> Radix1Tree a)
-> (forall x.
(x -> Step Prefix x) -> x -> Radix1Tree a -> Radix1Tree a)
-> Radix1Tree a
-> Radix1Tree a
forall a b. (a -> b) -> a -> b
$ \x -> Step Prefix x
step -> (a -> Maybe a)
-> Openness
-> (x -> Step Prefix x)
-> Prefix
-> x
-> Radix1Tree a
-> Radix1Tree a
forall a x.
(a -> Maybe a)
-> Openness
-> (x -> Step Prefix x)
-> Prefix
-> x
-> Radix1Tree a
-> Radix1Tree a
updateR_ a -> Maybe a
f Openness
openness x -> Step Prefix x
step Prefix
w
{-# INLINE updateR_ #-}
updateR_
:: (a -> Maybe a) -> Openness -> (x -> Step Word8 x)
-> Word8 -> x -> Radix1Tree a -> Radix1Tree a
updateR_ :: forall a x.
(a -> Maybe a)
-> Openness
-> (x -> Step Prefix x)
-> Prefix
-> x
-> Radix1Tree a
-> Radix1Tree a
updateR_ a -> Maybe a
f Openness
openness x -> Step Prefix x
step = Prefix -> x -> Radix1Tree a -> Radix1Tree a
go
where
go :: Prefix -> x -> Radix1Tree a -> Radix1Tree a
go Prefix
w x
s Radix1Tree a
t =
case Radix1Tree a
t of
Bin Prefix
p Radix1Tree a
l Radix1Tree a
r ->
if Prefix
w Prefix -> Prefix -> Bool
forall a. Ord a => a -> a -> Bool
< Prefix
p
then if Prefix
w Prefix -> Prefix -> Bool
forall a. Ord a => a -> a -> Bool
>= Prefix -> Prefix
lower Prefix
p
then Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
forall a. Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
rebin Prefix
p (Prefix -> x -> Radix1Tree a -> Radix1Tree a
go Prefix
w x
s Radix1Tree a
l) ((a -> Maybe a) -> Radix1Tree a -> Radix1Tree a
forall a b. (a -> Maybe b) -> Radix1Tree a -> Radix1Tree b
mapMaybe1 a -> Maybe a
f Radix1Tree a
r)
else (a -> Maybe a) -> Radix1Tree a -> Radix1Tree a
forall a b. (a -> Maybe b) -> Radix1Tree a -> Radix1Tree b
mapMaybe1 a -> Maybe a
f Radix1Tree a
t
else if Prefix
w Prefix -> Prefix -> Bool
forall a. Ord a => a -> a -> Bool
<= Prefix -> Prefix
upper Prefix
p
then Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
forall a. Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
rebinR Prefix
p Radix1Tree a
l (Prefix -> x -> Radix1Tree a -> Radix1Tree a
go Prefix
w x
s Radix1Tree a
r)
else Radix1Tree a
t
Tip ByteArray
arr Maybe a
mx Radix1Tree a
dx -> Prefix -> x -> Int -> Radix1Tree a
goarr Prefix
w x
s Int
0
where
goarr :: Prefix -> x -> Int -> Radix1Tree a
goarr Prefix
v x
z Int
n =
let n' :: Int
n' = Int
n Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1
in case ByteArray -> Int -> Prefix
forall a. Prim a => ByteArray -> Int -> a
indexByteArray ByteArray
arr Int
n Prefix -> Prefix -> Ordering
forall a. Ord a => a -> a -> Ordering
`compare` Prefix
v of
Ordering
EQ | Int
n' Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= ByteArray -> Int
sizeofByteArray ByteArray
arr ->
case x -> Step Prefix x
step x
z of
More Prefix
u x
z' -> ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
retip ByteArray
arr Maybe a
mx (Radix1Tree a -> Radix1Tree a) -> Radix1Tree a -> Radix1Tree a
forall a b. (a -> b) -> a -> b
$ Prefix -> x -> Radix1Tree a -> Radix1Tree a
go Prefix
u x
z' Radix1Tree a
dx
Step Prefix x
Done ->
let my :: Maybe a
my = case Openness
openness of
Openness
Open -> Maybe a
mx
Openness
Closed -> a -> Maybe a
f (a -> Maybe a) -> Maybe a -> Maybe a
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Maybe a
mx
in ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
retip ByteArray
arr Maybe a
my (Radix1Tree a -> Radix1Tree a) -> Radix1Tree a -> Radix1Tree a
forall a b. (a -> b) -> a -> b
$ (a -> Maybe a) -> Radix1Tree a -> Radix1Tree a
forall a b. (a -> Maybe b) -> Radix1Tree a -> Radix1Tree b
mapMaybe1 a -> Maybe a
f Radix1Tree a
dx
| Bool
otherwise ->
case x -> Step Prefix x
step x
z of
More Prefix
u x
z' -> Prefix -> x -> Int -> Radix1Tree a
goarr Prefix
u x
z' Int
n'
Step Prefix x
Done -> (a -> Maybe a) -> Radix1Tree a -> Radix1Tree a
forall a b. (a -> Maybe b) -> Radix1Tree a -> Radix1Tree b
mapMaybe1 a -> Maybe a
f Radix1Tree a
t
Ordering
GT -> (a -> Maybe a) -> Radix1Tree a -> Radix1Tree a
forall a b. (a -> Maybe b) -> Radix1Tree a -> Radix1Tree b
mapMaybe1 a -> Maybe a
f Radix1Tree a
t
Ordering
LT -> Radix1Tree a
t
Radix1Tree a
Nil -> Radix1Tree a
forall a. Radix1Tree a
Nil
{-# INLINE updateRWithKey0 #-}
updateRWithKey0
:: (Build -> a -> Maybe a) -> Openness -> Feed -> RadixTree a -> RadixTree a
updateRWithKey0 :: forall a.
(Build -> a -> Maybe a)
-> Openness -> Feed -> RadixTree a -> RadixTree a
updateRWithKey0 Build -> a -> Maybe a
f Openness
openness (Feed forall a. (forall x. (x -> Step Prefix x) -> x -> a) -> a
feed) (RadixTree Maybe a
mx Radix1Tree a
t) =
(forall x. (x -> Step Prefix x) -> x -> RadixTree a) -> RadixTree a
forall a. (forall x. (x -> Step Prefix x) -> x -> a) -> a
feed ((forall x. (x -> Step Prefix x) -> x -> RadixTree a)
-> RadixTree a)
-> (forall x. (x -> Step Prefix x) -> x -> RadixTree a)
-> RadixTree a
forall a b. (a -> b) -> a -> b
$ \x -> Step Prefix x
step x
s ->
case x -> Step Prefix x
step x
s of
More Prefix
w x
z ->
Maybe a -> Radix1Tree a -> RadixTree a
forall a. Maybe a -> Radix1Tree a -> RadixTree a
RadixTree Maybe a
mx (Radix1Tree a -> RadixTree a) -> Radix1Tree a -> RadixTree a
forall a b. (a -> b) -> a -> b
$
(Tsil ByteArray -> ByteArray -> a -> Maybe a)
-> Openness
-> (x -> Step Prefix x)
-> Prefix
-> x
-> Radix1Tree a
-> Radix1Tree a
forall a x.
(Tsil ByteArray -> ByteArray -> a -> Maybe a)
-> Openness
-> (x -> Step Prefix x)
-> Prefix
-> x
-> Radix1Tree a
-> Radix1Tree a
updateRWithKey_ (\Tsil ByteArray
b ByteArray
arr -> Build -> a -> Maybe a
f (Tsil ByteArray -> Build
Build (Tsil ByteArray -> Build) -> Tsil ByteArray -> Build
forall a b. (a -> b) -> a -> b
$ Tsil ByteArray -> ByteArray -> Tsil ByteArray
forall a. Tsil a -> a -> Tsil a
Snoc Tsil ByteArray
b ByteArray
arr)) Openness
openness x -> Step Prefix x
step Prefix
w x
z Radix1Tree a
t
Step Prefix x
Done ->
let my :: Maybe a
my = case Openness
openness of
Openness
Open -> Maybe a
mx
Openness
Closed -> Build -> a -> Maybe a
f (Tsil ByteArray -> Build
Build Tsil ByteArray
forall a. Tsil a
Lin) (a -> Maybe a) -> Maybe a -> Maybe a
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Maybe a
mx
in Maybe a -> Radix1Tree a -> RadixTree a
forall a. Maybe a -> Radix1Tree a -> RadixTree a
RadixTree Maybe a
my ((Tsil ByteArray -> ByteArray -> a -> Maybe a)
-> Tsil ByteArray -> Radix1Tree a -> Radix1Tree a
forall a b.
(Tsil ByteArray -> ByteArray -> a -> Maybe b)
-> Tsil ByteArray -> Radix1Tree a -> Radix1Tree b
mapMaybeWithKey_ (\Tsil ByteArray
b ByteArray
arr -> Build -> a -> Maybe a
f (Tsil ByteArray -> Build
Build (Tsil ByteArray -> Build) -> Tsil ByteArray -> Build
forall a b. (a -> b) -> a -> b
$ Tsil ByteArray -> ByteArray -> Tsil ByteArray
forall a. Tsil a -> a -> Tsil a
Snoc Tsil ByteArray
b ByteArray
arr)) Tsil ByteArray
forall a. Tsil a
Lin Radix1Tree a
t)
{-# INLINE updateRWithKey1 #-}
updateRWithKey1
:: (Build1 -> a -> Maybe a) -> Openness -> Feed1 -> Radix1Tree a -> Radix1Tree a
updateRWithKey1 :: forall a.
(Build1 -> a -> Maybe a)
-> Openness -> Feed1 -> Radix1Tree a -> Radix1Tree a
updateRWithKey1 Build1 -> a -> Maybe a
f Openness
openness (Feed1 Prefix
w forall a. (forall x. (x -> Step Prefix x) -> x -> a) -> a
feed) =
(forall x.
(x -> Step Prefix x) -> x -> Radix1Tree a -> Radix1Tree a)
-> Radix1Tree a -> Radix1Tree a
forall a. (forall x. (x -> Step Prefix x) -> x -> a) -> a
feed ((forall x.
(x -> Step Prefix x) -> x -> Radix1Tree a -> Radix1Tree a)
-> Radix1Tree a -> Radix1Tree a)
-> (forall x.
(x -> Step Prefix x) -> x -> Radix1Tree a -> Radix1Tree a)
-> Radix1Tree a
-> Radix1Tree a
forall a b. (a -> b) -> a -> b
$ \x -> Step Prefix x
step -> (Tsil ByteArray -> ByteArray -> a -> Maybe a)
-> Openness
-> (x -> Step Prefix x)
-> Prefix
-> x
-> Radix1Tree a
-> Radix1Tree a
forall a x.
(Tsil ByteArray -> ByteArray -> a -> Maybe a)
-> Openness
-> (x -> Step Prefix x)
-> Prefix
-> x
-> Radix1Tree a
-> Radix1Tree a
updateRWithKey_ (\Tsil ByteArray
b ByteArray
arr -> Build1 -> a -> Maybe a
f (YtpmeNon ByteArray -> Build1
Build1 (YtpmeNon ByteArray -> Build1) -> YtpmeNon ByteArray -> Build1
forall a b. (a -> b) -> a -> b
$ Tsil ByteArray
b Tsil ByteArray -> ByteArray -> YtpmeNon ByteArray
forall a. Tsil a -> a -> YtpmeNon a
:/ ByteArray
arr)) Openness
openness x -> Step Prefix x
step Prefix
w
{-# INLINE updateRWithKey_ #-}
updateRWithKey_
:: (Tsil ByteArray -> ByteArray -> a -> Maybe a) -> Openness -> (x -> Step Word8 x)
-> Word8 -> x -> Radix1Tree a -> Radix1Tree a
updateRWithKey_ :: forall a x.
(Tsil ByteArray -> ByteArray -> a -> Maybe a)
-> Openness
-> (x -> Step Prefix x)
-> Prefix
-> x
-> Radix1Tree a
-> Radix1Tree a
updateRWithKey_ Tsil ByteArray -> ByteArray -> a -> Maybe a
f Openness
openness x -> Step Prefix x
step = Tsil ByteArray -> Prefix -> x -> Radix1Tree a -> Radix1Tree a
go Tsil ByteArray
forall a. Tsil a
Lin
where
go :: Tsil ByteArray -> Prefix -> x -> Radix1Tree a -> Radix1Tree a
go Tsil ByteArray
b Prefix
w x
s Radix1Tree a
t =
case Radix1Tree a
t of
Bin Prefix
p Radix1Tree a
l Radix1Tree a
r ->
if Prefix
w Prefix -> Prefix -> Bool
forall a. Ord a => a -> a -> Bool
< Prefix
p
then if Prefix
w Prefix -> Prefix -> Bool
forall a. Ord a => a -> a -> Bool
>= Prefix -> Prefix
lower Prefix
p
then Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
forall a. Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
rebin Prefix
p (Tsil ByteArray -> Prefix -> x -> Radix1Tree a -> Radix1Tree a
go Tsil ByteArray
b Prefix
w x
s Radix1Tree a
l) ((Tsil ByteArray -> ByteArray -> a -> Maybe a)
-> Tsil ByteArray -> Radix1Tree a -> Radix1Tree a
forall a b.
(Tsil ByteArray -> ByteArray -> a -> Maybe b)
-> Tsil ByteArray -> Radix1Tree a -> Radix1Tree b
mapMaybeWithKey_ Tsil ByteArray -> ByteArray -> a -> Maybe a
f Tsil ByteArray
b Radix1Tree a
r)
else (Tsil ByteArray -> ByteArray -> a -> Maybe a)
-> Tsil ByteArray -> Radix1Tree a -> Radix1Tree a
forall a b.
(Tsil ByteArray -> ByteArray -> a -> Maybe b)
-> Tsil ByteArray -> Radix1Tree a -> Radix1Tree b
mapMaybeWithKey_ Tsil ByteArray -> ByteArray -> a -> Maybe a
f Tsil ByteArray
b Radix1Tree a
t
else if Prefix
w Prefix -> Prefix -> Bool
forall a. Ord a => a -> a -> Bool
<= Prefix -> Prefix
upper Prefix
p
then Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
forall a. Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
rebinR Prefix
p Radix1Tree a
l (Tsil ByteArray -> Prefix -> x -> Radix1Tree a -> Radix1Tree a
go Tsil ByteArray
b Prefix
w x
s Radix1Tree a
r)
else Radix1Tree a
t
Tip ByteArray
arr Maybe a
mx Radix1Tree a
dx -> Prefix -> x -> Int -> Radix1Tree a
goarr Prefix
w x
s Int
0
where
goarr :: Prefix -> x -> Int -> Radix1Tree a
goarr Prefix
v x
z Int
n =
let n' :: Int
n' = Int
n Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1
in case ByteArray -> Int -> Prefix
forall a. Prim a => ByteArray -> Int -> a
indexByteArray ByteArray
arr Int
n Prefix -> Prefix -> Ordering
forall a. Ord a => a -> a -> Ordering
`compare` Prefix
v of
Ordering
EQ | Int
n' Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= ByteArray -> Int
sizeofByteArray ByteArray
arr ->
case x -> Step Prefix x
step x
z of
More Prefix
u x
z' -> ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
retip ByteArray
arr Maybe a
mx (Radix1Tree a -> Radix1Tree a) -> Radix1Tree a -> Radix1Tree a
forall a b. (a -> b) -> a -> b
$ Tsil ByteArray -> Prefix -> x -> Radix1Tree a -> Radix1Tree a
go (Tsil ByteArray -> ByteArray -> Tsil ByteArray
forall a. Tsil a -> a -> Tsil a
Snoc Tsil ByteArray
b ByteArray
arr) Prefix
u x
z' Radix1Tree a
dx
Step Prefix x
Done ->
let my :: Maybe a
my = case Openness
openness of
Openness
Open -> Maybe a
mx
Openness
Closed -> Tsil ByteArray -> ByteArray -> a -> Maybe a
f Tsil ByteArray
b ByteArray
arr (a -> Maybe a) -> Maybe a -> Maybe a
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Maybe a
mx
in ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
retip ByteArray
arr Maybe a
my (Radix1Tree a -> Radix1Tree a) -> Radix1Tree a -> Radix1Tree a
forall a b. (a -> b) -> a -> b
$ (Tsil ByteArray -> ByteArray -> a -> Maybe a)
-> Tsil ByteArray -> Radix1Tree a -> Radix1Tree a
forall a b.
(Tsil ByteArray -> ByteArray -> a -> Maybe b)
-> Tsil ByteArray -> Radix1Tree a -> Radix1Tree b
mapMaybeWithKey_ Tsil ByteArray -> ByteArray -> a -> Maybe a
f (Tsil ByteArray -> ByteArray -> Tsil ByteArray
forall a. Tsil a -> a -> Tsil a
Snoc Tsil ByteArray
b ByteArray
arr) Radix1Tree a
dx
| Bool
otherwise ->
case x -> Step Prefix x
step x
z of
More Prefix
u x
z' -> Prefix -> x -> Int -> Radix1Tree a
goarr Prefix
u x
z' Int
n'
Step Prefix x
Done -> (Tsil ByteArray -> ByteArray -> a -> Maybe a)
-> Tsil ByteArray -> Radix1Tree a -> Radix1Tree a
forall a b.
(Tsil ByteArray -> ByteArray -> a -> Maybe b)
-> Tsil ByteArray -> Radix1Tree a -> Radix1Tree b
mapMaybeWithKey_ Tsil ByteArray -> ByteArray -> a -> Maybe a
f Tsil ByteArray
b Radix1Tree a
t
Ordering
GT -> (Tsil ByteArray -> ByteArray -> a -> Maybe a)
-> Tsil ByteArray -> Radix1Tree a -> Radix1Tree a
forall a b.
(Tsil ByteArray -> ByteArray -> a -> Maybe b)
-> Tsil ByteArray -> Radix1Tree a -> Radix1Tree b
mapMaybeWithKey_ Tsil ByteArray -> ByteArray -> a -> Maybe a
f Tsil ByteArray
b Radix1Tree a
t
Ordering
LT -> Radix1Tree a
t
Radix1Tree a
Nil -> Radix1Tree a
forall a. Radix1Tree a
Nil
{-# INLINE takeL0 #-}
takeL0 :: Openness -> Feed -> RadixTree a -> RadixTree a
takeL0 :: forall a. Openness -> Feed -> RadixTree a -> RadixTree a
takeL0 Openness
openness (Feed forall a. (forall x. (x -> Step Prefix x) -> x -> a) -> a
feed) = \(RadixTree Maybe a
mx Radix1Tree a
t) ->
(forall x. (x -> Step Prefix x) -> x -> RadixTree a) -> RadixTree a
forall a. (forall x. (x -> Step Prefix x) -> x -> a) -> a
feed ((forall x. (x -> Step Prefix x) -> x -> RadixTree a)
-> RadixTree a)
-> (forall x. (x -> Step Prefix x) -> x -> RadixTree a)
-> RadixTree a
forall a b. (a -> b) -> a -> b
$ \x -> Step Prefix x
step x
s ->
case x -> Step Prefix x
step x
s of
More Prefix
w x
z -> Maybe a -> Radix1Tree a -> RadixTree a
forall a. Maybe a -> Radix1Tree a -> RadixTree a
RadixTree Maybe a
mx (Radix1Tree a -> RadixTree a) -> Radix1Tree a -> RadixTree a
forall a b. (a -> b) -> a -> b
$ Openness
-> (x -> Step Prefix x)
-> Prefix
-> x
-> Radix1Tree a
-> Radix1Tree a
forall x a.
Openness
-> (x -> Step Prefix x)
-> Prefix
-> x
-> Radix1Tree a
-> Radix1Tree a
takeL_ Openness
openness x -> Step Prefix x
step Prefix
w x
z Radix1Tree a
t
Step Prefix x
Done ->
let my :: Maybe a
my = case Openness
openness of
Openness
Open -> Maybe a
forall a. Maybe a
Nothing
Openness
Closed -> Maybe a
mx
in Maybe a -> Radix1Tree a -> RadixTree a
forall a. Maybe a -> Radix1Tree a -> RadixTree a
RadixTree Maybe a
my Radix1Tree a
forall a. Radix1Tree a
Nil
{-# INLINE takeL1 #-}
takeL1 :: Openness -> Feed1 -> Radix1Tree a -> Radix1Tree a
takeL1 :: forall a. Openness -> Feed1 -> Radix1Tree a -> Radix1Tree a
takeL1 Openness
openness (Feed1 Prefix
w0 forall a. (forall x. (x -> Step Prefix x) -> x -> a) -> a
feed) = (forall x.
(x -> Step Prefix x) -> x -> Radix1Tree a -> Radix1Tree a)
-> Radix1Tree a -> Radix1Tree a
forall a. (forall x. (x -> Step Prefix x) -> x -> a) -> a
feed ((forall x.
(x -> Step Prefix x) -> x -> Radix1Tree a -> Radix1Tree a)
-> Radix1Tree a -> Radix1Tree a)
-> (forall x.
(x -> Step Prefix x) -> x -> Radix1Tree a -> Radix1Tree a)
-> Radix1Tree a
-> Radix1Tree a
forall a b. (a -> b) -> a -> b
$ \x -> Step Prefix x
step -> Openness
-> (x -> Step Prefix x)
-> Prefix
-> x
-> Radix1Tree a
-> Radix1Tree a
forall x a.
Openness
-> (x -> Step Prefix x)
-> Prefix
-> x
-> Radix1Tree a
-> Radix1Tree a
takeL_ Openness
openness x -> Step Prefix x
step Prefix
w0
{-# INLINE takeL_ #-}
takeL_ :: Openness -> (x -> Step Prefix x) -> Prefix -> x -> Radix1Tree a -> Radix1Tree a
takeL_ :: forall x a.
Openness
-> (x -> Step Prefix x)
-> Prefix
-> x
-> Radix1Tree a
-> Radix1Tree a
takeL_ Openness
openness x -> Step Prefix x
step = Prefix -> x -> Radix1Tree a -> Radix1Tree a
go
where
go :: Prefix -> x -> Radix1Tree a -> Radix1Tree a
go Prefix
w x
s Radix1Tree a
t =
case Radix1Tree a
t of
Bin Prefix
p Radix1Tree a
l Radix1Tree a
r ->
if Prefix
w Prefix -> Prefix -> Bool
forall a. Ord a => a -> a -> Bool
< Prefix
p
then if Prefix
w Prefix -> Prefix -> Bool
forall a. Ord a => a -> a -> Bool
>= Prefix -> Prefix
lower Prefix
p
then Prefix -> x -> Radix1Tree a -> Radix1Tree a
go Prefix
w x
s Radix1Tree a
l
else Radix1Tree a
forall a. Radix1Tree a
Nil
else if Prefix
w Prefix -> Prefix -> Bool
forall a. Ord a => a -> a -> Bool
<= Prefix -> Prefix
upper Prefix
p
then Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
forall a. Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
rebinR Prefix
p Radix1Tree a
l (Prefix -> x -> Radix1Tree a -> Radix1Tree a
go Prefix
w x
s Radix1Tree a
r)
else Radix1Tree a
t
Tip ByteArray
arr Maybe a
mx Radix1Tree a
dx -> Prefix -> x -> Int -> Radix1Tree a
goarr Prefix
w x
s Int
0
where
goarr :: Prefix -> x -> Int -> Radix1Tree a
goarr Prefix
v x
z Int
n =
let n' :: Int
n' = Int
n Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1
in case ByteArray -> Int -> Prefix
forall a. Prim a => ByteArray -> Int -> a
indexByteArray ByteArray
arr Int
n Prefix -> Prefix -> Ordering
forall a. Ord a => a -> a -> Ordering
`compare` Prefix
v of
Ordering
EQ | Int
n' Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= ByteArray -> Int
sizeofByteArray ByteArray
arr ->
case x -> Step Prefix x
step x
z of
More Prefix
u x
z' -> ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
retip ByteArray
arr Maybe a
mx (Radix1Tree a -> Radix1Tree a) -> Radix1Tree a -> Radix1Tree a
forall a b. (a -> b) -> a -> b
$ Prefix -> x -> Radix1Tree a -> Radix1Tree a
go Prefix
u x
z' Radix1Tree a
dx
Step Prefix x
Done ->
case Openness
openness of
Openness
Open -> Radix1Tree a
forall a. Radix1Tree a
Nil
Openness
Closed -> ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
retip ByteArray
arr Maybe a
mx Radix1Tree a
forall a. Radix1Tree a
Nil
| Bool
otherwise ->
case x -> Step Prefix x
step x
z of
More Prefix
u x
z' -> Prefix -> x -> Int -> Radix1Tree a
goarr Prefix
u x
z' Int
n'
Step Prefix x
Done -> Radix1Tree a
forall a. Radix1Tree a
Nil
Ordering
LT -> Radix1Tree a
t
Ordering
GT -> Radix1Tree a
forall a. Radix1Tree a
Nil
Radix1Tree a
Nil -> Radix1Tree a
forall a. Radix1Tree a
Nil
{-# INLINE takeR0 #-}
takeR0 :: Openness -> Feed -> RadixTree a -> RadixTree a
takeR0 :: forall a. Openness -> Feed -> RadixTree a -> RadixTree a
takeR0 Openness
openness (Feed forall a. (forall x. (x -> Step Prefix x) -> x -> a) -> a
feed) (RadixTree Maybe a
mx Radix1Tree a
t) =
(forall x. (x -> Step Prefix x) -> x -> RadixTree a) -> RadixTree a
forall a. (forall x. (x -> Step Prefix x) -> x -> a) -> a
feed ((forall x. (x -> Step Prefix x) -> x -> RadixTree a)
-> RadixTree a)
-> (forall x. (x -> Step Prefix x) -> x -> RadixTree a)
-> RadixTree a
forall a b. (a -> b) -> a -> b
$ \x -> Step Prefix x
step x
s ->
case x -> Step Prefix x
step x
s of
More Prefix
w x
z -> Maybe a -> Radix1Tree a -> RadixTree a
forall a. Maybe a -> Radix1Tree a -> RadixTree a
RadixTree Maybe a
forall a. Maybe a
Nothing (Radix1Tree a -> RadixTree a) -> Radix1Tree a -> RadixTree a
forall a b. (a -> b) -> a -> b
$ Openness
-> (x -> Step Prefix x)
-> Prefix
-> x
-> Radix1Tree a
-> Radix1Tree a
forall x a.
Openness
-> (x -> Step Prefix x)
-> Prefix
-> x
-> Radix1Tree a
-> Radix1Tree a
takeR_ Openness
openness x -> Step Prefix x
step Prefix
w x
z Radix1Tree a
t
Step Prefix x
Done ->
let my :: Maybe a
my = case Openness
openness of
Openness
Open -> Maybe a
forall a. Maybe a
Nothing
Openness
Closed -> Maybe a
mx
in Maybe a -> Radix1Tree a -> RadixTree a
forall a. Maybe a -> Radix1Tree a -> RadixTree a
RadixTree Maybe a
my Radix1Tree a
t
{-# INLINE takeR1 #-}
takeR1 :: Openness -> Feed1 -> Radix1Tree a -> Radix1Tree a
takeR1 :: forall a. Openness -> Feed1 -> Radix1Tree a -> Radix1Tree a
takeR1 Openness
openness (Feed1 Prefix
w0 forall a. (forall x. (x -> Step Prefix x) -> x -> a) -> a
feed) = (forall x.
(x -> Step Prefix x) -> x -> Radix1Tree a -> Radix1Tree a)
-> Radix1Tree a -> Radix1Tree a
forall a. (forall x. (x -> Step Prefix x) -> x -> a) -> a
feed ((forall x.
(x -> Step Prefix x) -> x -> Radix1Tree a -> Radix1Tree a)
-> Radix1Tree a -> Radix1Tree a)
-> (forall x.
(x -> Step Prefix x) -> x -> Radix1Tree a -> Radix1Tree a)
-> Radix1Tree a
-> Radix1Tree a
forall a b. (a -> b) -> a -> b
$ \x -> Step Prefix x
step -> Openness
-> (x -> Step Prefix x)
-> Prefix
-> x
-> Radix1Tree a
-> Radix1Tree a
forall x a.
Openness
-> (x -> Step Prefix x)
-> Prefix
-> x
-> Radix1Tree a
-> Radix1Tree a
takeR_ Openness
openness x -> Step Prefix x
step Prefix
w0
{-# INLINE takeR_ #-}
takeR_ :: Openness -> (x -> Step Prefix x) -> Prefix -> x -> Radix1Tree a -> Radix1Tree a
takeR_ :: forall x a.
Openness
-> (x -> Step Prefix x)
-> Prefix
-> x
-> Radix1Tree a
-> Radix1Tree a
takeR_ Openness
openness x -> Step Prefix x
step = Prefix -> x -> Radix1Tree a -> Radix1Tree a
go
where
go :: Prefix -> x -> Radix1Tree a -> Radix1Tree a
go Prefix
w x
s Radix1Tree a
t =
case Radix1Tree a
t of
Bin Prefix
p Radix1Tree a
l Radix1Tree a
r ->
if Prefix
w Prefix -> Prefix -> Bool
forall a. Ord a => a -> a -> Bool
< Prefix
p
then if Prefix
w Prefix -> Prefix -> Bool
forall a. Ord a => a -> a -> Bool
>= Prefix -> Prefix
lower Prefix
p
then Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
forall a. Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
rebinL Prefix
p (Prefix -> x -> Radix1Tree a -> Radix1Tree a
go Prefix
w x
s Radix1Tree a
l) Radix1Tree a
r
else Radix1Tree a
t
else if Prefix
w Prefix -> Prefix -> Bool
forall a. Ord a => a -> a -> Bool
<= Prefix -> Prefix
upper Prefix
p
then Prefix -> x -> Radix1Tree a -> Radix1Tree a
go Prefix
w x
s Radix1Tree a
r
else Radix1Tree a
forall a. Radix1Tree a
Nil
Tip ByteArray
arr Maybe a
mx Radix1Tree a
dx -> Prefix -> x -> Int -> Radix1Tree a
goarr Prefix
w x
s Int
0
where
goarr :: Prefix -> x -> Int -> Radix1Tree a
goarr Prefix
v x
z Int
n =
let n' :: Int
n' = Int
n Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1
in case ByteArray -> Int -> Prefix
forall a. Prim a => ByteArray -> Int -> a
indexByteArray ByteArray
arr Int
n Prefix -> Prefix -> Ordering
forall a. Ord a => a -> a -> Ordering
`compare` Prefix
v of
Ordering
EQ | Int
n' Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= ByteArray -> Int
sizeofByteArray ByteArray
arr ->
case x -> Step Prefix x
step x
z of
More Prefix
u x
z' -> ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
retip ByteArray
arr Maybe a
forall a. Maybe a
Nothing (Radix1Tree a -> Radix1Tree a) -> Radix1Tree a -> Radix1Tree a
forall a b. (a -> b) -> a -> b
$ Prefix -> x -> Radix1Tree a -> Radix1Tree a
go Prefix
u x
z' Radix1Tree a
dx
Step Prefix x
Done ->
let my :: Maybe a
my = case Openness
openness of
Openness
Open -> Maybe a
forall a. Maybe a
Nothing
Openness
Closed -> Maybe a
mx
in ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
retip ByteArray
arr Maybe a
my Radix1Tree a
dx
| Bool
otherwise ->
case x -> Step Prefix x
step x
z of
More Prefix
u x
z' -> Prefix -> x -> Int -> Radix1Tree a
goarr Prefix
u x
z' Int
n'
Step Prefix x
Done -> Radix1Tree a
t
Ordering
GT -> Radix1Tree a
t
Ordering
LT -> Radix1Tree a
forall a. Radix1Tree a
Nil
Radix1Tree a
Nil -> Radix1Tree a
forall a. Radix1Tree a
Nil
type UBin a = (# Prefix, Radix1Tree a, Radix1Tree a #)
type UTip a = (# Key, Int, ByteArray, Maybe a, Radix1Tree a #)
union0 :: RadixTree a -> RadixTree a -> RadixTree a
union0 :: forall a. RadixTree a -> RadixTree a -> RadixTree a
union0 (RadixTree Maybe a
mA Radix1Tree a
tA) (RadixTree Maybe a
mB Radix1Tree a
tB) = Maybe a -> Radix1Tree a -> RadixTree a
forall a. Maybe a -> Radix1Tree a -> RadixTree a
RadixTree (Maybe a
mA Maybe a -> Maybe a -> Maybe a
forall a. Maybe a -> Maybe a -> Maybe a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Maybe a
mB) (Radix1Tree a -> Radix1Tree a -> Radix1Tree a
forall a. Radix1Tree a -> Radix1Tree a -> Radix1Tree a
union1 Radix1Tree a
tA Radix1Tree a
tB)
union1 :: Radix1Tree a -> Radix1Tree a -> Radix1Tree a
union1 :: forall a. Radix1Tree a -> Radix1Tree a -> Radix1Tree a
union1 = Radix1Tree a -> Radix1Tree a -> Radix1Tree a
forall a. Radix1Tree a -> Radix1Tree a -> Radix1Tree a
anyAny
where
anyAny :: Radix1Tree a -> Radix1Tree a -> Radix1Tree a
anyAny Radix1Tree a
tA Radix1Tree a
tB =
case Radix1Tree a
tA of
Bin Prefix
pA Radix1Tree a
lA Radix1Tree a
rA -> (# Prefix, Radix1Tree a, Radix1Tree a #)
-> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
binAny (# Prefix
pA, Radix1Tree a
lA, Radix1Tree a
rA #) Radix1Tree a
tA Radix1Tree a
tB
Tip ByteArray
arrA Maybe a
mA Radix1Tree a
dA -> let !wA :: Prefix
wA = ByteArray -> Int -> Prefix
forall a. Prim a => ByteArray -> Int -> a
indexByteArray ByteArray
arrA Int
0
in (# Prefix, Int, ByteArray, Maybe a, Radix1Tree a #)
-> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
tipAny (# Prefix
wA, Int
0, ByteArray
arrA, Maybe a
mA, Radix1Tree a
dA #) Radix1Tree a
tA Radix1Tree a
tB
Radix1Tree a
Nil -> Radix1Tree a
tB
tipAny :: (# Prefix, Int, ByteArray, Maybe a, Radix1Tree a #)
-> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
tipAny uA :: (# Prefix, Int, ByteArray, Maybe a, Radix1Tree a #)
uA@(# Prefix
_, Int
nA, ByteArray
arrA, Maybe a
mA, Radix1Tree a
dA #) Radix1Tree a
tA Radix1Tree a
tB =
case Radix1Tree a
tB of
Bin Prefix
pB Radix1Tree a
lB Radix1Tree a
rB -> (# Prefix, Int, ByteArray, Maybe a, Radix1Tree a #)
-> Radix1Tree a
-> (# Prefix, Radix1Tree a, Radix1Tree a #)
-> Radix1Tree a
-> Radix1Tree a
tipBin (# Prefix, Int, ByteArray, Maybe a, Radix1Tree a #)
uA Radix1Tree a
tA (# Prefix
pB, Radix1Tree a
lB, Radix1Tree a
rB #) Radix1Tree a
tB
Tip ByteArray
arrB Maybe a
mB Radix1Tree a
dB -> let !wB :: Prefix
wB = ByteArray -> Int -> Prefix
forall a. Prim a => ByteArray -> Int -> a
indexByteArray ByteArray
arrB Int
0
uB :: (# Prefix, Int, ByteArray, Maybe a, Radix1Tree a #)
uB = (# Prefix
wB, Int
0, ByteArray
arrB, Maybe a
mB, Radix1Tree a
dB #)
!lenA :: Int
lenA = ByteArray -> Int
sizeofByteArray ByteArray
arrA Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
nA
!lenB :: Int
lenB = ByteArray -> Int
sizeofByteArray ByteArray
arrB
in if Int
lenB Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
lenA
then (# Prefix, Int, ByteArray, Maybe a, Radix1Tree a #)
-> Radix1Tree a
-> (# Prefix, Int, ByteArray, Maybe a, Radix1Tree a #)
-> Radix1Tree a
-> Int
-> Radix1Tree a
tipTip (# Prefix, Int, ByteArray, Maybe a, Radix1Tree a #)
uA Radix1Tree a
tA (# Prefix, Int, ByteArray, Maybe a, Radix1Tree a #)
uB Radix1Tree a
tB Int
lenA
else (# Prefix, Int, ByteArray, Maybe a, Radix1Tree a #)
-> Radix1Tree a
-> (# Prefix, Int, ByteArray, Maybe a, Radix1Tree a #)
-> Radix1Tree a
-> Int
-> Radix1Tree a
tipTip (# Prefix, Int, ByteArray, Maybe a, Radix1Tree a #)
uB Radix1Tree a
tB (# Prefix, Int, ByteArray, Maybe a, Radix1Tree a #)
uA Radix1Tree a
tA Int
lenB
Radix1Tree a
Nil | Int
nA Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
0 -> Radix1Tree a
tA
| Bool
otherwise -> ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
Tip (Int -> ByteArray -> ByteArray
dropByteArray Int
nA ByteArray
arrA) Maybe a
mA Radix1Tree a
dA
tipTip :: (# Prefix, Int, ByteArray, Maybe a, Radix1Tree a #)
-> Radix1Tree a
-> (# Prefix, Int, ByteArray, Maybe a, Radix1Tree a #)
-> Radix1Tree a
-> Int
-> Radix1Tree a
tipTip (# Prefix
wA0, Int
nA, ByteArray
arrA, Maybe a
mA, Radix1Tree a
dA #) Radix1Tree a
tA (# Prefix
wB0, Int
nB, ByteArray
arrB, Maybe a
mB, Radix1Tree a
dB #) Radix1Tree a
tB Int
len =
Prefix -> Prefix -> Int -> Radix1Tree a
go Prefix
wA0 Prefix
wB0 Int
1
where
go :: Prefix -> Prefix -> Int -> Radix1Tree a
go Prefix
wA Prefix
wB !Int
o
| Prefix
wA Prefix -> Prefix -> Bool
forall a. Eq a => a -> a -> Bool
== Prefix
wB =
let !nB' :: Int
nB' = Int
nB Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
o
!wB' :: Prefix
wB' = ByteArray -> Int -> Prefix
forall a. Prim a => ByteArray -> Int -> a
indexByteArray ByteArray
arrB Int
nB'
in if Int
o Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
len
then let !arrA' :: ByteArray
arrA' | Int
nA Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
0 = ByteArray
arrA
| Bool
otherwise = Int -> ByteArray -> ByteArray
dropByteArray Int
nA ByteArray
arrA
in if Int
nB' Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== ByteArray -> Int
sizeofByteArray ByteArray
arrB
then ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
Tip ByteArray
arrA' (Maybe a
mA Maybe a -> Maybe a -> Maybe a
forall a. Maybe a -> Maybe a -> Maybe a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Maybe a
mB) (Radix1Tree a -> Radix1Tree a -> Radix1Tree a
anyAny Radix1Tree a
dA Radix1Tree a
dB)
else ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
Tip ByteArray
arrA' Maybe a
mA (Radix1Tree a -> Radix1Tree a) -> Radix1Tree a -> Radix1Tree a
forall a b. (a -> b) -> a -> b
$
(# Prefix, Int, ByteArray, Maybe a, Radix1Tree a #)
-> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
tipAny (# Prefix
wB', Int
nB', ByteArray
arrB, Maybe a
mB, Radix1Tree a
dB #) Radix1Tree a
tB Radix1Tree a
dA
else let !nA' :: Int
nA' = Int
nA Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
o
!wA' :: Prefix
wA' = ByteArray -> Int -> Prefix
forall a. Prim a => ByteArray -> Int -> a
indexByteArray ByteArray
arrA Int
nA'
in Prefix -> Prefix -> Int -> Radix1Tree a
go Prefix
wA' Prefix
wB' (Int
o Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1)
| Int
o Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
1 =
let !tA' :: Radix1Tree a
tA' | Int
nA Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
0 = Radix1Tree a
tA
| Bool
otherwise = ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
Tip (Int -> ByteArray -> ByteArray
dropByteArray Int
nA ByteArray
arrA) Maybe a
mA Radix1Tree a
dA
!tB' :: Radix1Tree a
tB' | Int
nB Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
0 = Radix1Tree a
tB
| Bool
otherwise = ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
Tip (Int -> ByteArray -> ByteArray
dropByteArray Int
nB ByteArray
arrB) Maybe a
mB Radix1Tree a
dB
in Prefix -> Radix1Tree a -> Prefix -> Radix1Tree a -> Radix1Tree a
forall a.
Prefix -> Radix1Tree a -> Prefix -> Radix1Tree a -> Radix1Tree a
join Prefix
wA Radix1Tree a
tA' Prefix
wB Radix1Tree a
tB'
| Bool
otherwise =
let !o' :: Int
o' = Int
o Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1
!(# !ByteArray
arrC, !ByteArray
arrA' #) = Int -> Int -> ByteArray -> (# ByteArray, ByteArray #)
splitByteArray Int
nA Int
o' ByteArray
arrA
!arrB' :: ByteArray
arrB' = Int -> ByteArray -> ByteArray
dropByteArray (Int
nB Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
o') ByteArray
arrB
in ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
Tip ByteArray
arrC Maybe a
forall a. Maybe a
Nothing (Radix1Tree a -> Radix1Tree a) -> Radix1Tree a -> Radix1Tree a
forall a b. (a -> b) -> a -> b
$ Prefix -> Radix1Tree a -> Prefix -> Radix1Tree a -> Radix1Tree a
forall a.
Prefix -> Radix1Tree a -> Prefix -> Radix1Tree a -> Radix1Tree a
join Prefix
wA (ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
Tip ByteArray
arrA' Maybe a
mA Radix1Tree a
dA)
Prefix
wB (ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
Tip ByteArray
arrB' Maybe a
mB Radix1Tree a
dB)
binAny :: (# Prefix, Radix1Tree a, Radix1Tree a #)
-> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
binAny (# Prefix, Radix1Tree a, Radix1Tree a #)
uA Radix1Tree a
tA Radix1Tree a
tB =
case Radix1Tree a
tB of
Bin Prefix
pB Radix1Tree a
lB Radix1Tree a
rB -> (# Prefix, Radix1Tree a, Radix1Tree a #)
-> Radix1Tree a
-> (# Prefix, Radix1Tree a, Radix1Tree a #)
-> Radix1Tree a
-> Radix1Tree a
binBin (# Prefix, Radix1Tree a, Radix1Tree a #)
uA Radix1Tree a
tA (# Prefix
pB, Radix1Tree a
lB, Radix1Tree a
rB #) Radix1Tree a
tB
Tip ByteArray
arrB Maybe a
mB Radix1Tree a
dB -> let !wB :: Prefix
wB = ByteArray -> Int -> Prefix
forall a. Prim a => ByteArray -> Int -> a
indexByteArray ByteArray
arrB Int
0
in (# Prefix, Int, ByteArray, Maybe a, Radix1Tree a #)
-> Radix1Tree a
-> (# Prefix, Radix1Tree a, Radix1Tree a #)
-> Radix1Tree a
-> Radix1Tree a
tipBin (# Prefix
wB, Int
0, ByteArray
arrB, Maybe a
mB, Radix1Tree a
dB #) Radix1Tree a
tB (# Prefix, Radix1Tree a, Radix1Tree a #)
uA Radix1Tree a
tA
Radix1Tree a
Nil -> Radix1Tree a
tA
tipBin :: (# Prefix, Int, ByteArray, Maybe a, Radix1Tree a #)
-> Radix1Tree a
-> (# Prefix, Radix1Tree a, Radix1Tree a #)
-> Radix1Tree a
-> Radix1Tree a
tipBin uA :: (# Prefix, Int, ByteArray, Maybe a, Radix1Tree a #)
uA@(# Prefix
wA, Int
nA, ByteArray
arrA, Maybe a
mA, Radix1Tree a
dA #) Radix1Tree a
tA (# Prefix
pB, Radix1Tree a
lB, Radix1Tree a
rB #) Radix1Tree a
tB
| Prefix -> Prefix -> Bool
beyond Prefix
pB Prefix
wA = let !tA' :: Radix1Tree a
tA' | Int
nA Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
0 = Radix1Tree a
tA
| Bool
otherwise = ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
Tip (Int -> ByteArray -> ByteArray
dropByteArray Int
nA ByteArray
arrA) Maybe a
mA Radix1Tree a
dA
in Prefix -> Radix1Tree a -> Prefix -> Radix1Tree a -> Radix1Tree a
forall a.
Prefix -> Radix1Tree a -> Prefix -> Radix1Tree a -> Radix1Tree a
join Prefix
wA Radix1Tree a
tA' Prefix
pB Radix1Tree a
tB
| Prefix
wA Prefix -> Prefix -> Bool
forall a. Ord a => a -> a -> Bool
< Prefix
pB = Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
forall a. Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
Bin Prefix
pB ((# Prefix, Int, ByteArray, Maybe a, Radix1Tree a #)
-> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
tipAny (# Prefix, Int, ByteArray, Maybe a, Radix1Tree a #)
uA Radix1Tree a
tA Radix1Tree a
lB) Radix1Tree a
rB
| Bool
otherwise = Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
forall a. Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
Bin Prefix
pB Radix1Tree a
lB ((# Prefix, Int, ByteArray, Maybe a, Radix1Tree a #)
-> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
tipAny (# Prefix, Int, ByteArray, Maybe a, Radix1Tree a #)
uA Radix1Tree a
tA Radix1Tree a
rB)
binBin :: (# Prefix, Radix1Tree a, Radix1Tree a #)
-> Radix1Tree a
-> (# Prefix, Radix1Tree a, Radix1Tree a #)
-> Radix1Tree a
-> Radix1Tree a
binBin uA :: (# Prefix, Radix1Tree a, Radix1Tree a #)
uA@(# Prefix
pA, Radix1Tree a
lA, Radix1Tree a
rA #) Radix1Tree a
tA uB :: (# Prefix, Radix1Tree a, Radix1Tree a #)
uB@(# Prefix
pB, Radix1Tree a
lB, Radix1Tree a
rB #) Radix1Tree a
tB =
let {-# NOINLINE no #-}
no :: Radix1Tree a
no = Prefix -> Radix1Tree a -> Prefix -> Radix1Tree a -> Radix1Tree a
forall a.
Prefix -> Radix1Tree a -> Prefix -> Radix1Tree a -> Radix1Tree a
join Prefix
pA Radix1Tree a
tA Prefix
pB Radix1Tree a
tB
in case Prefix -> Prefix -> Ordering
forall a. Ord a => a -> a -> Ordering
Prelude.compare Prefix
pA Prefix
pB of
Ordering
EQ -> Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
forall a. Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
Bin Prefix
pA (Radix1Tree a -> Radix1Tree a -> Radix1Tree a
anyAny Radix1Tree a
lA Radix1Tree a
lB) (Radix1Tree a -> Radix1Tree a -> Radix1Tree a
anyAny Radix1Tree a
rA Radix1Tree a
rB)
Ordering
LT | Prefix
pB Prefix -> Prefix -> Bool
forall a. Ord a => a -> a -> Bool
<= Prefix -> Prefix
upper Prefix
pA -> Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
forall a. Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
Bin Prefix
pA Radix1Tree a
lA ((# Prefix, Radix1Tree a, Radix1Tree a #)
-> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
binAny (# Prefix, Radix1Tree a, Radix1Tree a #)
uB Radix1Tree a
tB Radix1Tree a
rA)
| Prefix
pA Prefix -> Prefix -> Bool
forall a. Ord a => a -> a -> Bool
>= Prefix -> Prefix
lower Prefix
pB -> Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
forall a. Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
Bin Prefix
pB ((# Prefix, Radix1Tree a, Radix1Tree a #)
-> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
binAny (# Prefix, Radix1Tree a, Radix1Tree a #)
uA Radix1Tree a
tA Radix1Tree a
lB) Radix1Tree a
rB
| Bool
otherwise -> Radix1Tree a
no
Ordering
GT | Prefix
pA Prefix -> Prefix -> Bool
forall a. Ord a => a -> a -> Bool
<= Prefix -> Prefix
upper Prefix
pB -> Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
forall a. Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
Bin Prefix
pB Radix1Tree a
lB ((# Prefix, Radix1Tree a, Radix1Tree a #)
-> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
binAny (# Prefix, Radix1Tree a, Radix1Tree a #)
uA Radix1Tree a
tA Radix1Tree a
rB)
| Prefix
pB Prefix -> Prefix -> Bool
forall a. Ord a => a -> a -> Bool
>= Prefix -> Prefix
lower Prefix
pA -> Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
forall a. Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
Bin Prefix
pA ((# Prefix, Radix1Tree a, Radix1Tree a #)
-> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
binAny (# Prefix, Radix1Tree a, Radix1Tree a #)
uB Radix1Tree a
tB Radix1Tree a
lA) Radix1Tree a
rA
| Bool
otherwise -> Radix1Tree a
no
unionL0 :: RadixTree a -> RadixTree a -> RadixTree a
unionL0 :: forall a. RadixTree a -> RadixTree a -> RadixTree a
unionL0 (RadixTree Maybe a
mA Radix1Tree a
tA) (RadixTree Maybe a
mB Radix1Tree a
tB) = Maybe a -> Radix1Tree a -> RadixTree a
forall a. Maybe a -> Radix1Tree a -> RadixTree a
RadixTree (Maybe a
mA Maybe a -> Maybe a -> Maybe a
forall a. Maybe a -> Maybe a -> Maybe a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Maybe a
mB) (Radix1Tree a -> Radix1Tree a -> Radix1Tree a
forall a. Radix1Tree a -> Radix1Tree a -> Radix1Tree a
unionL1 Radix1Tree a
tA Radix1Tree a
tB)
unionL1 :: Radix1Tree a -> Radix1Tree a -> Radix1Tree a
unionL1 :: forall a. Radix1Tree a -> Radix1Tree a -> Radix1Tree a
unionL1 =
(forall x y. S x y a a -> x -> y -> Maybe a)
-> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
forall a.
(forall x y. S x y a a -> x -> y -> Maybe a)
-> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
union_ ((forall x y. S x y a a -> x -> y -> Maybe a)
-> Radix1Tree a -> Radix1Tree a -> Radix1Tree a)
-> (forall x y. S x y a a -> x -> y -> Maybe a)
-> Radix1Tree a
-> Radix1Tree a
-> Radix1Tree a
forall a b. (a -> b) -> a -> b
$ \S x y a a
s x
a y
b ->
let !(# a
c #) = case S x y a a
s of
S x y a a
L -> (# x
a #)
S x y a a
R -> (# y
b #)
in a -> Maybe a
forall a. a -> Maybe a
Just a
c
unionWith0 :: (a -> a -> a) -> RadixTree a -> RadixTree a -> RadixTree a
unionWith0 :: forall a.
(a -> a -> a) -> RadixTree a -> RadixTree a -> RadixTree a
unionWith0 a -> a -> a
f (RadixTree Maybe a
mA Radix1Tree a
tA) (RadixTree Maybe a
mB Radix1Tree a
tB) =
let mC :: Maybe a
mC = case Maybe a
mA of
Just a
a -> case Maybe a
mB of
Just a
b -> a -> Maybe a
forall a. a -> Maybe a
Just (a -> Maybe a) -> a -> Maybe a
forall a b. (a -> b) -> a -> b
$ a -> a -> a
f a
a a
b
Maybe a
Nothing -> Maybe a
mA
Maybe a
Nothing -> Maybe a
mB
in Maybe a -> Radix1Tree a -> RadixTree a
forall a. Maybe a -> Radix1Tree a -> RadixTree a
RadixTree Maybe a
mC ((a -> a -> a) -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
forall a.
(a -> a -> a) -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
unionWith1 a -> a -> a
f Radix1Tree a
tA Radix1Tree a
tB)
unionWith1 :: (a -> a -> a) -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
unionWith1 :: forall a.
(a -> a -> a) -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
unionWith1 a -> a -> a
f =
(forall x y. S x y a a -> x -> y -> Maybe a)
-> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
forall a.
(forall x y. S x y a a -> x -> y -> Maybe a)
-> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
union_ ((forall x y. S x y a a -> x -> y -> Maybe a)
-> Radix1Tree a -> Radix1Tree a -> Radix1Tree a)
-> (forall x y. S x y a a -> x -> y -> Maybe a)
-> Radix1Tree a
-> Radix1Tree a
-> Radix1Tree a
forall a b. (a -> b) -> a -> b
$ \S x y a a
s x
a y
b ->
let !(# a
c #) = case S x y a a
s of
S x y a a
L -> (# a -> a -> a
f a
x
a a
y
b #)
S x y a a
R -> (# a -> a -> a
f a
y
b a
x
a #)
in a -> Maybe a
forall a. a -> Maybe a
Just a
c
{-# INLINE union_ #-}
union_
:: (forall x y. S x y a a -> x -> y -> Maybe a)
-> Radix1Tree a
-> Radix1Tree a
-> Radix1Tree a
union_ :: forall a.
(forall x y. S x y a a -> x -> y -> Maybe a)
-> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
union_ forall x y. S x y a a -> x -> y -> Maybe a
f = S a a a a -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
anyAny S a a a a
forall a b. S a b a b
L
where
anyAny :: S a a a a -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
anyAny S a a a a
s Radix1Tree a
tA Radix1Tree a
tB =
case Radix1Tree a
tA of
Bin Prefix
pA Radix1Tree a
lA Radix1Tree a
rA -> S a a a a
-> (# Prefix, Radix1Tree a, Radix1Tree a #)
-> Radix1Tree a
-> Radix1Tree a
-> Radix1Tree a
binAny S a a a a
s (# Prefix
pA, Radix1Tree a
lA, Radix1Tree a
rA #) Radix1Tree a
tA Radix1Tree a
tB
Tip ByteArray
arrA Maybe a
mA Radix1Tree a
dA -> let !wA :: Prefix
wA = ByteArray -> Int -> Prefix
forall a. Prim a => ByteArray -> Int -> a
indexByteArray ByteArray
arrA Int
0
in S a a a a
-> (# Prefix, Int, ByteArray, Maybe a, Radix1Tree a #)
-> Radix1Tree a
-> Radix1Tree a
-> Radix1Tree a
tipAny S a a a a
s (# Prefix
wA, Int
0, ByteArray
arrA, Maybe a
mA, Radix1Tree a
dA #) Radix1Tree a
tA Radix1Tree a
tB
Radix1Tree a
Nil -> Radix1Tree a
tB
tipAny :: S a a a a
-> (# Prefix, Int, ByteArray, Maybe a, Radix1Tree a #)
-> Radix1Tree a
-> Radix1Tree a
-> Radix1Tree a
tipAny S a a a a
s uA :: (# Prefix, Int, ByteArray, Maybe a, Radix1Tree a #)
uA@(# Prefix
_, Int
nA, ByteArray
arrA, Maybe a
mA, Radix1Tree a
dA #) Radix1Tree a
tA Radix1Tree a
tB =
case Radix1Tree a
tB of
Bin Prefix
pB Radix1Tree a
lB Radix1Tree a
rB -> S a a a a
-> (# Prefix, Int, ByteArray, Maybe a, Radix1Tree a #)
-> Radix1Tree a
-> (# Prefix, Radix1Tree a, Radix1Tree a #)
-> Radix1Tree a
-> Radix1Tree a
tipBin S a a a a
s (# Prefix, Int, ByteArray, Maybe a, Radix1Tree a #)
uA Radix1Tree a
tA (# Prefix
pB, Radix1Tree a
lB, Radix1Tree a
rB #) Radix1Tree a
tB
Tip ByteArray
arrB Maybe a
mB Radix1Tree a
dB -> let !wB :: Prefix
wB = ByteArray -> Int -> Prefix
forall a. Prim a => ByteArray -> Int -> a
indexByteArray ByteArray
arrB Int
0
uB :: (# Prefix, Int, ByteArray, Maybe a, Radix1Tree a #)
uB = (# Prefix
wB, Int
0, ByteArray
arrB, Maybe a
mB, Radix1Tree a
dB #)
!lenA :: Int
lenA = ByteArray -> Int
sizeofByteArray ByteArray
arrA Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
nA
!lenB :: Int
lenB = ByteArray -> Int
sizeofByteArray ByteArray
arrB
in if Int
lenB Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
lenA
then S a a a a
-> (# Prefix, Int, ByteArray, Maybe a, Radix1Tree a #)
-> Radix1Tree a
-> (# Prefix, Int, ByteArray, Maybe a, Radix1Tree a #)
-> Radix1Tree a
-> Int
-> Radix1Tree a
tipTip S a a a a
s (# Prefix, Int, ByteArray, Maybe a, Radix1Tree a #)
uA Radix1Tree a
tA (# Prefix, Int, ByteArray, Maybe a, Radix1Tree a #)
uB Radix1Tree a
tB Int
lenA
else let !(# S a a a a
s' #) = S a a a a -> (# S a a a a #)
forall a b x y. S a b x y -> (# S b a x y #)
other S a a a a
s
in S a a a a
-> (# Prefix, Int, ByteArray, Maybe a, Radix1Tree a #)
-> Radix1Tree a
-> (# Prefix, Int, ByteArray, Maybe a, Radix1Tree a #)
-> Radix1Tree a
-> Int
-> Radix1Tree a
tipTip S a a a a
s' (# Prefix, Int, ByteArray, Maybe a, Radix1Tree a #)
uB Radix1Tree a
tB (# Prefix, Int, ByteArray, Maybe a, Radix1Tree a #)
uA Radix1Tree a
tA Int
lenB
Radix1Tree a
Nil | Int
nA Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
0 -> Radix1Tree a
tA
| Bool
otherwise -> ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
Tip (Int -> ByteArray -> ByteArray
dropByteArray Int
nA ByteArray
arrA) Maybe a
mA Radix1Tree a
dA
tipTip :: S a a a a
-> (# Prefix, Int, ByteArray, Maybe a, Radix1Tree a #)
-> Radix1Tree a
-> (# Prefix, Int, ByteArray, Maybe a, Radix1Tree a #)
-> Radix1Tree a
-> Int
-> Radix1Tree a
tipTip S a a a a
s (# Prefix
wA0, Int
nA, ByteArray
arrA, Maybe a
mA, Radix1Tree a
dA #) Radix1Tree a
tA (# Prefix
wB0, Int
nB, ByteArray
arrB, Maybe a
mB, Radix1Tree a
dB #) Radix1Tree a
tB Int
len =
Prefix -> Prefix -> Int -> Radix1Tree a
go Prefix
wA0 Prefix
wB0 Int
1
where
go :: Prefix -> Prefix -> Int -> Radix1Tree a
go Prefix
wA Prefix
wB !Int
o
| Prefix
wA Prefix -> Prefix -> Bool
forall a. Eq a => a -> a -> Bool
== Prefix
wB =
let !nB' :: Int
nB' = Int
nB Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
o
!wB' :: Prefix
wB' = ByteArray -> Int -> Prefix
forall a. Prim a => ByteArray -> Int -> a
indexByteArray ByteArray
arrB Int
nB'
in if Int
o Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
len
then let !arrA' :: ByteArray
arrA' | Int
nA Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
0 = ByteArray
arrA
| Bool
otherwise = Int -> ByteArray -> ByteArray
dropByteArray Int
nA ByteArray
arrA
in if Int
nB' Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== ByteArray -> Int
sizeofByteArray ByteArray
arrB
then let mC :: Maybe a
mC = case Maybe a
mA of
Just a
a -> case Maybe a
mB of
Just a
b -> S a a a a -> a -> a -> Maybe a
forall x y. S x y a a -> x -> y -> Maybe a
f S a a a a
s a
a a
b
Maybe a
Nothing -> Maybe a
mA
Maybe a
Nothing -> Maybe a
mB
in ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
Tip ByteArray
arrA' Maybe a
mC (S a a a a -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
anyAny S a a a a
s Radix1Tree a
dA Radix1Tree a
dB)
else ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
Tip ByteArray
arrA' Maybe a
mA (Radix1Tree a -> Radix1Tree a) -> Radix1Tree a -> Radix1Tree a
forall a b. (a -> b) -> a -> b
$
let !(# S a a a a
s' #) = S a a a a -> (# S a a a a #)
forall a b x y. S a b x y -> (# S b a x y #)
other S a a a a
s
in S a a a a
-> (# Prefix, Int, ByteArray, Maybe a, Radix1Tree a #)
-> Radix1Tree a
-> Radix1Tree a
-> Radix1Tree a
tipAny S a a a a
s' (# Prefix
wB', Int
nB', ByteArray
arrB, Maybe a
mB, Radix1Tree a
dB #) Radix1Tree a
tB Radix1Tree a
dA
else let !nA' :: Int
nA' = Int
nA Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
o
!wA' :: Prefix
wA' = ByteArray -> Int -> Prefix
forall a. Prim a => ByteArray -> Int -> a
indexByteArray ByteArray
arrA Int
nA'
in Prefix -> Prefix -> Int -> Radix1Tree a
go Prefix
wA' Prefix
wB' (Int
o Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1)
| Int
o Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
1 =
let !tA' :: Radix1Tree a
tA' | Int
nA Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
0 = Radix1Tree a
tA
| Bool
otherwise = ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
Tip (Int -> ByteArray -> ByteArray
dropByteArray Int
nA ByteArray
arrA) Maybe a
mA Radix1Tree a
dA
!tB' :: Radix1Tree a
tB' | Int
nB Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
0 = Radix1Tree a
tB
| Bool
otherwise = ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
Tip (Int -> ByteArray -> ByteArray
dropByteArray Int
nB ByteArray
arrB) Maybe a
mB Radix1Tree a
dB
in Prefix -> Radix1Tree a -> Prefix -> Radix1Tree a -> Radix1Tree a
forall a.
Prefix -> Radix1Tree a -> Prefix -> Radix1Tree a -> Radix1Tree a
join Prefix
wA Radix1Tree a
tA' Prefix
wB Radix1Tree a
tB'
| Bool
otherwise =
let !o' :: Int
o' = Int
o Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1
!(# !ByteArray
arrC, !ByteArray
arrA' #) = Int -> Int -> ByteArray -> (# ByteArray, ByteArray #)
splitByteArray Int
nA Int
o' ByteArray
arrA
!arrB' :: ByteArray
arrB' = Int -> ByteArray -> ByteArray
dropByteArray (Int
nB Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
o') ByteArray
arrB
in ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
Tip ByteArray
arrC Maybe a
forall a. Maybe a
Nothing (Radix1Tree a -> Radix1Tree a) -> Radix1Tree a -> Radix1Tree a
forall a b. (a -> b) -> a -> b
$ Prefix -> Radix1Tree a -> Prefix -> Radix1Tree a -> Radix1Tree a
forall a.
Prefix -> Radix1Tree a -> Prefix -> Radix1Tree a -> Radix1Tree a
join Prefix
wA (ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
Tip ByteArray
arrA' Maybe a
mA Radix1Tree a
dA)
Prefix
wB (ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
Tip ByteArray
arrB' Maybe a
mB Radix1Tree a
dB)
binAny :: S a a a a
-> (# Prefix, Radix1Tree a, Radix1Tree a #)
-> Radix1Tree a
-> Radix1Tree a
-> Radix1Tree a
binAny S a a a a
s (# Prefix, Radix1Tree a, Radix1Tree a #)
uA Radix1Tree a
tA Radix1Tree a
tB =
case Radix1Tree a
tB of
Bin Prefix
pB Radix1Tree a
lB Radix1Tree a
rB -> S a a a a
-> (# Prefix, Radix1Tree a, Radix1Tree a #)
-> Radix1Tree a
-> (# Prefix, Radix1Tree a, Radix1Tree a #)
-> Radix1Tree a
-> Radix1Tree a
binBin S a a a a
s (# Prefix, Radix1Tree a, Radix1Tree a #)
uA Radix1Tree a
tA (# Prefix
pB, Radix1Tree a
lB, Radix1Tree a
rB #) Radix1Tree a
tB
Tip ByteArray
arrB Maybe a
mB Radix1Tree a
dB -> let !(# S a a a a
s' #) = S a a a a -> (# S a a a a #)
forall a b x y. S a b x y -> (# S b a x y #)
other S a a a a
s
!wB :: Prefix
wB = ByteArray -> Int -> Prefix
forall a. Prim a => ByteArray -> Int -> a
indexByteArray ByteArray
arrB Int
0
in S a a a a
-> (# Prefix, Int, ByteArray, Maybe a, Radix1Tree a #)
-> Radix1Tree a
-> (# Prefix, Radix1Tree a, Radix1Tree a #)
-> Radix1Tree a
-> Radix1Tree a
tipBin S a a a a
s' (# Prefix
wB, Int
0, ByteArray
arrB, Maybe a
mB, Radix1Tree a
dB #) Radix1Tree a
tB (# Prefix, Radix1Tree a, Radix1Tree a #)
uA Radix1Tree a
tA
Radix1Tree a
Nil -> Radix1Tree a
tA
tipBin :: S a a a a
-> (# Prefix, Int, ByteArray, Maybe a, Radix1Tree a #)
-> Radix1Tree a
-> (# Prefix, Radix1Tree a, Radix1Tree a #)
-> Radix1Tree a
-> Radix1Tree a
tipBin S a a a a
s uA :: (# Prefix, Int, ByteArray, Maybe a, Radix1Tree a #)
uA@(# Prefix
wA, Int
nA, ByteArray
arrA, Maybe a
mA, Radix1Tree a
dA #) Radix1Tree a
tA (# Prefix
pB, Radix1Tree a
lB, Radix1Tree a
rB #) Radix1Tree a
tB
| Prefix -> Prefix -> Bool
beyond Prefix
pB Prefix
wA = let !tA' :: Radix1Tree a
tA' | Int
nA Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
0 = Radix1Tree a
tA
| Bool
otherwise = ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
Tip (Int -> ByteArray -> ByteArray
dropByteArray Int
nA ByteArray
arrA) Maybe a
mA Radix1Tree a
dA
in Prefix -> Radix1Tree a -> Prefix -> Radix1Tree a -> Radix1Tree a
forall a.
Prefix -> Radix1Tree a -> Prefix -> Radix1Tree a -> Radix1Tree a
join Prefix
wA Radix1Tree a
tA' Prefix
pB Radix1Tree a
tB
| Prefix
wA Prefix -> Prefix -> Bool
forall a. Ord a => a -> a -> Bool
< Prefix
pB = Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
forall a. Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
Bin Prefix
pB (S a a a a
-> (# Prefix, Int, ByteArray, Maybe a, Radix1Tree a #)
-> Radix1Tree a
-> Radix1Tree a
-> Radix1Tree a
tipAny S a a a a
s (# Prefix, Int, ByteArray, Maybe a, Radix1Tree a #)
uA Radix1Tree a
tA Radix1Tree a
lB) Radix1Tree a
rB
| Bool
otherwise = Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
forall a. Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
Bin Prefix
pB Radix1Tree a
lB (S a a a a
-> (# Prefix, Int, ByteArray, Maybe a, Radix1Tree a #)
-> Radix1Tree a
-> Radix1Tree a
-> Radix1Tree a
tipAny S a a a a
s (# Prefix, Int, ByteArray, Maybe a, Radix1Tree a #)
uA Radix1Tree a
tA Radix1Tree a
rB)
binBin :: S a a a a
-> (# Prefix, Radix1Tree a, Radix1Tree a #)
-> Radix1Tree a
-> (# Prefix, Radix1Tree a, Radix1Tree a #)
-> Radix1Tree a
-> Radix1Tree a
binBin S a a a a
s uA :: (# Prefix, Radix1Tree a, Radix1Tree a #)
uA@(# Prefix
pA, Radix1Tree a
lA, Radix1Tree a
rA #) Radix1Tree a
tA uB :: (# Prefix, Radix1Tree a, Radix1Tree a #)
uB@(# Prefix
pB, Radix1Tree a
lB, Radix1Tree a
rB #) Radix1Tree a
tB =
let {-# NOINLINE no #-}
no :: Radix1Tree a
no = Prefix -> Radix1Tree a -> Prefix -> Radix1Tree a -> Radix1Tree a
forall a.
Prefix -> Radix1Tree a -> Prefix -> Radix1Tree a -> Radix1Tree a
join Prefix
pA Radix1Tree a
tA Prefix
pB Radix1Tree a
tB
in case Prefix -> Prefix -> Ordering
forall a. Ord a => a -> a -> Ordering
Prelude.compare Prefix
pA Prefix
pB of
Ordering
EQ -> Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
forall a. Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
Bin Prefix
pA (S a a a a -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
anyAny S a a a a
s Radix1Tree a
lA Radix1Tree a
lB) (S a a a a -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
anyAny S a a a a
s Radix1Tree a
rA Radix1Tree a
rB)
Ordering
LT | Prefix
pB Prefix -> Prefix -> Bool
forall a. Ord a => a -> a -> Bool
<= Prefix -> Prefix
upper Prefix
pA -> let !(# S a a a a
s' #) = S a a a a -> (# S a a a a #)
forall a b x y. S a b x y -> (# S b a x y #)
other S a a a a
s
in Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
forall a. Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
Bin Prefix
pA Radix1Tree a
lA (S a a a a
-> (# Prefix, Radix1Tree a, Radix1Tree a #)
-> Radix1Tree a
-> Radix1Tree a
-> Radix1Tree a
binAny S a a a a
s' (# Prefix, Radix1Tree a, Radix1Tree a #)
uB Radix1Tree a
tB Radix1Tree a
rA)
| Prefix
pA Prefix -> Prefix -> Bool
forall a. Ord a => a -> a -> Bool
>= Prefix -> Prefix
lower Prefix
pB -> Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
forall a. Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
Bin Prefix
pB (S a a a a
-> (# Prefix, Radix1Tree a, Radix1Tree a #)
-> Radix1Tree a
-> Radix1Tree a
-> Radix1Tree a
binAny S a a a a
s (# Prefix, Radix1Tree a, Radix1Tree a #)
uA Radix1Tree a
tA Radix1Tree a
lB) Radix1Tree a
rB
| Bool
otherwise -> Radix1Tree a
no
Ordering
GT | Prefix
pA Prefix -> Prefix -> Bool
forall a. Ord a => a -> a -> Bool
<= Prefix -> Prefix
upper Prefix
pB -> Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
forall a. Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
Bin Prefix
pB Radix1Tree a
lB (S a a a a
-> (# Prefix, Radix1Tree a, Radix1Tree a #)
-> Radix1Tree a
-> Radix1Tree a
-> Radix1Tree a
binAny S a a a a
s (# Prefix, Radix1Tree a, Radix1Tree a #)
uA Radix1Tree a
tA Radix1Tree a
rB)
| Prefix
pB Prefix -> Prefix -> Bool
forall a. Ord a => a -> a -> Bool
>= Prefix -> Prefix
lower Prefix
pA -> let !(# S a a a a
s' #) = S a a a a -> (# S a a a a #)
forall a b x y. S a b x y -> (# S b a x y #)
other S a a a a
s
in Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
forall a. Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
Bin Prefix
pA (S a a a a
-> (# Prefix, Radix1Tree a, Radix1Tree a #)
-> Radix1Tree a
-> Radix1Tree a
-> Radix1Tree a
binAny S a a a a
s' (# Prefix, Radix1Tree a, Radix1Tree a #)
uB Radix1Tree a
tB Radix1Tree a
lA) Radix1Tree a
rA
| Bool
otherwise -> Radix1Tree a
no
unionWithKey0 :: (Build -> a -> a -> a) -> RadixTree a -> RadixTree a -> RadixTree a
unionWithKey0 :: forall a.
(Build -> a -> a -> a) -> RadixTree a -> RadixTree a -> RadixTree a
unionWithKey0 Build -> a -> a -> a
f (RadixTree Maybe a
mA Radix1Tree a
tA) (RadixTree Maybe a
mB Radix1Tree a
tB) =
let mC :: Maybe a
mC = case Maybe a
mA of
Just a
a -> case Maybe a
mB of
Just a
b -> a -> Maybe a
forall a. a -> Maybe a
Just (a -> Maybe a) -> a -> Maybe a
forall a b. (a -> b) -> a -> b
$ Build -> a -> a -> a
f (Tsil ByteArray -> Build
Build Tsil ByteArray
forall a. Tsil a
Lin) a
a a
b
Maybe a
Nothing -> Maybe a
mA
Maybe a
Nothing -> Maybe a
mB
in Maybe a -> Radix1Tree a -> RadixTree a
forall a. Maybe a -> Radix1Tree a -> RadixTree a
RadixTree Maybe a
mC (Radix1Tree a -> RadixTree a) -> Radix1Tree a -> RadixTree a
forall a b. (a -> b) -> a -> b
$ (forall x y.
S x y a a -> Tsil ByteArray -> ByteArray -> x -> y -> Maybe a)
-> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
forall a.
(forall x y.
S x y a a -> Tsil ByteArray -> ByteArray -> x -> y -> Maybe a)
-> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
unionWithKey_
( \S x y a a
s Tsil ByteArray
b ByteArray
arr x
vA y
vB ->
let b0 :: Build
b0 = Tsil ByteArray -> Build
Build (Tsil ByteArray -> Build) -> Tsil ByteArray -> Build
forall a b. (a -> b) -> a -> b
$ Tsil ByteArray -> ByteArray -> Tsil ByteArray
forall a. Tsil a -> a -> Tsil a
Snoc Tsil ByteArray
b ByteArray
arr
!(# a
c #) = case S x y a a
s of
S x y a a
L -> (# Build -> a -> a -> a
f Build
b0 a
x
vA a
y
vB #)
S x y a a
R -> (# Build -> a -> a -> a
f Build
b0 a
y
vB a
x
vA #)
in a -> Maybe a
forall a. a -> Maybe a
Just a
c
)
Radix1Tree a
tA Radix1Tree a
tB
unionWithKey1 :: (Build1 -> a -> a -> a) -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
unionWithKey1 :: forall a.
(Build1 -> a -> a -> a)
-> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
unionWithKey1 Build1 -> a -> a -> a
f =
(forall x y.
S x y a a -> Tsil ByteArray -> ByteArray -> x -> y -> Maybe a)
-> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
forall a.
(forall x y.
S x y a a -> Tsil ByteArray -> ByteArray -> x -> y -> Maybe a)
-> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
unionWithKey_ ((forall x y.
S x y a a -> Tsil ByteArray -> ByteArray -> x -> y -> Maybe a)
-> Radix1Tree a -> Radix1Tree a -> Radix1Tree a)
-> (forall x y.
S x y a a -> Tsil ByteArray -> ByteArray -> x -> y -> Maybe a)
-> Radix1Tree a
-> Radix1Tree a
-> Radix1Tree a
forall a b. (a -> b) -> a -> b
$ \S x y a a
s Tsil ByteArray
b ByteArray
arr x
vA y
vB ->
let b1 :: Build1
b1 = YtpmeNon ByteArray -> Build1
Build1 (YtpmeNon ByteArray -> Build1) -> YtpmeNon ByteArray -> Build1
forall a b. (a -> b) -> a -> b
$ Tsil ByteArray
b Tsil ByteArray -> ByteArray -> YtpmeNon ByteArray
forall a. Tsil a -> a -> YtpmeNon a
:/ ByteArray
arr
!(# a
c #) = case S x y a a
s of
S x y a a
L -> (# Build1 -> a -> a -> a
f Build1
b1 a
x
vA a
y
vB #)
S x y a a
R -> (# Build1 -> a -> a -> a
f Build1
b1 a
y
vB a
x
vA #)
in a -> Maybe a
forall a. a -> Maybe a
Just a
c
{-# INLINE unionWithKey_ #-}
unionWithKey_
:: (forall x y. S x y a a -> Tsil ByteArray -> ByteArray -> x -> y -> Maybe a)
-> Radix1Tree a
-> Radix1Tree a
-> Radix1Tree a
unionWithKey_ :: forall a.
(forall x y.
S x y a a -> Tsil ByteArray -> ByteArray -> x -> y -> Maybe a)
-> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
unionWithKey_ forall x y.
S x y a a -> Tsil ByteArray -> ByteArray -> x -> y -> Maybe a
f = S a a a a
-> Tsil ByteArray -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
anyAny S a a a a
forall a b. S a b a b
L Tsil ByteArray
forall a. Tsil a
Lin
where
anyAny :: S a a a a
-> Tsil ByteArray -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
anyAny S a a a a
s Tsil ByteArray
b Radix1Tree a
tA Radix1Tree a
tB =
case Radix1Tree a
tA of
Bin Prefix
pA Radix1Tree a
lA Radix1Tree a
rA -> S a a a a
-> Tsil ByteArray
-> (# Prefix, Radix1Tree a, Radix1Tree a #)
-> Radix1Tree a
-> Radix1Tree a
-> Radix1Tree a
binAny S a a a a
s Tsil ByteArray
b (# Prefix
pA, Radix1Tree a
lA, Radix1Tree a
rA #) Radix1Tree a
tA Radix1Tree a
tB
Tip ByteArray
arrA Maybe a
mA Radix1Tree a
dA -> let !wA :: Prefix
wA = ByteArray -> Int -> Prefix
forall a. Prim a => ByteArray -> Int -> a
indexByteArray ByteArray
arrA Int
0
in S a a a a
-> Tsil ByteArray
-> (# Prefix, Int, ByteArray, Maybe a, Radix1Tree a #)
-> Radix1Tree a
-> Radix1Tree a
-> Radix1Tree a
tipAny S a a a a
s Tsil ByteArray
b (# Prefix
wA, Int
0, ByteArray
arrA, Maybe a
mA, Radix1Tree a
dA #) Radix1Tree a
tA Radix1Tree a
tB
Radix1Tree a
Nil -> Radix1Tree a
tB
tipAny :: S a a a a
-> Tsil ByteArray
-> (# Prefix, Int, ByteArray, Maybe a, Radix1Tree a #)
-> Radix1Tree a
-> Radix1Tree a
-> Radix1Tree a
tipAny S a a a a
s Tsil ByteArray
b uA :: (# Prefix, Int, ByteArray, Maybe a, Radix1Tree a #)
uA@(# Prefix
_, Int
nA, ByteArray
arrA, Maybe a
mA, Radix1Tree a
dA #) Radix1Tree a
tA Radix1Tree a
tB =
case Radix1Tree a
tB of
Bin Prefix
pB Radix1Tree a
lB Radix1Tree a
rB -> S a a a a
-> Tsil ByteArray
-> (# Prefix, Int, ByteArray, Maybe a, Radix1Tree a #)
-> Radix1Tree a
-> (# Prefix, Radix1Tree a, Radix1Tree a #)
-> Radix1Tree a
-> Radix1Tree a
tipBin S a a a a
s Tsil ByteArray
b (# Prefix, Int, ByteArray, Maybe a, Radix1Tree a #)
uA Radix1Tree a
tA (# Prefix
pB, Radix1Tree a
lB, Radix1Tree a
rB #) Radix1Tree a
tB
Tip ByteArray
arrB Maybe a
mB Radix1Tree a
dB -> let !wB :: Prefix
wB = ByteArray -> Int -> Prefix
forall a. Prim a => ByteArray -> Int -> a
indexByteArray ByteArray
arrB Int
0
uB :: (# Prefix, Int, ByteArray, Maybe a, Radix1Tree a #)
uB = (# Prefix
wB, Int
0, ByteArray
arrB, Maybe a
mB, Radix1Tree a
dB #)
!lenA :: Int
lenA = ByteArray -> Int
sizeofByteArray ByteArray
arrA Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
nA
!lenB :: Int
lenB = ByteArray -> Int
sizeofByteArray ByteArray
arrB
in if Int
lenB Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
lenA
then S a a a a
-> Tsil ByteArray
-> (# Prefix, Int, ByteArray, Maybe a, Radix1Tree a #)
-> Radix1Tree a
-> (# Prefix, Int, ByteArray, Maybe a, Radix1Tree a #)
-> Radix1Tree a
-> Int
-> Radix1Tree a
tipTip S a a a a
s Tsil ByteArray
b (# Prefix, Int, ByteArray, Maybe a, Radix1Tree a #)
uA Radix1Tree a
tA (# Prefix, Int, ByteArray, Maybe a, Radix1Tree a #)
uB Radix1Tree a
tB Int
lenA
else let !(# S a a a a
s' #) = S a a a a -> (# S a a a a #)
forall a b x y. S a b x y -> (# S b a x y #)
other S a a a a
s
in S a a a a
-> Tsil ByteArray
-> (# Prefix, Int, ByteArray, Maybe a, Radix1Tree a #)
-> Radix1Tree a
-> (# Prefix, Int, ByteArray, Maybe a, Radix1Tree a #)
-> Radix1Tree a
-> Int
-> Radix1Tree a
tipTip S a a a a
s' Tsil ByteArray
b (# Prefix, Int, ByteArray, Maybe a, Radix1Tree a #)
uB Radix1Tree a
tB (# Prefix, Int, ByteArray, Maybe a, Radix1Tree a #)
uA Radix1Tree a
tA Int
lenB
Radix1Tree a
Nil | Int
nA Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
0 -> Radix1Tree a
tA
| Bool
otherwise -> ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
Tip (Int -> ByteArray -> ByteArray
dropByteArray Int
nA ByteArray
arrA) Maybe a
mA Radix1Tree a
dA
tipTip :: S a a a a
-> Tsil ByteArray
-> (# Prefix, Int, ByteArray, Maybe a, Radix1Tree a #)
-> Radix1Tree a
-> (# Prefix, Int, ByteArray, Maybe a, Radix1Tree a #)
-> Radix1Tree a
-> Int
-> Radix1Tree a
tipTip S a a a a
s Tsil ByteArray
b (# Prefix
wA0, Int
nA, ByteArray
arrA, Maybe a
mA, Radix1Tree a
dA #) Radix1Tree a
tA (# Prefix
wB0, Int
nB, ByteArray
arrB, Maybe a
mB, Radix1Tree a
dB #) Radix1Tree a
tB Int
len =
Prefix -> Prefix -> Int -> Radix1Tree a
go Prefix
wA0 Prefix
wB0 Int
1
where
go :: Prefix -> Prefix -> Int -> Radix1Tree a
go Prefix
wA Prefix
wB !Int
o
| Prefix
wA Prefix -> Prefix -> Bool
forall a. Eq a => a -> a -> Bool
== Prefix
wB =
let !nB' :: Int
nB' = Int
nB Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
o
!wB' :: Prefix
wB' = ByteArray -> Int -> Prefix
forall a. Prim a => ByteArray -> Int -> a
indexByteArray ByteArray
arrB Int
nB'
in if Int
o Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
len
then let !arrA' :: ByteArray
arrA' | Int
nA Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
0 = ByteArray
arrA
| Bool
otherwise = Int -> ByteArray -> ByteArray
dropByteArray Int
nA ByteArray
arrA
in if Int
nB' Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== ByteArray -> Int
sizeofByteArray ByteArray
arrB
then let mC :: Maybe a
mC =
case Maybe a
mA of
Just a
xA ->
case Maybe a
mB of
Just a
xB -> S a a a a -> Tsil ByteArray -> ByteArray -> a -> a -> Maybe a
forall x y.
S x y a a -> Tsil ByteArray -> ByteArray -> x -> y -> Maybe a
f S a a a a
s Tsil ByteArray
b ByteArray
arrA' a
xA a
xB
Maybe a
Nothing -> Maybe a
mA
Maybe a
Nothing -> Maybe a
mB
in ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
Tip ByteArray
arrA' Maybe a
mC (S a a a a
-> Tsil ByteArray -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
anyAny S a a a a
s (Tsil ByteArray -> ByteArray -> Tsil ByteArray
forall a. Tsil a -> a -> Tsil a
Snoc Tsil ByteArray
b ByteArray
arrA') Radix1Tree a
dA Radix1Tree a
dB)
else ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
Tip ByteArray
arrA' Maybe a
mA (Radix1Tree a -> Radix1Tree a) -> Radix1Tree a -> Radix1Tree a
forall a b. (a -> b) -> a -> b
$
let !(# S a a a a
s' #) = S a a a a -> (# S a a a a #)
forall a b x y. S a b x y -> (# S b a x y #)
other S a a a a
s
in S a a a a
-> Tsil ByteArray
-> (# Prefix, Int, ByteArray, Maybe a, Radix1Tree a #)
-> Radix1Tree a
-> Radix1Tree a
-> Radix1Tree a
tipAny S a a a a
s' (Tsil ByteArray -> ByteArray -> Tsil ByteArray
forall a. Tsil a -> a -> Tsil a
Snoc Tsil ByteArray
b ByteArray
arrA')
(# Prefix
wB', Int
nB', ByteArray
arrB, Maybe a
mB, Radix1Tree a
dB #) Radix1Tree a
tB Radix1Tree a
dA
else let !nA' :: Int
nA' = Int
nA Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
o
!wA' :: Prefix
wA' = ByteArray -> Int -> Prefix
forall a. Prim a => ByteArray -> Int -> a
indexByteArray ByteArray
arrA Int
nA'
in Prefix -> Prefix -> Int -> Radix1Tree a
go Prefix
wA' Prefix
wB' (Int
o Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1)
| Int
o Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
1 =
let !tA' :: Radix1Tree a
tA' | Int
nA Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
0 = Radix1Tree a
tA
| Bool
otherwise = ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
Tip (Int -> ByteArray -> ByteArray
dropByteArray Int
nA ByteArray
arrA) Maybe a
mA Radix1Tree a
dA
!tB' :: Radix1Tree a
tB' | Int
nB Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
0 = Radix1Tree a
tB
| Bool
otherwise = ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
Tip (Int -> ByteArray -> ByteArray
dropByteArray Int
nB ByteArray
arrB) Maybe a
mB Radix1Tree a
dB
in Prefix -> Radix1Tree a -> Prefix -> Radix1Tree a -> Radix1Tree a
forall a.
Prefix -> Radix1Tree a -> Prefix -> Radix1Tree a -> Radix1Tree a
join Prefix
wA Radix1Tree a
tA' Prefix
wB Radix1Tree a
tB'
| Bool
otherwise =
let !o' :: Int
o' = Int
o Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1
!(# !ByteArray
arrC, !ByteArray
arrA' #) = Int -> Int -> ByteArray -> (# ByteArray, ByteArray #)
splitByteArray Int
nA Int
o' ByteArray
arrA
!arrB' :: ByteArray
arrB' = Int -> ByteArray -> ByteArray
dropByteArray (Int
nB Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
o') ByteArray
arrB
in ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
Tip ByteArray
arrC Maybe a
forall a. Maybe a
Nothing (Radix1Tree a -> Radix1Tree a) -> Radix1Tree a -> Radix1Tree a
forall a b. (a -> b) -> a -> b
$ Prefix -> Radix1Tree a -> Prefix -> Radix1Tree a -> Radix1Tree a
forall a.
Prefix -> Radix1Tree a -> Prefix -> Radix1Tree a -> Radix1Tree a
join Prefix
wA (ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
Tip ByteArray
arrA' Maybe a
mA Radix1Tree a
dA)
Prefix
wB (ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
Tip ByteArray
arrB' Maybe a
mB Radix1Tree a
dB)
binAny :: S a a a a
-> Tsil ByteArray
-> (# Prefix, Radix1Tree a, Radix1Tree a #)
-> Radix1Tree a
-> Radix1Tree a
-> Radix1Tree a
binAny S a a a a
s Tsil ByteArray
b (# Prefix, Radix1Tree a, Radix1Tree a #)
uA Radix1Tree a
tA Radix1Tree a
tB =
case Radix1Tree a
tB of
Bin Prefix
pB Radix1Tree a
lB Radix1Tree a
rB -> S a a a a
-> Tsil ByteArray
-> (# Prefix, Radix1Tree a, Radix1Tree a #)
-> Radix1Tree a
-> (# Prefix, Radix1Tree a, Radix1Tree a #)
-> Radix1Tree a
-> Radix1Tree a
binBin S a a a a
s Tsil ByteArray
b (# Prefix, Radix1Tree a, Radix1Tree a #)
uA Radix1Tree a
tA (# Prefix
pB, Radix1Tree a
lB, Radix1Tree a
rB #) Radix1Tree a
tB
Tip ByteArray
arrB Maybe a
mB Radix1Tree a
dB -> let !(# S a a a a
s' #) = S a a a a -> (# S a a a a #)
forall a b x y. S a b x y -> (# S b a x y #)
other S a a a a
s
!wB :: Prefix
wB = ByteArray -> Int -> Prefix
forall a. Prim a => ByteArray -> Int -> a
indexByteArray ByteArray
arrB Int
0
in S a a a a
-> Tsil ByteArray
-> (# Prefix, Int, ByteArray, Maybe a, Radix1Tree a #)
-> Radix1Tree a
-> (# Prefix, Radix1Tree a, Radix1Tree a #)
-> Radix1Tree a
-> Radix1Tree a
tipBin S a a a a
s' Tsil ByteArray
b (# Prefix
wB, Int
0, ByteArray
arrB, Maybe a
mB, Radix1Tree a
dB #) Radix1Tree a
tB (# Prefix, Radix1Tree a, Radix1Tree a #)
uA Radix1Tree a
tA
Radix1Tree a
Nil -> Radix1Tree a
tA
tipBin :: S a a a a
-> Tsil ByteArray
-> (# Prefix, Int, ByteArray, Maybe a, Radix1Tree a #)
-> Radix1Tree a
-> (# Prefix, Radix1Tree a, Radix1Tree a #)
-> Radix1Tree a
-> Radix1Tree a
tipBin S a a a a
s Tsil ByteArray
b uA :: (# Prefix, Int, ByteArray, Maybe a, Radix1Tree a #)
uA@(# Prefix
wA, Int
nA, ByteArray
arrA, Maybe a
mA, Radix1Tree a
dA #) Radix1Tree a
tA (# Prefix
pB, Radix1Tree a
lB, Radix1Tree a
rB #) Radix1Tree a
tB
| Prefix -> Prefix -> Bool
beyond Prefix
pB Prefix
wA = let !tA' :: Radix1Tree a
tA' | Int
nA Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
0 = Radix1Tree a
tA
| Bool
otherwise = ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
Tip (Int -> ByteArray -> ByteArray
dropByteArray Int
nA ByteArray
arrA) Maybe a
mA Radix1Tree a
dA
in Prefix -> Radix1Tree a -> Prefix -> Radix1Tree a -> Radix1Tree a
forall a.
Prefix -> Radix1Tree a -> Prefix -> Radix1Tree a -> Radix1Tree a
join Prefix
wA Radix1Tree a
tA' Prefix
pB Radix1Tree a
tB
| Prefix
wA Prefix -> Prefix -> Bool
forall a. Ord a => a -> a -> Bool
< Prefix
pB = Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
forall a. Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
Bin Prefix
pB (S a a a a
-> Tsil ByteArray
-> (# Prefix, Int, ByteArray, Maybe a, Radix1Tree a #)
-> Radix1Tree a
-> Radix1Tree a
-> Radix1Tree a
tipAny S a a a a
s Tsil ByteArray
b (# Prefix, Int, ByteArray, Maybe a, Radix1Tree a #)
uA Radix1Tree a
tA Radix1Tree a
lB) Radix1Tree a
rB
| Bool
otherwise = Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
forall a. Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
Bin Prefix
pB Radix1Tree a
lB (S a a a a
-> Tsil ByteArray
-> (# Prefix, Int, ByteArray, Maybe a, Radix1Tree a #)
-> Radix1Tree a
-> Radix1Tree a
-> Radix1Tree a
tipAny S a a a a
s Tsil ByteArray
b (# Prefix, Int, ByteArray, Maybe a, Radix1Tree a #)
uA Radix1Tree a
tA Radix1Tree a
rB)
binBin :: S a a a a
-> Tsil ByteArray
-> (# Prefix, Radix1Tree a, Radix1Tree a #)
-> Radix1Tree a
-> (# Prefix, Radix1Tree a, Radix1Tree a #)
-> Radix1Tree a
-> Radix1Tree a
binBin S a a a a
s Tsil ByteArray
b uA :: (# Prefix, Radix1Tree a, Radix1Tree a #)
uA@(# Prefix
pA, Radix1Tree a
lA, Radix1Tree a
rA #) Radix1Tree a
tA uB :: (# Prefix, Radix1Tree a, Radix1Tree a #)
uB@(# Prefix
pB, Radix1Tree a
lB, Radix1Tree a
rB #) Radix1Tree a
tB =
let {-# NOINLINE no #-}
no :: Radix1Tree a
no = Prefix -> Radix1Tree a -> Prefix -> Radix1Tree a -> Radix1Tree a
forall a.
Prefix -> Radix1Tree a -> Prefix -> Radix1Tree a -> Radix1Tree a
join Prefix
pA Radix1Tree a
tA Prefix
pB Radix1Tree a
tB
in case Prefix -> Prefix -> Ordering
forall a. Ord a => a -> a -> Ordering
Prelude.compare Prefix
pA Prefix
pB of
Ordering
EQ -> Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
forall a. Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
Bin Prefix
pA (S a a a a
-> Tsil ByteArray -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
anyAny S a a a a
s Tsil ByteArray
b Radix1Tree a
lA Radix1Tree a
lB) (S a a a a
-> Tsil ByteArray -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
anyAny S a a a a
s Tsil ByteArray
b Radix1Tree a
rA Radix1Tree a
rB)
Ordering
LT | Prefix
pB Prefix -> Prefix -> Bool
forall a. Ord a => a -> a -> Bool
<= Prefix -> Prefix
upper Prefix
pA -> let !(# S a a a a
s' #) = S a a a a -> (# S a a a a #)
forall a b x y. S a b x y -> (# S b a x y #)
other S a a a a
s
in Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
forall a. Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
Bin Prefix
pA Radix1Tree a
lA (S a a a a
-> Tsil ByteArray
-> (# Prefix, Radix1Tree a, Radix1Tree a #)
-> Radix1Tree a
-> Radix1Tree a
-> Radix1Tree a
binAny S a a a a
s' Tsil ByteArray
b (# Prefix, Radix1Tree a, Radix1Tree a #)
uB Radix1Tree a
tB Radix1Tree a
rA)
| Prefix
pA Prefix -> Prefix -> Bool
forall a. Ord a => a -> a -> Bool
>= Prefix -> Prefix
lower Prefix
pB -> Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
forall a. Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
Bin Prefix
pB (S a a a a
-> Tsil ByteArray
-> (# Prefix, Radix1Tree a, Radix1Tree a #)
-> Radix1Tree a
-> Radix1Tree a
-> Radix1Tree a
binAny S a a a a
s Tsil ByteArray
b (# Prefix, Radix1Tree a, Radix1Tree a #)
uA Radix1Tree a
tA Radix1Tree a
lB) Radix1Tree a
rB
| Bool
otherwise -> Radix1Tree a
no
Ordering
GT | Prefix
pA Prefix -> Prefix -> Bool
forall a. Ord a => a -> a -> Bool
<= Prefix -> Prefix
upper Prefix
pB -> Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
forall a. Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
Bin Prefix
pB Radix1Tree a
lB (S a a a a
-> Tsil ByteArray
-> (# Prefix, Radix1Tree a, Radix1Tree a #)
-> Radix1Tree a
-> Radix1Tree a
-> Radix1Tree a
binAny S a a a a
s Tsil ByteArray
b (# Prefix, Radix1Tree a, Radix1Tree a #)
uA Radix1Tree a
tA Radix1Tree a
rB)
| Prefix
pB Prefix -> Prefix -> Bool
forall a. Ord a => a -> a -> Bool
>= Prefix -> Prefix
lower Prefix
pA -> let !(# S a a a a
s' #) = S a a a a -> (# S a a a a #)
forall a b x y. S a b x y -> (# S b a x y #)
other S a a a a
s
in Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
forall a. Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
Bin Prefix
pA (S a a a a
-> Tsil ByteArray
-> (# Prefix, Radix1Tree a, Radix1Tree a #)
-> Radix1Tree a
-> Radix1Tree a
-> Radix1Tree a
binAny S a a a a
s' Tsil ByteArray
b (# Prefix, Radix1Tree a, Radix1Tree a #)
uB Radix1Tree a
tB Radix1Tree a
lA) Radix1Tree a
rA
| Bool
otherwise -> Radix1Tree a
no
difference0 :: RadixTree a -> RadixTree b -> RadixTree a
difference0 :: forall a b. RadixTree a -> RadixTree b -> RadixTree a
difference0 (RadixTree Maybe a
mA Radix1Tree a
tA) (RadixTree Maybe b
mB Radix1Tree b
tB) =
let mC :: Maybe a
mC = case Maybe b
mB of
Just b
_ -> Maybe a
forall a. Maybe a
Nothing
Maybe b
Nothing -> Maybe a
mA
in Maybe a -> Radix1Tree a -> RadixTree a
forall a. Maybe a -> Radix1Tree a -> RadixTree a
RadixTree Maybe a
mC (Radix1Tree a -> RadixTree a) -> Radix1Tree a -> RadixTree a
forall a b. (a -> b) -> a -> b
$ Radix1Tree a -> Radix1Tree b -> Radix1Tree a
forall a b. Radix1Tree a -> Radix1Tree b -> Radix1Tree a
difference1 Radix1Tree a
tA Radix1Tree b
tB
difference1 :: Radix1Tree a -> Radix1Tree b -> Radix1Tree a
difference1 :: forall a b. Radix1Tree a -> Radix1Tree b -> Radix1Tree a
difference1 =
(forall x y. S x y a b -> x -> y -> Maybe a)
-> Radix1Tree a -> Radix1Tree b -> Radix1Tree a
forall a b.
(forall x y. S x y a b -> x -> y -> Maybe a)
-> Radix1Tree a -> Radix1Tree b -> Radix1Tree a
difference_ ((forall x y. S x y a b -> x -> y -> Maybe a)
-> Radix1Tree a -> Radix1Tree b -> Radix1Tree a)
-> (forall x y. S x y a b -> x -> y -> Maybe a)
-> Radix1Tree a
-> Radix1Tree b
-> Radix1Tree a
forall a b. (a -> b) -> a -> b
$ \S x y a b
_ x
_ y
_ ->
Maybe a
forall a. Maybe a
Nothing
differenceWith0
:: (a -> b -> Maybe a) -> RadixTree a -> RadixTree b -> RadixTree a
differenceWith0 :: forall a b.
(a -> b -> Maybe a) -> RadixTree a -> RadixTree b -> RadixTree a
differenceWith0 a -> b -> Maybe a
f (RadixTree Maybe a
mA Radix1Tree a
tA) (RadixTree Maybe b
mB Radix1Tree b
tB) =
let mC :: Maybe a
mC | Just a
xA <- Maybe a
mA, Just b
xB <- Maybe b
mB = a -> b -> Maybe a
f a
xA b
xB
| Bool
otherwise = Maybe a
mA
in Maybe a -> Radix1Tree a -> RadixTree a
forall a. Maybe a -> Radix1Tree a -> RadixTree a
RadixTree Maybe a
mC (Radix1Tree a -> RadixTree a) -> Radix1Tree a -> RadixTree a
forall a b. (a -> b) -> a -> b
$ (a -> b -> Maybe a) -> Radix1Tree a -> Radix1Tree b -> Radix1Tree a
forall a b.
(a -> b -> Maybe a) -> Radix1Tree a -> Radix1Tree b -> Radix1Tree a
differenceWith1 a -> b -> Maybe a
f Radix1Tree a
tA Radix1Tree b
tB
differenceWith1
:: (a -> b -> Maybe a) -> Radix1Tree a -> Radix1Tree b -> Radix1Tree a
differenceWith1 :: forall a b.
(a -> b -> Maybe a) -> Radix1Tree a -> Radix1Tree b -> Radix1Tree a
differenceWith1 a -> b -> Maybe a
f =
(forall x y. S x y a b -> x -> y -> Maybe a)
-> Radix1Tree a -> Radix1Tree b -> Radix1Tree a
forall a b.
(forall x y. S x y a b -> x -> y -> Maybe a)
-> Radix1Tree a -> Radix1Tree b -> Radix1Tree a
difference_ ((forall x y. S x y a b -> x -> y -> Maybe a)
-> Radix1Tree a -> Radix1Tree b -> Radix1Tree a)
-> (forall x y. S x y a b -> x -> y -> Maybe a)
-> Radix1Tree a
-> Radix1Tree b
-> Radix1Tree a
forall a b. (a -> b) -> a -> b
$ \S x y a b
s x
xA y
xB ->
case S x y a b
s of
S x y a b
L -> a -> b -> Maybe a
f a
x
xA b
y
xB
S x y a b
R -> a -> b -> Maybe a
f a
y
xB b
x
xA
{-# INLINE difference_ #-}
difference_
:: (forall x y. S x y a b -> x -> y -> Maybe a)
-> Radix1Tree a
-> Radix1Tree b
-> Radix1Tree a
difference_ :: forall a b.
(forall x y. S x y a b -> x -> y -> Maybe a)
-> Radix1Tree a -> Radix1Tree b -> Radix1Tree a
difference_ (forall x y. S x y a b -> x -> y -> Maybe a
f :: forall n o. S n o x y -> n -> o -> Maybe x) = S a b a b -> Radix1Tree a -> Radix1Tree b -> Radix1Tree a
forall a b.
S a b a b -> Radix1Tree a -> Radix1Tree b -> Radix1Tree a
anyAny S a b a b
forall a b. S a b a b
L
where
anyAny :: forall a b. S a b x y -> Radix1Tree a -> Radix1Tree b -> Radix1Tree x
anyAny :: forall a b.
S a b a b -> Radix1Tree a -> Radix1Tree b -> Radix1Tree a
anyAny S a b a b
s Radix1Tree a
tA Radix1Tree b
tB =
case Radix1Tree a
tA of
Bin Prefix
pA Radix1Tree a
lA Radix1Tree a
rA -> S a b a b -> UBin a -> Radix1Tree a -> Radix1Tree b -> Radix1Tree a
forall a b.
S a b a b -> UBin a -> Radix1Tree a -> Radix1Tree b -> Radix1Tree a
binAny S a b a b
s (# Prefix
pA, Radix1Tree a
lA, Radix1Tree a
rA #) Radix1Tree a
tA Radix1Tree b
tB
Tip ByteArray
arrA Maybe a
mA Radix1Tree a
dA -> let !wA :: Prefix
wA = ByteArray -> Int -> Prefix
forall a. Prim a => ByteArray -> Int -> a
indexByteArray ByteArray
arrA Int
0
in S a b a b -> UTip a -> Radix1Tree a -> Radix1Tree b -> Radix1Tree a
forall a b.
S a b a b -> UTip a -> Radix1Tree a -> Radix1Tree b -> Radix1Tree a
tipAny S a b a b
s (# Prefix
wA, Int
0, ByteArray
arrA, Maybe a
mA, Radix1Tree a
dA #) Radix1Tree a
tA Radix1Tree b
tB
Radix1Tree a
Nil -> case S a b a b
s of
S a b a b
L -> Radix1Tree a
forall a. Radix1Tree a
Nil
S a b a b
R -> Radix1Tree a
Radix1Tree b
tB
tipAny
:: forall a b. S a b x y -> UTip a -> Radix1Tree a -> Radix1Tree b -> Radix1Tree x
tipAny :: forall a b.
S a b a b -> UTip a -> Radix1Tree a -> Radix1Tree b -> Radix1Tree a
tipAny S a b a b
s uA :: UTip a
uA@(# Prefix
_, Int
nA, ByteArray
arrA, Maybe a
mA, Radix1Tree a
dA #) Radix1Tree a
tA Radix1Tree b
tB =
case Radix1Tree b
tB of
Bin Prefix
pB Radix1Tree b
lB Radix1Tree b
rB -> S a b a b
-> UTip a -> Radix1Tree a -> UBin b -> Radix1Tree b -> Radix1Tree a
forall a b.
S a b a b
-> UTip a -> Radix1Tree a -> UBin b -> Radix1Tree b -> Radix1Tree a
tipBin S a b a b
s UTip a
uA Radix1Tree a
tA (# Prefix
pB, Radix1Tree b
lB, Radix1Tree b
rB #) Radix1Tree b
tB
Tip ByteArray
arrB Maybe b
mB Radix1Tree b
dB -> let !wB :: Prefix
wB = ByteArray -> Int -> Prefix
forall a. Prim a => ByteArray -> Int -> a
indexByteArray ByteArray
arrB Int
0
uB :: (# Prefix, Int, ByteArray, Maybe b, Radix1Tree b #)
uB = (# Prefix
wB, Int
0, ByteArray
arrB, Maybe b
mB, Radix1Tree b
dB #)
!lenA :: Int
lenA = ByteArray -> Int
sizeofByteArray ByteArray
arrA Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
nA
!lenB :: Int
lenB = ByteArray -> Int
sizeofByteArray ByteArray
arrB
in if Int
lenB Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
lenA
then S a b a b
-> UTip a
-> Radix1Tree a
-> (# Prefix, Int, ByteArray, Maybe b, Radix1Tree b #)
-> Radix1Tree b
-> Int
-> Radix1Tree a
forall a b.
S a b a b
-> UTip a
-> Radix1Tree a
-> UTip b
-> Radix1Tree b
-> Int
-> Radix1Tree a
tipTip S a b a b
s UTip a
uA Radix1Tree a
tA (# Prefix, Int, ByteArray, Maybe b, Radix1Tree b #)
uB Radix1Tree b
tB Int
lenA
else let !(# S b a a b
s' #) = S a b a b -> (# S b a a b #)
forall a b x y. S a b x y -> (# S b a x y #)
other S a b a b
s
in S b a a b
-> (# Prefix, Int, ByteArray, Maybe b, Radix1Tree b #)
-> Radix1Tree b
-> UTip a
-> Radix1Tree a
-> Int
-> Radix1Tree a
forall a b.
S a b a b
-> UTip a
-> Radix1Tree a
-> UTip b
-> Radix1Tree b
-> Int
-> Radix1Tree a
tipTip S b a a b
s' (# Prefix, Int, ByteArray, Maybe b, Radix1Tree b #)
uB Radix1Tree b
tB UTip a
uA Radix1Tree a
tA Int
lenB
Radix1Tree b
Nil -> case S a b a b
s of
S a b a b
L | Int
nA Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
0 -> Radix1Tree a
Radix1Tree a
tA
| Bool
otherwise -> ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
Tip (Int -> ByteArray -> ByteArray
dropByteArray Int
nA ByteArray
arrA) Maybe a
Maybe a
mA Radix1Tree a
Radix1Tree a
dA
S a b a b
R -> Radix1Tree a
forall a. Radix1Tree a
Nil
tipTip
:: forall a b. S a b x y
-> UTip a -> Radix1Tree a -> UTip b -> Radix1Tree b -> Int -> Radix1Tree x
tipTip :: forall a b.
S a b a b
-> UTip a
-> Radix1Tree a
-> UTip b
-> Radix1Tree b
-> Int
-> Radix1Tree a
tipTip S a b a b
s (# Prefix
wA0, Int
nA, ByteArray
arrA, Maybe a
mA, Radix1Tree a
dA #) Radix1Tree a
tA (# Prefix
wB0, Int
nB, ByteArray
arrB, Maybe b
mB, Radix1Tree b
dB #) Radix1Tree b
tB Int
len =
Prefix -> Prefix -> Int -> Radix1Tree a
go Prefix
wA0 Prefix
wB0 Int
1
where
go :: Prefix -> Prefix -> Int -> Radix1Tree a
go Prefix
wA Prefix
wB !Int
o
| Prefix
wA Prefix -> Prefix -> Bool
forall a. Eq a => a -> a -> Bool
== Prefix
wB =
let !nB' :: Int
nB' = Int
nB Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
o
!wB' :: Prefix
wB' = ByteArray -> Int -> Prefix
forall a. Prim a => ByteArray -> Int -> a
indexByteArray ByteArray
arrB Int
nB'
in if Int
o Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
len
then let !arrA' :: ByteArray
arrA' | Int
nA Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
0 = ByteArray
arrA
| Bool
otherwise = Int -> ByteArray -> ByteArray
dropByteArray Int
nA ByteArray
arrA
in if Int
nB' Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== ByteArray -> Int
sizeofByteArray ByteArray
arrB
then let mC :: Maybe a
mC | Just a
xA <- Maybe a
mA, Just b
xB <- Maybe b
mB = S a b a b -> a -> b -> Maybe a
forall x y. S x y a b -> x -> y -> Maybe a
f S a b a b
s a
xA b
xB
| Bool
otherwise =
case S a b a b
s of
S a b a b
L -> Maybe a
Maybe a
mA
S a b a b
R -> Maybe a
Maybe b
mB
in ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
retip ByteArray
arrA' Maybe a
mC (S a b a b -> Radix1Tree a -> Radix1Tree b -> Radix1Tree a
forall a b.
S a b a b -> Radix1Tree a -> Radix1Tree b -> Radix1Tree a
anyAny S a b a b
s Radix1Tree a
dA Radix1Tree b
dB)
else let mA' :: Maybe a
mA' = case S a b a b
s of
S a b a b
L -> Maybe a
Maybe a
mA
S a b a b
R -> Maybe a
forall a. Maybe a
Nothing
in ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
retip ByteArray
arrA' Maybe a
mA' (Radix1Tree a -> Radix1Tree a) -> Radix1Tree a -> Radix1Tree a
forall a b. (a -> b) -> a -> b
$
let !(# S b a a b
s' #) = S a b a b -> (# S b a a b #)
forall a b x y. S a b x y -> (# S b a x y #)
other S a b a b
s
in S b a a b
-> (# Prefix, Int, ByteArray, Maybe b, Radix1Tree b #)
-> Radix1Tree b
-> Radix1Tree a
-> Radix1Tree a
forall a b.
S a b a b -> UTip a -> Radix1Tree a -> Radix1Tree b -> Radix1Tree a
tipAny S b a a b
s' (# Prefix
wB', Int
nB', ByteArray
arrB, Maybe b
mB, Radix1Tree b
dB #) Radix1Tree b
tB Radix1Tree a
dA
else let !nA' :: Int
nA' = Int
nA Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
o
!wA' :: Prefix
wA' = ByteArray -> Int -> Prefix
forall a. Prim a => ByteArray -> Int -> a
indexByteArray ByteArray
arrA Int
nA'
in Prefix -> Prefix -> Int -> Radix1Tree a
go Prefix
wA' Prefix
wB' (Int
o Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1)
| Bool
otherwise =
case S a b a b
s of
S a b a b
L | Int
nA Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
0 -> Radix1Tree a
Radix1Tree a
tA
| Bool
otherwise -> ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
Tip (Int -> ByteArray -> ByteArray
dropByteArray Int
nA ByteArray
arrA) Maybe a
Maybe a
mA Radix1Tree a
Radix1Tree a
dA
S a b a b
R | Int
nB Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
0 -> Radix1Tree a
Radix1Tree b
tB
| Bool
otherwise -> ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
Tip (Int -> ByteArray -> ByteArray
dropByteArray Int
nB ByteArray
arrB) Maybe a
Maybe b
mB Radix1Tree a
Radix1Tree b
dB
binAny
:: forall a b. S a b x y -> UBin a -> Radix1Tree a -> Radix1Tree b -> Radix1Tree x
binAny :: forall a b.
S a b a b -> UBin a -> Radix1Tree a -> Radix1Tree b -> Radix1Tree a
binAny S a b a b
s UBin a
uA Radix1Tree a
tA Radix1Tree b
tB =
case Radix1Tree b
tB of
Bin Prefix
pB Radix1Tree b
lB Radix1Tree b
rB -> S a b a b
-> UBin a -> Radix1Tree a -> UBin b -> Radix1Tree b -> Radix1Tree a
forall a b.
S a b a b
-> UBin a -> Radix1Tree a -> UBin b -> Radix1Tree b -> Radix1Tree a
binBin S a b a b
s UBin a
uA Radix1Tree a
tA (# Prefix
pB, Radix1Tree b
lB, Radix1Tree b
rB #) Radix1Tree b
tB
Tip ByteArray
arrB Maybe b
mB Radix1Tree b
dB -> let !(# S b a a b
s' #) = S a b a b -> (# S b a a b #)
forall a b x y. S a b x y -> (# S b a x y #)
other S a b a b
s
!wB :: Prefix
wB = ByteArray -> Int -> Prefix
forall a. Prim a => ByteArray -> Int -> a
indexByteArray ByteArray
arrB Int
0
in S b a a b
-> UTip b -> Radix1Tree b -> UBin a -> Radix1Tree a -> Radix1Tree a
forall a b.
S a b a b
-> UTip a -> Radix1Tree a -> UBin b -> Radix1Tree b -> Radix1Tree a
tipBin S b a a b
s' (# Prefix
wB, Int
0, ByteArray
arrB, Maybe b
mB, Radix1Tree b
dB #) Radix1Tree b
tB UBin a
uA Radix1Tree a
tA
Radix1Tree b
Nil -> case S a b a b
s of
S a b a b
L -> Radix1Tree a
Radix1Tree a
tA
S a b a b
R -> Radix1Tree a
Radix1Tree b
tB
tipBin
:: forall a b. S a b x y
-> UTip a -> Radix1Tree a -> UBin b -> Radix1Tree b -> Radix1Tree x
tipBin :: forall a b.
S a b a b
-> UTip a -> Radix1Tree a -> UBin b -> Radix1Tree b -> Radix1Tree a
tipBin S a b a b
s uA :: UTip a
uA@(# Prefix
wA, Int
nA, ByteArray
arrA, Maybe a
mA, Radix1Tree a
dA #) Radix1Tree a
tA (# Prefix
pB, Radix1Tree b
lB, Radix1Tree b
rB #) Radix1Tree b
tB
| Prefix -> Prefix -> Bool
beyond Prefix
pB Prefix
wA = case S a b a b
s of
S a b a b
L | Int
nA Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
0 -> Radix1Tree a
Radix1Tree a
tA
| Bool
otherwise -> ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
Tip (Int -> ByteArray -> ByteArray
dropByteArray Int
nA ByteArray
arrA) Maybe a
Maybe a
mA Radix1Tree a
Radix1Tree a
dA
S a b a b
R -> Radix1Tree a
Radix1Tree b
tB
| Prefix
wA Prefix -> Prefix -> Bool
forall a. Ord a => a -> a -> Bool
< Prefix
pB = case S a b a b
s of
S a b a b
L -> S a b a b -> UTip a -> Radix1Tree a -> Radix1Tree b -> Radix1Tree a
forall a b.
S a b a b -> UTip a -> Radix1Tree a -> Radix1Tree b -> Radix1Tree a
tipAny S a b a b
s UTip a
uA Radix1Tree a
tA Radix1Tree b
lB
S a b a b
R -> Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
forall a. Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
rebinL Prefix
pB (S a b a b -> UTip a -> Radix1Tree a -> Radix1Tree b -> Radix1Tree a
forall a b.
S a b a b -> UTip a -> Radix1Tree a -> Radix1Tree b -> Radix1Tree a
tipAny S a b a b
s UTip a
uA Radix1Tree a
tA Radix1Tree b
lB) Radix1Tree a
Radix1Tree b
rB
| Bool
otherwise = case S a b a b
s of
S a b a b
L -> S a b a b -> UTip a -> Radix1Tree a -> Radix1Tree b -> Radix1Tree a
forall a b.
S a b a b -> UTip a -> Radix1Tree a -> Radix1Tree b -> Radix1Tree a
tipAny S a b a b
s UTip a
uA Radix1Tree a
tA Radix1Tree b
rB
S a b a b
R -> Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
forall a. Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
rebinR Prefix
pB Radix1Tree a
Radix1Tree b
lB (S a b a b -> UTip a -> Radix1Tree a -> Radix1Tree b -> Radix1Tree a
forall a b.
S a b a b -> UTip a -> Radix1Tree a -> Radix1Tree b -> Radix1Tree a
tipAny S a b a b
s UTip a
uA Radix1Tree a
tA Radix1Tree b
rB)
binBin
:: forall a b. S a b x y
-> UBin a -> Radix1Tree a -> UBin b -> Radix1Tree b -> Radix1Tree x
binBin :: forall a b.
S a b a b
-> UBin a -> Radix1Tree a -> UBin b -> Radix1Tree b -> Radix1Tree a
binBin S a b a b
s uA :: UBin a
uA@(# Prefix
pA, Radix1Tree a
lA, Radix1Tree a
rA #) Radix1Tree a
tA uB :: UBin b
uB@(# Prefix
pB, Radix1Tree b
lB, Radix1Tree b
rB #) Radix1Tree b
tB =
let no :: Radix1Tree a
no = case S a b a b
s of
S a b a b
L -> Radix1Tree a
Radix1Tree a
tA
S a b a b
R -> Radix1Tree a
Radix1Tree b
tB
in case Prefix -> Prefix -> Ordering
forall a. Ord a => a -> a -> Ordering
Prelude.compare Prefix
pA Prefix
pB of
Ordering
EQ -> Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
forall a. Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
rebin Prefix
pA (S a b a b -> Radix1Tree a -> Radix1Tree b -> Radix1Tree a
forall a b.
S a b a b -> Radix1Tree a -> Radix1Tree b -> Radix1Tree a
anyAny S a b a b
s Radix1Tree a
lA Radix1Tree b
lB) (S a b a b -> Radix1Tree a -> Radix1Tree b -> Radix1Tree a
forall a b.
S a b a b -> Radix1Tree a -> Radix1Tree b -> Radix1Tree a
anyAny S a b a b
s Radix1Tree a
rA Radix1Tree b
rB)
Ordering
LT | Prefix
pB Prefix -> Prefix -> Bool
forall a. Ord a => a -> a -> Bool
<= Prefix -> Prefix
upper Prefix
pA -> case S a b a b
s of
S a b a b
L -> Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
forall a. Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
rebinR Prefix
pA Radix1Tree a
Radix1Tree a
lA (S b a a b -> UBin b -> Radix1Tree b -> Radix1Tree a -> Radix1Tree a
forall a b.
S a b a b -> UBin a -> Radix1Tree a -> Radix1Tree b -> Radix1Tree a
binAny S b a a b
forall a b. S a b b a
R UBin b
UBin b
uB Radix1Tree b
Radix1Tree b
tB Radix1Tree a
Radix1Tree a
rA)
S a b a b
R -> S a b a b -> UBin a -> Radix1Tree a -> Radix1Tree b -> Radix1Tree a
forall a b.
S a b a b -> UBin a -> Radix1Tree a -> Radix1Tree b -> Radix1Tree a
binAny S a b a b
forall a b. S a b a b
L UBin a
UBin b
uB Radix1Tree a
Radix1Tree b
tB Radix1Tree b
Radix1Tree a
rA
| Prefix
pA Prefix -> Prefix -> Bool
forall a. Ord a => a -> a -> Bool
>= Prefix -> Prefix
lower Prefix
pB -> case S a b a b
s of
S a b a b
L -> S a b a b -> UBin a -> Radix1Tree a -> Radix1Tree b -> Radix1Tree a
forall a b.
S a b a b -> UBin a -> Radix1Tree a -> Radix1Tree b -> Radix1Tree a
binAny S a b a b
s UBin a
uA Radix1Tree a
tA Radix1Tree b
lB
S a b a b
R -> Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
forall a. Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
rebinL Prefix
pB (S a b a b -> UBin a -> Radix1Tree a -> Radix1Tree b -> Radix1Tree a
forall a b.
S a b a b -> UBin a -> Radix1Tree a -> Radix1Tree b -> Radix1Tree a
binAny S a b a b
s UBin a
uA Radix1Tree a
tA Radix1Tree b
lB) Radix1Tree a
Radix1Tree b
rB
| Bool
otherwise -> Radix1Tree a
no
Ordering
GT | Prefix
pA Prefix -> Prefix -> Bool
forall a. Ord a => a -> a -> Bool
<= Prefix -> Prefix
upper Prefix
pB -> case S a b a b
s of
S a b a b
L -> S a b a b -> UBin a -> Radix1Tree a -> Radix1Tree b -> Radix1Tree a
forall a b.
S a b a b -> UBin a -> Radix1Tree a -> Radix1Tree b -> Radix1Tree a
binAny S a b a b
s UBin a
uA Radix1Tree a
tA Radix1Tree b
rB
S a b a b
R -> Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
forall a. Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
rebinR Prefix
pB Radix1Tree a
Radix1Tree b
lB (S a b a b -> UBin a -> Radix1Tree a -> Radix1Tree b -> Radix1Tree a
forall a b.
S a b a b -> UBin a -> Radix1Tree a -> Radix1Tree b -> Radix1Tree a
binAny S a b a b
s UBin a
uA Radix1Tree a
tA Radix1Tree b
rB)
| Prefix
pB Prefix -> Prefix -> Bool
forall a. Ord a => a -> a -> Bool
>= Prefix -> Prefix
lower Prefix
pA -> case S a b a b
s of
S a b a b
L -> Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
forall a. Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
rebinL Prefix
pA (S b a a b -> UBin b -> Radix1Tree b -> Radix1Tree a -> Radix1Tree a
forall a b.
S a b a b -> UBin a -> Radix1Tree a -> Radix1Tree b -> Radix1Tree a
binAny S b a a b
forall a b. S a b b a
R UBin b
UBin b
uB Radix1Tree b
Radix1Tree b
tB Radix1Tree a
Radix1Tree a
lA) Radix1Tree a
Radix1Tree a
rA
S a b a b
R -> S a b a b -> UBin a -> Radix1Tree a -> Radix1Tree b -> Radix1Tree a
forall a b.
S a b a b -> UBin a -> Radix1Tree a -> Radix1Tree b -> Radix1Tree a
binAny S a b a b
forall a b. S a b a b
L UBin a
UBin b
uB Radix1Tree a
Radix1Tree b
tB Radix1Tree b
Radix1Tree a
lA
| Bool
otherwise -> Radix1Tree a
no
differenceWithKey0
:: (Build -> a -> b -> Maybe a) -> RadixTree a -> RadixTree b -> RadixTree a
differenceWithKey0 :: forall a b.
(Build -> a -> b -> Maybe a)
-> RadixTree a -> RadixTree b -> RadixTree a
differenceWithKey0 Build -> a -> b -> Maybe a
f (RadixTree Maybe a
mA Radix1Tree a
tA) (RadixTree Maybe b
mB Radix1Tree b
tB) =
let mC :: Maybe a
mC | Just a
xA <- Maybe a
mA, Just b
xB <- Maybe b
mB = Build -> a -> b -> Maybe a
f (Tsil ByteArray -> Build
Build Tsil ByteArray
forall a. Tsil a
Lin) a
xA b
xB
| Bool
otherwise = Maybe a
mA
in Maybe a -> Radix1Tree a -> RadixTree a
forall a. Maybe a -> Radix1Tree a -> RadixTree a
RadixTree Maybe a
mC (Radix1Tree a -> RadixTree a) -> Radix1Tree a -> RadixTree a
forall a b. (a -> b) -> a -> b
$ (forall x y.
S x y a b -> Tsil ByteArray -> ByteArray -> x -> y -> Maybe a)
-> Radix1Tree a -> Radix1Tree b -> Radix1Tree a
forall a b.
(forall x y.
S x y a b -> Tsil ByteArray -> ByteArray -> x -> y -> Maybe a)
-> Radix1Tree a -> Radix1Tree b -> Radix1Tree a
differenceWithKey_
( \S x y a b
s Tsil ByteArray
b ByteArray
arr x
xA y
xB ->
let b0 :: Build
b0 = Tsil ByteArray -> Build
Build (Tsil ByteArray -> Build) -> Tsil ByteArray -> Build
forall a b. (a -> b) -> a -> b
$ Tsil ByteArray -> ByteArray -> Tsil ByteArray
forall a. Tsil a -> a -> Tsil a
Snoc Tsil ByteArray
b ByteArray
arr
in case S x y a b
s of
S x y a b
L -> Build -> a -> b -> Maybe a
f Build
b0 a
x
xA b
y
xB
S x y a b
R -> Build -> a -> b -> Maybe a
f Build
b0 a
y
xB b
x
xA
)
Radix1Tree a
tA Radix1Tree b
tB
differenceWithKey1
:: (Build1 -> a -> b -> Maybe a) -> Radix1Tree a -> Radix1Tree b -> Radix1Tree a
differenceWithKey1 :: forall a b.
(Build1 -> a -> b -> Maybe a)
-> Radix1Tree a -> Radix1Tree b -> Radix1Tree a
differenceWithKey1 Build1 -> a -> b -> Maybe a
f =
(forall x y.
S x y a b -> Tsil ByteArray -> ByteArray -> x -> y -> Maybe a)
-> Radix1Tree a -> Radix1Tree b -> Radix1Tree a
forall a b.
(forall x y.
S x y a b -> Tsil ByteArray -> ByteArray -> x -> y -> Maybe a)
-> Radix1Tree a -> Radix1Tree b -> Radix1Tree a
differenceWithKey_ ((forall x y.
S x y a b -> Tsil ByteArray -> ByteArray -> x -> y -> Maybe a)
-> Radix1Tree a -> Radix1Tree b -> Radix1Tree a)
-> (forall x y.
S x y a b -> Tsil ByteArray -> ByteArray -> x -> y -> Maybe a)
-> Radix1Tree a
-> Radix1Tree b
-> Radix1Tree a
forall a b. (a -> b) -> a -> b
$ \S x y a b
s Tsil ByteArray
b ByteArray
arr x
xA y
xB ->
let b1 :: Build1
b1 = YtpmeNon ByteArray -> Build1
Build1 (YtpmeNon ByteArray -> Build1) -> YtpmeNon ByteArray -> Build1
forall a b. (a -> b) -> a -> b
$ Tsil ByteArray
b Tsil ByteArray -> ByteArray -> YtpmeNon ByteArray
forall a. Tsil a -> a -> YtpmeNon a
:/ ByteArray
arr
in case S x y a b
s of
S x y a b
L -> Build1 -> a -> b -> Maybe a
f Build1
b1 a
x
xA b
y
xB
S x y a b
R -> Build1 -> a -> b -> Maybe a
f Build1
b1 a
y
xB b
x
xA
{-# INLINE differenceWithKey_ #-}
differenceWithKey_
:: (forall x y. S x y a b -> Tsil ByteArray -> ByteArray -> x -> y -> Maybe a)
-> Radix1Tree a
-> Radix1Tree b
-> Radix1Tree a
differenceWithKey_ :: forall a b.
(forall x y.
S x y a b -> Tsil ByteArray -> ByteArray -> x -> y -> Maybe a)
-> Radix1Tree a -> Radix1Tree b -> Radix1Tree a
differenceWithKey_
(forall x y.
S x y a b -> Tsil ByteArray -> ByteArray -> x -> y -> Maybe a
f :: forall n o. S n o x y -> Tsil ByteArray -> ByteArray -> n -> o -> Maybe x) =
S a b a b
-> Tsil ByteArray -> Radix1Tree a -> Radix1Tree b -> Radix1Tree a
forall a b.
S a b a b
-> Tsil ByteArray -> Radix1Tree a -> Radix1Tree b -> Radix1Tree a
anyAny S a b a b
forall a b. S a b a b
L Tsil ByteArray
forall a. Tsil a
Lin
where
anyAny
:: forall a b. S a b x y -> Tsil ByteArray
-> Radix1Tree a -> Radix1Tree b -> Radix1Tree x
anyAny :: forall a b.
S a b a b
-> Tsil ByteArray -> Radix1Tree a -> Radix1Tree b -> Radix1Tree a
anyAny S a b a b
s Tsil ByteArray
b Radix1Tree a
tA Radix1Tree b
tB =
case Radix1Tree a
tA of
Bin Prefix
pA Radix1Tree a
lA Radix1Tree a
rA -> S a b a b
-> Tsil ByteArray
-> UBin a
-> Radix1Tree a
-> Radix1Tree b
-> Radix1Tree a
forall a b.
S a b a b
-> Tsil ByteArray
-> UBin a
-> Radix1Tree a
-> Radix1Tree b
-> Radix1Tree a
binAny S a b a b
s Tsil ByteArray
b (# Prefix
pA, Radix1Tree a
lA, Radix1Tree a
rA #) Radix1Tree a
tA Radix1Tree b
tB
Tip ByteArray
arrA Maybe a
mA Radix1Tree a
dA -> let !wA :: Prefix
wA = ByteArray -> Int -> Prefix
forall a. Prim a => ByteArray -> Int -> a
indexByteArray ByteArray
arrA Int
0
in S a b a b
-> Tsil ByteArray
-> UTip a
-> Radix1Tree a
-> Radix1Tree b
-> Radix1Tree a
forall a b.
S a b a b
-> Tsil ByteArray
-> UTip a
-> Radix1Tree a
-> Radix1Tree b
-> Radix1Tree a
tipAny S a b a b
s Tsil ByteArray
b (# Prefix
wA, Int
0, ByteArray
arrA, Maybe a
mA, Radix1Tree a
dA #) Radix1Tree a
tA Radix1Tree b
tB
Radix1Tree a
Nil -> case S a b a b
s of
S a b a b
L -> Radix1Tree a
forall a. Radix1Tree a
Nil
S a b a b
R -> Radix1Tree a
Radix1Tree b
tB
tipAny
:: forall a b. S a b x y -> Tsil ByteArray
-> UTip a -> Radix1Tree a -> Radix1Tree b -> Radix1Tree x
tipAny :: forall a b.
S a b a b
-> Tsil ByteArray
-> UTip a
-> Radix1Tree a
-> Radix1Tree b
-> Radix1Tree a
tipAny S a b a b
s Tsil ByteArray
b uA :: UTip a
uA@(# Prefix
_, Int
nA, ByteArray
arrA, Maybe a
mA, Radix1Tree a
dA #) Radix1Tree a
tA Radix1Tree b
tB =
case Radix1Tree b
tB of
Bin Prefix
pB Radix1Tree b
lB Radix1Tree b
rB -> S a b a b
-> Tsil ByteArray
-> UTip a
-> Radix1Tree a
-> UBin b
-> Radix1Tree b
-> Radix1Tree a
forall a b.
S a b a b
-> Tsil ByteArray
-> UTip a
-> Radix1Tree a
-> UBin b
-> Radix1Tree b
-> Radix1Tree a
tipBin S a b a b
s Tsil ByteArray
b UTip a
uA Radix1Tree a
tA (# Prefix
pB, Radix1Tree b
lB, Radix1Tree b
rB #) Radix1Tree b
tB
Tip ByteArray
arrB Maybe b
mB Radix1Tree b
dB -> let !wB :: Prefix
wB = ByteArray -> Int -> Prefix
forall a. Prim a => ByteArray -> Int -> a
indexByteArray ByteArray
arrB Int
0
uB :: (# Prefix, Int, ByteArray, Maybe b, Radix1Tree b #)
uB = (# Prefix
wB, Int
0, ByteArray
arrB, Maybe b
mB, Radix1Tree b
dB #)
!lenA :: Int
lenA = ByteArray -> Int
sizeofByteArray ByteArray
arrA Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
nA
!lenB :: Int
lenB = ByteArray -> Int
sizeofByteArray ByteArray
arrB
in if Int
lenB Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
lenA
then S a b a b
-> Tsil ByteArray
-> UTip a
-> Radix1Tree a
-> (# Prefix, Int, ByteArray, Maybe b, Radix1Tree b #)
-> Radix1Tree b
-> Int
-> Radix1Tree a
forall a b.
S a b a b
-> Tsil ByteArray
-> UTip a
-> Radix1Tree a
-> UTip b
-> Radix1Tree b
-> Int
-> Radix1Tree a
tipTip S a b a b
s Tsil ByteArray
b UTip a
uA Radix1Tree a
tA (# Prefix, Int, ByteArray, Maybe b, Radix1Tree b #)
uB Radix1Tree b
tB Int
lenA
else let !(# S b a a b
s' #) = S a b a b -> (# S b a a b #)
forall a b x y. S a b x y -> (# S b a x y #)
other S a b a b
s
in S b a a b
-> Tsil ByteArray
-> (# Prefix, Int, ByteArray, Maybe b, Radix1Tree b #)
-> Radix1Tree b
-> UTip a
-> Radix1Tree a
-> Int
-> Radix1Tree a
forall a b.
S a b a b
-> Tsil ByteArray
-> UTip a
-> Radix1Tree a
-> UTip b
-> Radix1Tree b
-> Int
-> Radix1Tree a
tipTip S b a a b
s' Tsil ByteArray
b (# Prefix, Int, ByteArray, Maybe b, Radix1Tree b #)
uB Radix1Tree b
tB UTip a
uA Radix1Tree a
tA Int
lenB
Radix1Tree b
Nil -> case S a b a b
s of
S a b a b
L | Int
nA Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
0 -> Radix1Tree a
Radix1Tree a
tA
| Bool
otherwise -> ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
Tip (Int -> ByteArray -> ByteArray
dropByteArray Int
nA ByteArray
arrA) Maybe a
Maybe a
mA Radix1Tree a
Radix1Tree a
dA
S a b a b
R -> Radix1Tree a
forall a. Radix1Tree a
Nil
tipTip
:: forall a b. S a b x y -> Tsil ByteArray
-> UTip a -> Radix1Tree a -> UTip b -> Radix1Tree b -> Int -> Radix1Tree x
tipTip :: forall a b.
S a b a b
-> Tsil ByteArray
-> UTip a
-> Radix1Tree a
-> UTip b
-> Radix1Tree b
-> Int
-> Radix1Tree a
tipTip S a b a b
s Tsil ByteArray
b (# Prefix
wA0, Int
nA, ByteArray
arrA, Maybe a
mA, Radix1Tree a
dA #) Radix1Tree a
tA (# Prefix
wB0, Int
nB, ByteArray
arrB, Maybe b
mB, Radix1Tree b
dB #) Radix1Tree b
tB Int
len =
Prefix -> Prefix -> Int -> Radix1Tree a
go Prefix
wA0 Prefix
wB0 Int
1
where
go :: Prefix -> Prefix -> Int -> Radix1Tree a
go Prefix
wA Prefix
wB !Int
o
| Prefix
wA Prefix -> Prefix -> Bool
forall a. Eq a => a -> a -> Bool
== Prefix
wB =
let !nB' :: Int
nB' = Int
nB Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
o
!wB' :: Prefix
wB' = ByteArray -> Int -> Prefix
forall a. Prim a => ByteArray -> Int -> a
indexByteArray ByteArray
arrB Int
nB'
in if Int
o Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
len
then let !arrA' :: ByteArray
arrA' | Int
nA Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
0 = ByteArray
arrA
| Bool
otherwise = Int -> ByteArray -> ByteArray
dropByteArray Int
nA ByteArray
arrA
in if Int
nB' Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== ByteArray -> Int
sizeofByteArray ByteArray
arrB
then let mC :: Maybe a
mC | Just a
xA <- Maybe a
mA, Just b
xB <- Maybe b
mB =
S a b a b -> Tsil ByteArray -> ByteArray -> a -> b -> Maybe a
forall x y.
S x y a b -> Tsil ByteArray -> ByteArray -> x -> y -> Maybe a
f S a b a b
s Tsil ByteArray
b ByteArray
arrA' a
xA b
xB
| Bool
otherwise =
case S a b a b
s of
S a b a b
L -> Maybe a
Maybe a
mA
S a b a b
R -> Maybe a
Maybe b
mB
in ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
retip ByteArray
arrA' Maybe a
mC (S a b a b
-> Tsil ByteArray -> Radix1Tree a -> Radix1Tree b -> Radix1Tree a
forall a b.
S a b a b
-> Tsil ByteArray -> Radix1Tree a -> Radix1Tree b -> Radix1Tree a
anyAny S a b a b
s (Tsil ByteArray -> ByteArray -> Tsil ByteArray
forall a. Tsil a -> a -> Tsil a
Snoc Tsil ByteArray
b ByteArray
arrA') Radix1Tree a
dA Radix1Tree b
dB)
else let mA' :: Maybe a
mA' = case S a b a b
s of
S a b a b
L -> Maybe a
Maybe a
mA
S a b a b
R -> Maybe a
forall a. Maybe a
Nothing
in ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
retip ByteArray
arrA' Maybe a
mA' (Radix1Tree a -> Radix1Tree a) -> Radix1Tree a -> Radix1Tree a
forall a b. (a -> b) -> a -> b
$
let !(# S b a a b
s' #) = S a b a b -> (# S b a a b #)
forall a b x y. S a b x y -> (# S b a x y #)
other S a b a b
s
in S b a a b
-> Tsil ByteArray
-> (# Prefix, Int, ByteArray, Maybe b, Radix1Tree b #)
-> Radix1Tree b
-> Radix1Tree a
-> Radix1Tree a
forall a b.
S a b a b
-> Tsil ByteArray
-> UTip a
-> Radix1Tree a
-> Radix1Tree b
-> Radix1Tree a
tipAny S b a a b
s' (Tsil ByteArray -> ByteArray -> Tsil ByteArray
forall a. Tsil a -> a -> Tsil a
Snoc Tsil ByteArray
b ByteArray
arrA')
(# Prefix
wB', Int
nB', ByteArray
arrB, Maybe b
mB, Radix1Tree b
dB #) Radix1Tree b
tB Radix1Tree a
dA
else let !nA' :: Int
nA' = Int
nA Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
o
!wA' :: Prefix
wA' = ByteArray -> Int -> Prefix
forall a. Prim a => ByteArray -> Int -> a
indexByteArray ByteArray
arrA Int
nA'
in Prefix -> Prefix -> Int -> Radix1Tree a
go Prefix
wA' Prefix
wB' (Int
o Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1)
| Bool
otherwise =
case S a b a b
s of
S a b a b
L | Int
nA Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
0 -> Radix1Tree a
Radix1Tree a
tA
| Bool
otherwise -> ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
Tip (Int -> ByteArray -> ByteArray
dropByteArray Int
nA ByteArray
arrA) Maybe a
Maybe a
mA Radix1Tree a
Radix1Tree a
dA
S a b a b
R | Int
nB Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
0 -> Radix1Tree a
Radix1Tree b
tB
| Bool
otherwise -> ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
Tip (Int -> ByteArray -> ByteArray
dropByteArray Int
nB ByteArray
arrB) Maybe a
Maybe b
mB Radix1Tree a
Radix1Tree b
dB
binAny
:: forall a b. S a b x y -> Tsil ByteArray
-> UBin a -> Radix1Tree a -> Radix1Tree b -> Radix1Tree x
binAny :: forall a b.
S a b a b
-> Tsil ByteArray
-> UBin a
-> Radix1Tree a
-> Radix1Tree b
-> Radix1Tree a
binAny S a b a b
s Tsil ByteArray
b UBin a
uA Radix1Tree a
tA Radix1Tree b
tB =
case Radix1Tree b
tB of
Bin Prefix
pB Radix1Tree b
lB Radix1Tree b
rB -> S a b a b
-> Tsil ByteArray
-> UBin a
-> Radix1Tree a
-> UBin b
-> Radix1Tree b
-> Radix1Tree a
forall a b.
S a b a b
-> Tsil ByteArray
-> UBin a
-> Radix1Tree a
-> UBin b
-> Radix1Tree b
-> Radix1Tree a
binBin S a b a b
s Tsil ByteArray
b UBin a
uA Radix1Tree a
tA (# Prefix
pB, Radix1Tree b
lB, Radix1Tree b
rB #) Radix1Tree b
tB
Tip ByteArray
arrB Maybe b
mB Radix1Tree b
dB -> let !(# S b a a b
s' #) = S a b a b -> (# S b a a b #)
forall a b x y. S a b x y -> (# S b a x y #)
other S a b a b
s
!wB :: Prefix
wB = ByteArray -> Int -> Prefix
forall a. Prim a => ByteArray -> Int -> a
indexByteArray ByteArray
arrB Int
0
in S b a a b
-> Tsil ByteArray
-> UTip b
-> Radix1Tree b
-> UBin a
-> Radix1Tree a
-> Radix1Tree a
forall a b.
S a b a b
-> Tsil ByteArray
-> UTip a
-> Radix1Tree a
-> UBin b
-> Radix1Tree b
-> Radix1Tree a
tipBin S b a a b
s' Tsil ByteArray
b (# Prefix
wB, Int
0, ByteArray
arrB, Maybe b
mB, Radix1Tree b
dB #) Radix1Tree b
tB UBin a
uA Radix1Tree a
tA
Radix1Tree b
Nil -> case S a b a b
s of
S a b a b
L -> Radix1Tree a
Radix1Tree a
tA
S a b a b
R -> Radix1Tree a
Radix1Tree b
tB
tipBin
:: forall a b. S a b x y -> Tsil ByteArray
-> UTip a -> Radix1Tree a -> UBin b -> Radix1Tree b -> Radix1Tree x
tipBin :: forall a b.
S a b a b
-> Tsil ByteArray
-> UTip a
-> Radix1Tree a
-> UBin b
-> Radix1Tree b
-> Radix1Tree a
tipBin S a b a b
s Tsil ByteArray
b uA :: UTip a
uA@(# Prefix
wA, Int
nA, ByteArray
arrA, Maybe a
mA, Radix1Tree a
dA #) Radix1Tree a
tA (# Prefix
pB, Radix1Tree b
lB, Radix1Tree b
rB #) Radix1Tree b
tB
| Prefix -> Prefix -> Bool
beyond Prefix
pB Prefix
wA = case S a b a b
s of
S a b a b
L | Int
nA Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
0 -> Radix1Tree a
Radix1Tree a
tA
| Bool
otherwise -> ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
Tip (Int -> ByteArray -> ByteArray
dropByteArray Int
nA ByteArray
arrA) Maybe a
Maybe a
mA Radix1Tree a
Radix1Tree a
dA
S a b a b
R -> Radix1Tree a
Radix1Tree b
tB
| Prefix
wA Prefix -> Prefix -> Bool
forall a. Ord a => a -> a -> Bool
< Prefix
pB = case S a b a b
s of
S a b a b
L -> S a b a b
-> Tsil ByteArray
-> UTip a
-> Radix1Tree a
-> Radix1Tree b
-> Radix1Tree a
forall a b.
S a b a b
-> Tsil ByteArray
-> UTip a
-> Radix1Tree a
-> Radix1Tree b
-> Radix1Tree a
tipAny S a b a b
s Tsil ByteArray
b UTip a
uA Radix1Tree a
tA Radix1Tree b
lB
S a b a b
R -> Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
forall a. Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
rebinL Prefix
pB (S a b a b
-> Tsil ByteArray
-> UTip a
-> Radix1Tree a
-> Radix1Tree b
-> Radix1Tree a
forall a b.
S a b a b
-> Tsil ByteArray
-> UTip a
-> Radix1Tree a
-> Radix1Tree b
-> Radix1Tree a
tipAny S a b a b
s Tsil ByteArray
b UTip a
uA Radix1Tree a
tA Radix1Tree b
lB) Radix1Tree a
Radix1Tree b
rB
| Bool
otherwise = case S a b a b
s of
S a b a b
L -> S a b a b
-> Tsil ByteArray
-> UTip a
-> Radix1Tree a
-> Radix1Tree b
-> Radix1Tree a
forall a b.
S a b a b
-> Tsil ByteArray
-> UTip a
-> Radix1Tree a
-> Radix1Tree b
-> Radix1Tree a
tipAny S a b a b
s Tsil ByteArray
b UTip a
uA Radix1Tree a
tA Radix1Tree b
rB
S a b a b
R -> Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
forall a. Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
rebinR Prefix
pB Radix1Tree a
Radix1Tree b
lB (S a b a b
-> Tsil ByteArray
-> UTip a
-> Radix1Tree a
-> Radix1Tree b
-> Radix1Tree a
forall a b.
S a b a b
-> Tsil ByteArray
-> UTip a
-> Radix1Tree a
-> Radix1Tree b
-> Radix1Tree a
tipAny S a b a b
s Tsil ByteArray
b UTip a
uA Radix1Tree a
tA Radix1Tree b
rB)
binBin
:: forall a b. S a b x y -> Tsil ByteArray
-> UBin a -> Radix1Tree a -> UBin b -> Radix1Tree b -> Radix1Tree x
binBin :: forall a b.
S a b a b
-> Tsil ByteArray
-> UBin a
-> Radix1Tree a
-> UBin b
-> Radix1Tree b
-> Radix1Tree a
binBin S a b a b
s Tsil ByteArray
b uA :: UBin a
uA@(# Prefix
pA, Radix1Tree a
lA, Radix1Tree a
rA #) Radix1Tree a
tA uB :: UBin b
uB@(# Prefix
pB, Radix1Tree b
lB, Radix1Tree b
rB #) Radix1Tree b
tB =
let no :: Radix1Tree a
no = case S a b a b
s of
S a b a b
L -> Radix1Tree a
Radix1Tree a
tA
S a b a b
R -> Radix1Tree a
Radix1Tree b
tB
in case Prefix -> Prefix -> Ordering
forall a. Ord a => a -> a -> Ordering
Prelude.compare Prefix
pA Prefix
pB of
Ordering
EQ -> Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
forall a. Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
rebin Prefix
pA (S a b a b
-> Tsil ByteArray -> Radix1Tree a -> Radix1Tree b -> Radix1Tree a
forall a b.
S a b a b
-> Tsil ByteArray -> Radix1Tree a -> Radix1Tree b -> Radix1Tree a
anyAny S a b a b
s Tsil ByteArray
b Radix1Tree a
lA Radix1Tree b
lB) (S a b a b
-> Tsil ByteArray -> Radix1Tree a -> Radix1Tree b -> Radix1Tree a
forall a b.
S a b a b
-> Tsil ByteArray -> Radix1Tree a -> Radix1Tree b -> Radix1Tree a
anyAny S a b a b
s Tsil ByteArray
b Radix1Tree a
rA Radix1Tree b
rB)
Ordering
LT | Prefix
pB Prefix -> Prefix -> Bool
forall a. Ord a => a -> a -> Bool
<= Prefix -> Prefix
upper Prefix
pA -> case S a b a b
s of
S a b a b
L -> Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
forall a. Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
rebinR Prefix
pA Radix1Tree a
Radix1Tree a
lA (S b a a b
-> Tsil ByteArray
-> UBin b
-> Radix1Tree b
-> Radix1Tree a
-> Radix1Tree a
forall a b.
S a b a b
-> Tsil ByteArray
-> UBin a
-> Radix1Tree a
-> Radix1Tree b
-> Radix1Tree a
binAny S b a a b
forall a b. S a b b a
R Tsil ByteArray
b UBin b
UBin b
uB Radix1Tree b
Radix1Tree b
tB Radix1Tree a
Radix1Tree a
rA)
S a b a b
R -> S a b a b
-> Tsil ByteArray
-> UBin a
-> Radix1Tree a
-> Radix1Tree b
-> Radix1Tree a
forall a b.
S a b a b
-> Tsil ByteArray
-> UBin a
-> Radix1Tree a
-> Radix1Tree b
-> Radix1Tree a
binAny S a b a b
forall a b. S a b a b
L Tsil ByteArray
b UBin a
UBin b
uB Radix1Tree a
Radix1Tree b
tB Radix1Tree b
Radix1Tree a
rA
| Prefix
pA Prefix -> Prefix -> Bool
forall a. Ord a => a -> a -> Bool
>= Prefix -> Prefix
lower Prefix
pB -> case S a b a b
s of
S a b a b
L -> S a b a b
-> Tsil ByteArray
-> UBin a
-> Radix1Tree a
-> Radix1Tree b
-> Radix1Tree a
forall a b.
S a b a b
-> Tsil ByteArray
-> UBin a
-> Radix1Tree a
-> Radix1Tree b
-> Radix1Tree a
binAny S a b a b
s Tsil ByteArray
b UBin a
uA Radix1Tree a
tA Radix1Tree b
lB
S a b a b
R -> Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
forall a. Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
rebinL Prefix
pB (S a b a b
-> Tsil ByteArray
-> UBin a
-> Radix1Tree a
-> Radix1Tree b
-> Radix1Tree a
forall a b.
S a b a b
-> Tsil ByteArray
-> UBin a
-> Radix1Tree a
-> Radix1Tree b
-> Radix1Tree a
binAny S a b a b
s Tsil ByteArray
b UBin a
uA Radix1Tree a
tA Radix1Tree b
lB) Radix1Tree a
Radix1Tree b
rB
| Bool
otherwise -> Radix1Tree a
no
Ordering
GT | Prefix
pA Prefix -> Prefix -> Bool
forall a. Ord a => a -> a -> Bool
<= Prefix -> Prefix
upper Prefix
pB -> case S a b a b
s of
S a b a b
L -> S a b a b
-> Tsil ByteArray
-> UBin a
-> Radix1Tree a
-> Radix1Tree b
-> Radix1Tree a
forall a b.
S a b a b
-> Tsil ByteArray
-> UBin a
-> Radix1Tree a
-> Radix1Tree b
-> Radix1Tree a
binAny S a b a b
s Tsil ByteArray
b UBin a
uA Radix1Tree a
tA Radix1Tree b
rB
S a b a b
R -> Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
forall a. Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
rebinR Prefix
pB Radix1Tree a
Radix1Tree b
lB (S a b a b
-> Tsil ByteArray
-> UBin a
-> Radix1Tree a
-> Radix1Tree b
-> Radix1Tree a
forall a b.
S a b a b
-> Tsil ByteArray
-> UBin a
-> Radix1Tree a
-> Radix1Tree b
-> Radix1Tree a
binAny S a b a b
s Tsil ByteArray
b UBin a
uA Radix1Tree a
tA Radix1Tree b
rB)
| Prefix
pB Prefix -> Prefix -> Bool
forall a. Ord a => a -> a -> Bool
>= Prefix -> Prefix
lower Prefix
pA -> case S a b a b
s of
S a b a b
L -> Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
forall a. Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
rebinL Prefix
pA (S b a a b
-> Tsil ByteArray
-> UBin b
-> Radix1Tree b
-> Radix1Tree a
-> Radix1Tree a
forall a b.
S a b a b
-> Tsil ByteArray
-> UBin a
-> Radix1Tree a
-> Radix1Tree b
-> Radix1Tree a
binAny S b a a b
forall a b. S a b b a
R Tsil ByteArray
b UBin b
UBin b
uB Radix1Tree b
Radix1Tree b
tB Radix1Tree a
Radix1Tree a
lA) Radix1Tree a
Radix1Tree a
rA
S a b a b
R -> S a b a b
-> Tsil ByteArray
-> UBin a
-> Radix1Tree a
-> Radix1Tree b
-> Radix1Tree a
forall a b.
S a b a b
-> Tsil ByteArray
-> UBin a
-> Radix1Tree a
-> Radix1Tree b
-> Radix1Tree a
binAny S a b a b
forall a b. S a b a b
L Tsil ByteArray
b UBin a
UBin b
uB Radix1Tree a
Radix1Tree b
tB Radix1Tree b
Radix1Tree a
lA
| Bool
otherwise -> Radix1Tree a
no
compare0 :: (a -> b -> Bool) -> RadixTree a -> RadixTree b -> PartialOrdering
compare0 :: forall a b.
(a -> b -> Bool) -> RadixTree a -> RadixTree b -> PartialOrdering
compare0 a -> b -> Bool
f (RadixTree Maybe a
mA Radix1Tree a
tA) (RadixTree Maybe b
mB Radix1Tree b
tB) =
let o :: PartialOrdering
o = case Maybe a
mA of
Just a
xA -> case Maybe b
mB of
Just b
xB
| a -> b -> Bool
f a
xA b
xB -> PartialOrdering
Equal
| Bool
otherwise -> PartialOrdering
Incomparable
Maybe b
Nothing -> PartialOrdering
Superset
Maybe a
Nothing -> case Maybe b
mB of
Just b
_ -> PartialOrdering
Subset
Maybe b
Nothing -> PartialOrdering
Equal
in PartialOrdering -> PartialOrdering -> PartialOrdering
order PartialOrdering
o (PartialOrdering -> PartialOrdering)
-> PartialOrdering -> PartialOrdering
forall a b. (a -> b) -> a -> b
$ (a -> b -> Bool) -> Radix1Tree a -> Radix1Tree b -> PartialOrdering
forall a b.
(a -> b -> Bool) -> Radix1Tree a -> Radix1Tree b -> PartialOrdering
Data.RadixNTree.Word8.Lazy.compare1 a -> b -> Bool
f Radix1Tree a
tA Radix1Tree b
tB
compare1 :: (a -> b -> Bool) -> Radix1Tree a -> Radix1Tree b -> PartialOrdering
compare1 :: forall a b.
(a -> b -> Bool) -> Radix1Tree a -> Radix1Tree b -> PartialOrdering
compare1 (a -> b -> Bool
f :: x -> y -> Bool) = S a b a b -> Radix1Tree a -> Radix1Tree b -> PartialOrdering
forall a b.
S a b a b -> Radix1Tree a -> Radix1Tree b -> PartialOrdering
anyAny S a b a b
forall a b. S a b a b
L
where
anyAny :: forall a b. S a b x y -> Radix1Tree a -> Radix1Tree b -> PartialOrdering
anyAny :: forall a b.
S a b a b -> Radix1Tree a -> Radix1Tree b -> PartialOrdering
anyAny S a b a b
s Radix1Tree a
tA Radix1Tree b
tB =
case Radix1Tree a
tA of
Bin Prefix
pA Radix1Tree a
lA Radix1Tree a
rA -> S a b a b
-> UBin a -> Radix1Tree a -> Radix1Tree b -> PartialOrdering
forall a b.
S a b a b
-> UBin a -> Radix1Tree a -> Radix1Tree b -> PartialOrdering
binAny S a b a b
s (# Prefix
pA, Radix1Tree a
lA, Radix1Tree a
rA #) Radix1Tree a
tA Radix1Tree b
tB
Tip ByteArray
arrA Maybe a
mA Radix1Tree a
dA -> let !wA :: Prefix
wA = ByteArray -> Int -> Prefix
forall a. Prim a => ByteArray -> Int -> a
indexByteArray ByteArray
arrA Int
0
in S a b a b
-> UTip a -> Radix1Tree a -> Radix1Tree b -> PartialOrdering
forall a b.
S a b a b
-> UTip a -> Radix1Tree a -> Radix1Tree b -> PartialOrdering
tipAny S a b a b
s (# Prefix
wA, Int
0, ByteArray
arrA, Maybe a
mA, Radix1Tree a
dA #) Radix1Tree a
tA Radix1Tree b
tB
Radix1Tree a
Nil -> case Radix1Tree b
tB of
Radix1Tree b
Nil -> PartialOrdering
Equal
Radix1Tree b
_ -> case S a b a b
s of
S a b a b
L -> PartialOrdering
Subset
S a b a b
R -> PartialOrdering
Superset
tipAny
:: forall a b. S a b x y -> UTip a -> Radix1Tree a -> Radix1Tree b -> PartialOrdering
tipAny :: forall a b.
S a b a b
-> UTip a -> Radix1Tree a -> Radix1Tree b -> PartialOrdering
tipAny S a b a b
s uA :: UTip a
uA@(# Prefix
_, Int
nA, ByteArray
arrA, Maybe a
_, Radix1Tree a
_ #) Radix1Tree a
tA Radix1Tree b
tB =
case Radix1Tree b
tB of
Bin Prefix
pB Radix1Tree b
lB Radix1Tree b
rB -> S a b a b -> UTip a -> Radix1Tree a -> UBin b -> PartialOrdering
forall a b.
S a b a b -> UTip a -> Radix1Tree a -> UBin b -> PartialOrdering
tipBin S a b a b
s UTip a
uA Radix1Tree a
tA (# Prefix
pB, Radix1Tree b
lB, Radix1Tree b
rB #)
Tip ByteArray
arrB Maybe b
mB Radix1Tree b
dB -> let !wB :: Prefix
wB = ByteArray -> Int -> Prefix
forall a. Prim a => ByteArray -> Int -> a
indexByteArray ByteArray
arrB Int
0
uB :: (# Prefix, Int, ByteArray, Maybe b, Radix1Tree b #)
uB = (# Prefix
wB, Int
0, ByteArray
arrB, Maybe b
mB, Radix1Tree b
dB #)
!lenA :: Int
lenA = ByteArray -> Int
sizeofByteArray ByteArray
arrA Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
nA
!lenB :: Int
lenB = ByteArray -> Int
sizeofByteArray ByteArray
arrB
in if Int
lenB Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
lenA
then S a b a b
-> UTip a
-> (# Prefix, Int, ByteArray, Maybe b, Radix1Tree b #)
-> Radix1Tree b
-> Int
-> PartialOrdering
forall a b.
S a b a b
-> UTip a -> UTip b -> Radix1Tree b -> Int -> PartialOrdering
tipTip S a b a b
s UTip a
uA (# Prefix, Int, ByteArray, Maybe b, Radix1Tree b #)
uB Radix1Tree b
tB Int
lenA
else let !(# S b a a b
s' #) = S a b a b -> (# S b a a b #)
forall a b x y. S a b x y -> (# S b a x y #)
other S a b a b
s
in S b a a b
-> (# Prefix, Int, ByteArray, Maybe b, Radix1Tree b #)
-> UTip a
-> Radix1Tree a
-> Int
-> PartialOrdering
forall a b.
S a b a b
-> UTip a -> UTip b -> Radix1Tree b -> Int -> PartialOrdering
tipTip S b a a b
s' (# Prefix, Int, ByteArray, Maybe b, Radix1Tree b #)
uB UTip a
uA Radix1Tree a
tA Int
lenB
Radix1Tree b
Nil -> case S a b a b
s of
S a b a b
L -> PartialOrdering
Superset
S a b a b
R -> PartialOrdering
Subset
tipTip
:: forall a b. S a b x y -> UTip a -> UTip b -> Radix1Tree b -> Int -> PartialOrdering
tipTip :: forall a b.
S a b a b
-> UTip a -> UTip b -> Radix1Tree b -> Int -> PartialOrdering
tipTip S a b a b
s (# Prefix
wA0, Int
nA, ByteArray
arrA, Maybe a
mA, Radix1Tree a
dA #) (# Prefix
wB0, Int
nB, ByteArray
arrB, Maybe b
mB, Radix1Tree b
dB #) Radix1Tree b
tB Int
len =
Prefix -> Prefix -> Int -> PartialOrdering
go Prefix
wA0 Prefix
wB0 Int
1
where
go :: Prefix -> Prefix -> Int -> PartialOrdering
go Prefix
wA Prefix
wB !Int
o
| Prefix
wA Prefix -> Prefix -> Bool
forall a. Eq a => a -> a -> Bool
== Prefix
wB =
let !nB' :: Int
nB' = Int
nB Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
o
!wB' :: Prefix
wB' = ByteArray -> Int -> Prefix
forall a. Prim a => ByteArray -> Int -> a
indexByteArray ByteArray
arrB Int
nB'
in if Int
o Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
len
then if Int
nB' Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== ByteArray -> Int
sizeofByteArray ByteArray
arrB
then let o_ :: PartialOrdering
o_ = case Maybe a
mA of
Just a
xA -> case Maybe b
mB of
Just b
xB ->
let eq :: Bool
eq = case S a b a b
s of
S a b a b
L -> a -> b -> Bool
f a
a
xA b
b
xB
S a b a b
R -> a -> b -> Bool
f a
b
xB b
a
xA
in if Bool
eq
then PartialOrdering
Equal
else PartialOrdering
Incomparable
Maybe b
Nothing -> case S a b a b
s of
S a b a b
L -> PartialOrdering
Superset
S a b a b
R -> PartialOrdering
Subset
Maybe a
Nothing -> case Maybe b
mB of
Just b
_ -> case S a b a b
s of
S a b a b
L -> PartialOrdering
Subset
S a b a b
R -> PartialOrdering
Superset
Maybe b
Nothing -> PartialOrdering
Equal
in PartialOrdering -> PartialOrdering -> PartialOrdering
order PartialOrdering
o_ (PartialOrdering -> PartialOrdering)
-> PartialOrdering -> PartialOrdering
forall a b. (a -> b) -> a -> b
$ S a b a b -> Radix1Tree a -> Radix1Tree b -> PartialOrdering
forall a b.
S a b a b -> Radix1Tree a -> Radix1Tree b -> PartialOrdering
anyAny S a b a b
s Radix1Tree a
dA Radix1Tree b
dB
else let !(# S b a a b
s' #) = S a b a b -> (# S b a a b #)
forall a b x y. S a b x y -> (# S b a x y #)
other S a b a b
s
in S b a a b
-> (# Prefix, Int, ByteArray, Maybe b, Radix1Tree b #)
-> Radix1Tree b
-> Radix1Tree a
-> PartialOrdering
forall a b.
S a b a b
-> UTip a -> Radix1Tree a -> Radix1Tree b -> PartialOrdering
tipAny S b a a b
s' (# Prefix
wB', Int
nB', ByteArray
arrB, Maybe b
mB, Radix1Tree b
dB #) Radix1Tree b
tB Radix1Tree a
dA
else let !nA' :: Int
nA' = Int
nA Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
o
!wA' :: Prefix
wA' = ByteArray -> Int -> Prefix
forall a. Prim a => ByteArray -> Int -> a
indexByteArray ByteArray
arrA Int
nA'
in Prefix -> Prefix -> Int -> PartialOrdering
go Prefix
wA' Prefix
wB' (Int
o Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1)
| Bool
otherwise = case S a b a b
s of
S a b a b
L -> PartialOrdering
Superset
S a b a b
R -> PartialOrdering
Subset
binAny
:: forall a b. S a b x y -> UBin a -> Radix1Tree a -> Radix1Tree b -> PartialOrdering
binAny :: forall a b.
S a b a b
-> UBin a -> Radix1Tree a -> Radix1Tree b -> PartialOrdering
binAny S a b a b
s UBin a
uA Radix1Tree a
tA Radix1Tree b
tB =
case Radix1Tree b
tB of
Bin Prefix
pB Radix1Tree b
lB Radix1Tree b
rB -> S a b a b
-> UBin a
-> Radix1Tree a
-> UBin b
-> Radix1Tree b
-> PartialOrdering
forall a b.
S a b a b
-> UBin a
-> Radix1Tree a
-> UBin b
-> Radix1Tree b
-> PartialOrdering
binBin S a b a b
s UBin a
uA Radix1Tree a
tA (# Prefix
pB, Radix1Tree b
lB, Radix1Tree b
rB #) Radix1Tree b
tB
Tip ByteArray
arrB Maybe b
mB Radix1Tree b
dB -> let !(# S b a a b
s' #) = S a b a b -> (# S b a a b #)
forall a b x y. S a b x y -> (# S b a x y #)
other S a b a b
s
!wB :: Prefix
wB = ByteArray -> Int -> Prefix
forall a. Prim a => ByteArray -> Int -> a
indexByteArray ByteArray
arrB Int
0
in S b a a b -> UTip b -> Radix1Tree b -> UBin a -> PartialOrdering
forall a b.
S a b a b -> UTip a -> Radix1Tree a -> UBin b -> PartialOrdering
tipBin S b a a b
s' (# Prefix
wB, Int
0, ByteArray
arrB, Maybe b
mB, Radix1Tree b
dB #) Radix1Tree b
tB UBin a
uA
Radix1Tree b
Nil -> case S a b a b
s of
S a b a b
L -> PartialOrdering
Superset
S a b a b
R -> PartialOrdering
Subset
tipBin :: forall a b. S a b x y -> UTip a -> Radix1Tree a -> UBin b -> PartialOrdering
tipBin :: forall a b.
S a b a b -> UTip a -> Radix1Tree a -> UBin b -> PartialOrdering
tipBin S a b a b
s uA :: UTip a
uA@(# Prefix
wA, Int
_, ByteArray
_, Maybe a
_, Radix1Tree a
_ #) Radix1Tree a
tA (# Prefix
pB, Radix1Tree b
lB, Radix1Tree b
rB #)
| Prefix -> Prefix -> Bool
beyond Prefix
pB Prefix
wA = PartialOrdering
Incomparable
| Bool
otherwise = S a b a b -> PartialOrdering -> PartialOrdering
forall x y a b. S x y a b -> PartialOrdering -> PartialOrdering
limit S a b a b
s (PartialOrdering -> PartialOrdering)
-> (Radix1Tree b -> PartialOrdering)
-> Radix1Tree b
-> PartialOrdering
forall b c a. (b -> c) -> (a -> b) -> a -> c
. S a b a b
-> UTip a -> Radix1Tree a -> Radix1Tree b -> PartialOrdering
forall a b.
S a b a b
-> UTip a -> Radix1Tree a -> Radix1Tree b -> PartialOrdering
tipAny S a b a b
s UTip a
uA Radix1Tree a
tA (Radix1Tree b -> PartialOrdering)
-> Radix1Tree b -> PartialOrdering
forall a b. (a -> b) -> a -> b
$ if Prefix
wA Prefix -> Prefix -> Bool
forall a. Ord a => a -> a -> Bool
< Prefix
pB
then Radix1Tree b
lB
else Radix1Tree b
rB
binBin
:: forall a b. S a b x y
-> UBin a -> Radix1Tree a -> UBin b -> Radix1Tree b -> PartialOrdering
binBin :: forall a b.
S a b a b
-> UBin a
-> Radix1Tree a
-> UBin b
-> Radix1Tree b
-> PartialOrdering
binBin S a b a b
s uA :: UBin a
uA@(# Prefix
pA, Radix1Tree a
lA, Radix1Tree a
rA #) Radix1Tree a
tA uB :: UBin b
uB@(# Prefix
pB, Radix1Tree b
lB, Radix1Tree b
rB #) Radix1Tree b
tB =
case Prefix -> Prefix -> Ordering
forall a. Ord a => a -> a -> Ordering
Prelude.compare Prefix
pA Prefix
pB of
Ordering
EQ -> PartialOrdering -> PartialOrdering -> PartialOrdering
order (S a b a b -> Radix1Tree a -> Radix1Tree b -> PartialOrdering
forall a b.
S a b a b -> Radix1Tree a -> Radix1Tree b -> PartialOrdering
anyAny S a b a b
s Radix1Tree a
lA Radix1Tree b
lB) (S a b a b -> Radix1Tree a -> Radix1Tree b -> PartialOrdering
forall a b.
S a b a b -> Radix1Tree a -> Radix1Tree b -> PartialOrdering
anyAny S a b a b
s Radix1Tree a
rA Radix1Tree b
rB)
Ordering
LT | Prefix
pB Prefix -> Prefix -> Bool
forall a. Ord a => a -> a -> Bool
<= Prefix -> Prefix
upper Prefix
pA -> let !(# S b a a b
s' #) = S a b a b -> (# S b a a b #)
forall a b x y. S a b x y -> (# S b a x y #)
other S a b a b
s
in S b a a b -> PartialOrdering -> PartialOrdering
forall x y a b. S x y a b -> PartialOrdering -> PartialOrdering
limit S b a a b
s' (PartialOrdering -> PartialOrdering)
-> PartialOrdering -> PartialOrdering
forall a b. (a -> b) -> a -> b
$ S b a a b
-> UBin b -> Radix1Tree b -> Radix1Tree a -> PartialOrdering
forall a b.
S a b a b
-> UBin a -> Radix1Tree a -> Radix1Tree b -> PartialOrdering
binAny S b a a b
s' UBin b
uB Radix1Tree b
tB Radix1Tree a
rA
| Prefix
pA Prefix -> Prefix -> Bool
forall a. Ord a => a -> a -> Bool
>= Prefix -> Prefix
lower Prefix
pB -> S a b a b -> PartialOrdering -> PartialOrdering
forall x y a b. S x y a b -> PartialOrdering -> PartialOrdering
limit S a b a b
s (PartialOrdering -> PartialOrdering)
-> PartialOrdering -> PartialOrdering
forall a b. (a -> b) -> a -> b
$ S a b a b
-> UBin a -> Radix1Tree a -> Radix1Tree b -> PartialOrdering
forall a b.
S a b a b
-> UBin a -> Radix1Tree a -> Radix1Tree b -> PartialOrdering
binAny S a b a b
s UBin a
uA Radix1Tree a
tA Radix1Tree b
lB
| Bool
otherwise -> PartialOrdering
Incomparable
Ordering
GT | Prefix
pA Prefix -> Prefix -> Bool
forall a. Ord a => a -> a -> Bool
<= Prefix -> Prefix
upper Prefix
pB -> S a b a b -> PartialOrdering -> PartialOrdering
forall x y a b. S x y a b -> PartialOrdering -> PartialOrdering
limit S a b a b
s (PartialOrdering -> PartialOrdering)
-> PartialOrdering -> PartialOrdering
forall a b. (a -> b) -> a -> b
$ S a b a b
-> UBin a -> Radix1Tree a -> Radix1Tree b -> PartialOrdering
forall a b.
S a b a b
-> UBin a -> Radix1Tree a -> Radix1Tree b -> PartialOrdering
binAny S a b a b
s UBin a
uA Radix1Tree a
tA Radix1Tree b
rB
| Prefix
pB Prefix -> Prefix -> Bool
forall a. Ord a => a -> a -> Bool
>= Prefix -> Prefix
lower Prefix
pA -> let !(# S b a a b
s' #) = S a b a b -> (# S b a a b #)
forall a b x y. S a b x y -> (# S b a x y #)
other S a b a b
s
in S b a a b -> PartialOrdering -> PartialOrdering
forall x y a b. S x y a b -> PartialOrdering -> PartialOrdering
limit S b a a b
s' (PartialOrdering -> PartialOrdering)
-> PartialOrdering -> PartialOrdering
forall a b. (a -> b) -> a -> b
$ S b a a b
-> UBin b -> Radix1Tree b -> Radix1Tree a -> PartialOrdering
forall a b.
S a b a b
-> UBin a -> Radix1Tree a -> Radix1Tree b -> PartialOrdering
binAny S b a a b
s' UBin b
uB Radix1Tree b
tB Radix1Tree a
lA
| Bool
otherwise -> PartialOrdering
Incomparable
disjoint0 :: RadixTree a -> RadixTree b -> Bool
disjoint0 :: forall a b. RadixTree a -> RadixTree b -> Bool
disjoint0 (RadixTree Maybe a
mA Radix1Tree a
tA) (RadixTree Maybe b
mB Radix1Tree b
tB) =
let mC :: Bool
mC | Just a
_ <- Maybe a
mA, Just b
_ <- Maybe b
mB = Bool
False
| Bool
otherwise = Bool
True
in Bool
mC Bool -> Bool -> Bool
&& Radix1Tree a -> Radix1Tree b -> Bool
forall a b. Radix1Tree a -> Radix1Tree b -> Bool
disjoint1 Radix1Tree a
tA Radix1Tree b
tB
disjoint1 :: Radix1Tree a -> Radix1Tree b -> Bool
disjoint1 :: forall a b. Radix1Tree a -> Radix1Tree b -> Bool
disjoint1 = Radix1Tree a -> Radix1Tree b -> Bool
forall a b. Radix1Tree a -> Radix1Tree b -> Bool
anyAny
where
anyAny :: forall a b. Radix1Tree a -> Radix1Tree b -> Bool
anyAny :: forall a b. Radix1Tree a -> Radix1Tree b -> Bool
anyAny Radix1Tree a
tA Radix1Tree b
tB =
case Radix1Tree a
tA of
Bin Prefix
pA Radix1Tree a
lA Radix1Tree a
rA -> UBin a -> Radix1Tree a -> Radix1Tree b -> Bool
forall a b. UBin a -> Radix1Tree a -> Radix1Tree b -> Bool
binAny (# Prefix
pA, Radix1Tree a
lA, Radix1Tree a
rA #) Radix1Tree a
tA Radix1Tree b
tB
Tip ByteArray
arrA Maybe a
mA Radix1Tree a
dA -> let !wA :: Prefix
wA = ByteArray -> Int -> Prefix
forall a. Prim a => ByteArray -> Int -> a
indexByteArray ByteArray
arrA Int
0
in UTip a -> Radix1Tree a -> Radix1Tree b -> Bool
forall a b. UTip a -> Radix1Tree a -> Radix1Tree b -> Bool
tipAny (# Prefix
wA, Int
0, ByteArray
arrA, Maybe a
mA, Radix1Tree a
dA #) Radix1Tree a
tA Radix1Tree b
tB
Radix1Tree a
Nil -> Bool
True
tipAny :: forall a b. UTip a -> Radix1Tree a -> Radix1Tree b -> Bool
tipAny :: forall a b. UTip a -> Radix1Tree a -> Radix1Tree b -> Bool
tipAny uA :: UTip a
uA@(# Prefix
_, Int
nA, ByteArray
arrA, Maybe a
_, Radix1Tree a
_ #) Radix1Tree a
tA Radix1Tree b
tB =
case Radix1Tree b
tB of
Bin Prefix
pB Radix1Tree b
lB Radix1Tree b
rB -> UTip a -> Radix1Tree a -> UBin b -> Bool
forall a b. UTip a -> Radix1Tree a -> UBin b -> Bool
tipBin UTip a
uA Radix1Tree a
tA (# Prefix
pB, Radix1Tree b
lB, Radix1Tree b
rB #)
Tip ByteArray
arrB Maybe b
mB Radix1Tree b
dB -> let !wB :: Prefix
wB = ByteArray -> Int -> Prefix
forall a. Prim a => ByteArray -> Int -> a
indexByteArray ByteArray
arrB Int
0
uB :: (# Prefix, Int, ByteArray, Maybe b, Radix1Tree b #)
uB = (# Prefix
wB, Int
0, ByteArray
arrB, Maybe b
mB, Radix1Tree b
dB #)
!lenA :: Int
lenA = ByteArray -> Int
sizeofByteArray ByteArray
arrA Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
nA
!lenB :: Int
lenB = ByteArray -> Int
sizeofByteArray ByteArray
arrB
in if Int
lenB Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
lenA
then UTip a
-> (# Prefix, Int, ByteArray, Maybe b, Radix1Tree b #)
-> Radix1Tree b
-> Int
-> Bool
forall a b. UTip a -> UTip b -> Radix1Tree b -> Int -> Bool
tipTip UTip a
uA (# Prefix, Int, ByteArray, Maybe b, Radix1Tree b #)
uB Radix1Tree b
tB Int
lenA
else (# Prefix, Int, ByteArray, Maybe b, Radix1Tree b #)
-> UTip a -> Radix1Tree a -> Int -> Bool
forall a b. UTip a -> UTip b -> Radix1Tree b -> Int -> Bool
tipTip (# Prefix, Int, ByteArray, Maybe b, Radix1Tree b #)
uB UTip a
uA Radix1Tree a
tA Int
lenB
Radix1Tree b
Nil -> Bool
True
tipTip :: forall a b. UTip a -> UTip b -> Radix1Tree b -> Int -> Bool
tipTip :: forall a b. UTip a -> UTip b -> Radix1Tree b -> Int -> Bool
tipTip (# Prefix
wA0, Int
nA, ByteArray
arrA, Maybe a
mA, Radix1Tree a
dA #) (# Prefix
wB0, Int
nB, ByteArray
arrB, Maybe b
mB, Radix1Tree b
dB #) Radix1Tree b
tB Int
len = Prefix -> Prefix -> Int -> Bool
go Prefix
wA0 Prefix
wB0 Int
1
where
go :: Prefix -> Prefix -> Int -> Bool
go Prefix
wA Prefix
wB !Int
o
| Prefix
wA Prefix -> Prefix -> Bool
forall a. Eq a => a -> a -> Bool
== Prefix
wB =
let !nB' :: Int
nB' = Int
nB Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
o
!wB' :: Prefix
wB' = ByteArray -> Int -> Prefix
forall a. Prim a => ByteArray -> Int -> a
indexByteArray ByteArray
arrB Int
nB'
in if Int
o Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
len
then if Int
nB' Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== ByteArray -> Int
sizeofByteArray ByteArray
arrB
then let mC :: Bool
mC | Just a
_ <- Maybe a
mA, Just b
_ <- Maybe b
mB = Bool
False
| Bool
otherwise = Bool
True
in Bool
mC Bool -> Bool -> Bool
&& Radix1Tree a -> Radix1Tree b -> Bool
forall a b. Radix1Tree a -> Radix1Tree b -> Bool
anyAny Radix1Tree a
dA Radix1Tree b
dB
else (# Prefix, Int, ByteArray, Maybe b, Radix1Tree b #)
-> Radix1Tree b -> Radix1Tree a -> Bool
forall a b. UTip a -> Radix1Tree a -> Radix1Tree b -> Bool
tipAny (# Prefix
wB', Int
nB', ByteArray
arrB, Maybe b
mB, Radix1Tree b
dB #) Radix1Tree b
tB Radix1Tree a
dA
else let !nA' :: Int
nA' = Int
nA Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
o
!wA' :: Prefix
wA' = ByteArray -> Int -> Prefix
forall a. Prim a => ByteArray -> Int -> a
indexByteArray ByteArray
arrA Int
nA'
in Prefix -> Prefix -> Int -> Bool
go Prefix
wA' Prefix
wB' (Int
o Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1)
| Bool
otherwise = Bool
True
binAny :: forall a b. UBin a -> Radix1Tree a -> Radix1Tree b -> Bool
binAny :: forall a b. UBin a -> Radix1Tree a -> Radix1Tree b -> Bool
binAny UBin a
uA Radix1Tree a
tA Radix1Tree b
tB =
case Radix1Tree b
tB of
Bin Prefix
pB Radix1Tree b
lB Radix1Tree b
rB -> UBin a -> Radix1Tree a -> UBin b -> Radix1Tree b -> Bool
forall a b.
UBin a -> Radix1Tree a -> UBin b -> Radix1Tree b -> Bool
binBin UBin a
uA Radix1Tree a
tA (# Prefix
pB, Radix1Tree b
lB, Radix1Tree b
rB #) Radix1Tree b
tB
Tip ByteArray
arrB Maybe b
mB Radix1Tree b
dB -> let !wB :: Prefix
wB = ByteArray -> Int -> Prefix
forall a. Prim a => ByteArray -> Int -> a
indexByteArray ByteArray
arrB Int
0
in UTip b -> Radix1Tree b -> UBin a -> Bool
forall a b. UTip a -> Radix1Tree a -> UBin b -> Bool
tipBin (# Prefix
wB, Int
0, ByteArray
arrB, Maybe b
mB, Radix1Tree b
dB #) Radix1Tree b
tB UBin a
uA
Radix1Tree b
Nil -> Bool
True
tipBin :: forall a b. UTip a -> Radix1Tree a -> UBin b -> Bool
tipBin :: forall a b. UTip a -> Radix1Tree a -> UBin b -> Bool
tipBin uA :: UTip a
uA@(# Prefix
wA, Int
_, ByteArray
_, Maybe a
_, Radix1Tree a
_ #) Radix1Tree a
tA (# Prefix
pB, Radix1Tree b
lB, Radix1Tree b
rB #)
| Prefix -> Prefix -> Bool
beyond Prefix
pB Prefix
wA = Bool
True
| Bool
otherwise = UTip a -> Radix1Tree a -> Radix1Tree b -> Bool
forall a b. UTip a -> Radix1Tree a -> Radix1Tree b -> Bool
tipAny UTip a
uA Radix1Tree a
tA (Radix1Tree b -> Bool) -> Radix1Tree b -> Bool
forall a b. (a -> b) -> a -> b
$ if Prefix
wA Prefix -> Prefix -> Bool
forall a. Ord a => a -> a -> Bool
< Prefix
pB
then Radix1Tree b
lB
else Radix1Tree b
rB
binBin :: forall a b. UBin a -> Radix1Tree a -> UBin b -> Radix1Tree b -> Bool
binBin :: forall a b.
UBin a -> Radix1Tree a -> UBin b -> Radix1Tree b -> Bool
binBin uA :: UBin a
uA@(# Prefix
pA, Radix1Tree a
lA, Radix1Tree a
rA #) Radix1Tree a
tA uB :: UBin b
uB@(# Prefix
pB, Radix1Tree b
lB, Radix1Tree b
rB #) Radix1Tree b
tB =
case Prefix -> Prefix -> Ordering
forall a. Ord a => a -> a -> Ordering
Prelude.compare Prefix
pA Prefix
pB of
Ordering
EQ -> Radix1Tree a -> Radix1Tree b -> Bool
forall a b. Radix1Tree a -> Radix1Tree b -> Bool
anyAny Radix1Tree a
lA Radix1Tree b
lB Bool -> Bool -> Bool
&& Radix1Tree a -> Radix1Tree b -> Bool
forall a b. Radix1Tree a -> Radix1Tree b -> Bool
anyAny Radix1Tree a
rA Radix1Tree b
rB
Ordering
LT | Prefix
pB Prefix -> Prefix -> Bool
forall a. Ord a => a -> a -> Bool
<= Prefix -> Prefix
upper Prefix
pA -> UBin b -> Radix1Tree b -> Radix1Tree a -> Bool
forall a b. UBin a -> Radix1Tree a -> Radix1Tree b -> Bool
binAny UBin b
uB Radix1Tree b
tB Radix1Tree a
rA
| Prefix
pA Prefix -> Prefix -> Bool
forall a. Ord a => a -> a -> Bool
>= Prefix -> Prefix
lower Prefix
pB -> UBin a -> Radix1Tree a -> Radix1Tree b -> Bool
forall a b. UBin a -> Radix1Tree a -> Radix1Tree b -> Bool
binAny UBin a
uA Radix1Tree a
tA Radix1Tree b
lB
| Bool
otherwise -> Bool
True
Ordering
GT | Prefix
pA Prefix -> Prefix -> Bool
forall a. Ord a => a -> a -> Bool
<= Prefix -> Prefix
upper Prefix
pB -> UBin a -> Radix1Tree a -> Radix1Tree b -> Bool
forall a b. UBin a -> Radix1Tree a -> Radix1Tree b -> Bool
binAny UBin a
uA Radix1Tree a
tA Radix1Tree b
rB
| Prefix
pB Prefix -> Prefix -> Bool
forall a. Ord a => a -> a -> Bool
>= Prefix -> Prefix
lower Prefix
pA -> UBin b -> Radix1Tree b -> Radix1Tree a -> Bool
forall a b. UBin a -> Radix1Tree a -> Radix1Tree b -> Bool
binAny UBin b
uB Radix1Tree b
tB Radix1Tree a
lA
| Bool
otherwise -> Bool
True
intersection0 :: RadixTree a -> RadixTree a -> RadixTree a
intersection0 :: forall a. RadixTree a -> RadixTree a -> RadixTree a
intersection0 (RadixTree Maybe a
mA Radix1Tree a
tA) (RadixTree Maybe a
mB Radix1Tree a
tB) =
let mC :: Maybe a
mC | Just a
_ <- Maybe a
mA, Just a
_ <- Maybe a
mB = Maybe a
mA
| Bool
otherwise = Maybe a
forall a. Maybe a
Nothing
in Maybe a -> Radix1Tree a -> RadixTree a
forall a. Maybe a -> Radix1Tree a -> RadixTree a
RadixTree Maybe a
mC (Radix1Tree a -> Radix1Tree a -> Radix1Tree a
forall a. Radix1Tree a -> Radix1Tree a -> Radix1Tree a
intersection1 Radix1Tree a
tA Radix1Tree a
tB)
intersection1 :: Radix1Tree a -> Radix1Tree a -> Radix1Tree a
intersection1 :: forall a. Radix1Tree a -> Radix1Tree a -> Radix1Tree a
intersection1 = Radix1Tree a -> Radix1Tree a -> Radix1Tree a
forall a. Radix1Tree a -> Radix1Tree a -> Radix1Tree a
anyAny
where
anyAny :: Radix1Tree a -> Radix1Tree a -> Radix1Tree a
anyAny Radix1Tree a
tA Radix1Tree a
tB =
case Radix1Tree a
tA of
Bin Prefix
pA Radix1Tree a
lA Radix1Tree a
rA -> (# Prefix, Radix1Tree a, Radix1Tree a #)
-> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
binAny (# Prefix
pA, Radix1Tree a
lA, Radix1Tree a
rA #) Radix1Tree a
tA Radix1Tree a
tB
Tip ByteArray
arrA Maybe a
mA Radix1Tree a
dA -> let !wA :: Prefix
wA = ByteArray -> Int -> Prefix
forall a. Prim a => ByteArray -> Int -> a
indexByteArray ByteArray
arrA Int
0
in (# Prefix, Int, ByteArray, Maybe a, Radix1Tree a #)
-> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
tipAny (# Prefix
wA, Int
0, ByteArray
arrA, Maybe a
mA, Radix1Tree a
dA #) Radix1Tree a
tA Radix1Tree a
tB
Radix1Tree a
Nil -> Radix1Tree a
forall a. Radix1Tree a
Nil
tipAny :: (# Prefix, Int, ByteArray, Maybe a, Radix1Tree a #)
-> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
tipAny uA :: (# Prefix, Int, ByteArray, Maybe a, Radix1Tree a #)
uA@(# Prefix
_, Int
nA, ByteArray
arrA, Maybe a
_, Radix1Tree a
_ #) Radix1Tree a
tA Radix1Tree a
tB =
case Radix1Tree a
tB of
Bin Prefix
pB Radix1Tree a
lB Radix1Tree a
rB -> (# Prefix, Int, ByteArray, Maybe a, Radix1Tree a #)
-> Radix1Tree a
-> (# Prefix, Radix1Tree a, Radix1Tree a #)
-> Radix1Tree a
tipBin (# Prefix, Int, ByteArray, Maybe a, Radix1Tree a #)
uA Radix1Tree a
tA (# Prefix
pB, Radix1Tree a
lB, Radix1Tree a
rB #)
Tip ByteArray
arrB Maybe a
mB Radix1Tree a
dB -> let !wB :: Prefix
wB = ByteArray -> Int -> Prefix
forall a. Prim a => ByteArray -> Int -> a
indexByteArray ByteArray
arrB Int
0
uB :: (# Prefix, Int, ByteArray, Maybe a, Radix1Tree a #)
uB = (# Prefix
wB, Int
0, ByteArray
arrB, Maybe a
mB, Radix1Tree a
dB #)
!lenA :: Int
lenA = ByteArray -> Int
sizeofByteArray ByteArray
arrA Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
nA
!lenB :: Int
lenB = ByteArray -> Int
sizeofByteArray ByteArray
arrB
in if Int
lenB Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
lenA
then (# Prefix, Int, ByteArray, Maybe a, Radix1Tree a #)
-> (# Prefix, Int, ByteArray, Maybe a, Radix1Tree a #)
-> Radix1Tree a
-> Int
-> Radix1Tree a
tipTip (# Prefix, Int, ByteArray, Maybe a, Radix1Tree a #)
uA (# Prefix, Int, ByteArray, Maybe a, Radix1Tree a #)
uB Radix1Tree a
tB Int
lenA
else (# Prefix, Int, ByteArray, Maybe a, Radix1Tree a #)
-> (# Prefix, Int, ByteArray, Maybe a, Radix1Tree a #)
-> Radix1Tree a
-> Int
-> Radix1Tree a
tipTip (# Prefix, Int, ByteArray, Maybe a, Radix1Tree a #)
uB (# Prefix, Int, ByteArray, Maybe a, Radix1Tree a #)
uA Radix1Tree a
tA Int
lenB
Radix1Tree a
Nil -> Radix1Tree a
forall a. Radix1Tree a
Nil
tipTip :: (# Prefix, Int, ByteArray, Maybe a, Radix1Tree a #)
-> (# Prefix, Int, ByteArray, Maybe a, Radix1Tree a #)
-> Radix1Tree a
-> Int
-> Radix1Tree a
tipTip (# Prefix
wA0, Int
nA, ByteArray
arrA, Maybe a
mA, Radix1Tree a
dA #) (# Prefix
wB0, Int
nB, ByteArray
arrB, Maybe a
mB, Radix1Tree a
dB #) Radix1Tree a
tB Int
len = Prefix -> Prefix -> Int -> Radix1Tree a
go Prefix
wA0 Prefix
wB0 Int
1
where
go :: Prefix -> Prefix -> Int -> Radix1Tree a
go Prefix
wA Prefix
wB !Int
o
| Prefix
wA Prefix -> Prefix -> Bool
forall a. Eq a => a -> a -> Bool
== Prefix
wB =
let !nB' :: Int
nB' = Int
nB Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
o
!wB' :: Prefix
wB' = ByteArray -> Int -> Prefix
forall a. Prim a => ByteArray -> Int -> a
indexByteArray ByteArray
arrB Int
nB'
in if Int
o Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
len
then let !arrA' :: ByteArray
arrA' | Int
nA Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
0 = ByteArray
arrA
| Bool
otherwise = Int -> ByteArray -> ByteArray
dropByteArray Int
nA ByteArray
arrA
in if Int
nB' Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== ByteArray -> Int
sizeofByteArray ByteArray
arrB
then let mC :: Maybe a
mC | Just a
_ <- Maybe a
mA, Just a
_ <- Maybe a
mB = Maybe a
mA
| Bool
otherwise = Maybe a
forall a. Maybe a
Nothing
in ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
retip ByteArray
arrA' Maybe a
mC (Radix1Tree a -> Radix1Tree a -> Radix1Tree a
anyAny Radix1Tree a
dA Radix1Tree a
dB)
else ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
retip ByteArray
arrA' Maybe a
forall a. Maybe a
Nothing (Radix1Tree a -> Radix1Tree a) -> Radix1Tree a -> Radix1Tree a
forall a b. (a -> b) -> a -> b
$
(# Prefix, Int, ByteArray, Maybe a, Radix1Tree a #)
-> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
tipAny (# Prefix
wB', Int
nB', ByteArray
arrB, Maybe a
mB, Radix1Tree a
dB #) Radix1Tree a
tB Radix1Tree a
dA
else let !nA' :: Int
nA' = Int
nA Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
o
!wA' :: Prefix
wA' = ByteArray -> Int -> Prefix
forall a. Prim a => ByteArray -> Int -> a
indexByteArray ByteArray
arrA Int
nA'
in Prefix -> Prefix -> Int -> Radix1Tree a
go Prefix
wA' Prefix
wB' (Int
o Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1)
| Bool
otherwise = Radix1Tree a
forall a. Radix1Tree a
Nil
binAny :: (# Prefix, Radix1Tree a, Radix1Tree a #)
-> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
binAny (# Prefix, Radix1Tree a, Radix1Tree a #)
uA Radix1Tree a
tA Radix1Tree a
tB =
case Radix1Tree a
tB of
Bin Prefix
pB Radix1Tree a
lB Radix1Tree a
rB -> (# Prefix, Radix1Tree a, Radix1Tree a #)
-> Radix1Tree a
-> (# Prefix, Radix1Tree a, Radix1Tree a #)
-> Radix1Tree a
-> Radix1Tree a
binBin (# Prefix, Radix1Tree a, Radix1Tree a #)
uA Radix1Tree a
tA (# Prefix
pB, Radix1Tree a
lB, Radix1Tree a
rB #) Radix1Tree a
tB
Tip ByteArray
arrB Maybe a
mB Radix1Tree a
dB -> let !wB :: Prefix
wB = ByteArray -> Int -> Prefix
forall a. Prim a => ByteArray -> Int -> a
indexByteArray ByteArray
arrB Int
0
in (# Prefix, Int, ByteArray, Maybe a, Radix1Tree a #)
-> Radix1Tree a
-> (# Prefix, Radix1Tree a, Radix1Tree a #)
-> Radix1Tree a
tipBin (# Prefix
wB, Int
0, ByteArray
arrB, Maybe a
mB, Radix1Tree a
dB #) Radix1Tree a
tB (# Prefix, Radix1Tree a, Radix1Tree a #)
uA
Radix1Tree a
Nil -> Radix1Tree a
forall a. Radix1Tree a
Nil
tipBin :: (# Prefix, Int, ByteArray, Maybe a, Radix1Tree a #)
-> Radix1Tree a
-> (# Prefix, Radix1Tree a, Radix1Tree a #)
-> Radix1Tree a
tipBin uA :: (# Prefix, Int, ByteArray, Maybe a, Radix1Tree a #)
uA@(# Prefix
wA, Int
_, ByteArray
_, Maybe a
_, Radix1Tree a
_ #) Radix1Tree a
tA (# Prefix
pB, Radix1Tree a
lB, Radix1Tree a
rB #)
| Prefix -> Prefix -> Bool
beyond Prefix
pB Prefix
wA = Radix1Tree a
forall a. Radix1Tree a
Nil
| Bool
otherwise = (# Prefix, Int, ByteArray, Maybe a, Radix1Tree a #)
-> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
tipAny (# Prefix, Int, ByteArray, Maybe a, Radix1Tree a #)
uA Radix1Tree a
tA (Radix1Tree a -> Radix1Tree a) -> Radix1Tree a -> Radix1Tree a
forall a b. (a -> b) -> a -> b
$ if Prefix
wA Prefix -> Prefix -> Bool
forall a. Ord a => a -> a -> Bool
< Prefix
pB
then Radix1Tree a
lB
else Radix1Tree a
rB
binBin :: (# Prefix, Radix1Tree a, Radix1Tree a #)
-> Radix1Tree a
-> (# Prefix, Radix1Tree a, Radix1Tree a #)
-> Radix1Tree a
-> Radix1Tree a
binBin uA :: (# Prefix, Radix1Tree a, Radix1Tree a #)
uA@(# Prefix
pA, Radix1Tree a
lA, Radix1Tree a
rA #) Radix1Tree a
tA uB :: (# Prefix, Radix1Tree a, Radix1Tree a #)
uB@(# Prefix
pB, Radix1Tree a
lB, Radix1Tree a
rB #) Radix1Tree a
tB =
case Prefix -> Prefix -> Ordering
forall a. Ord a => a -> a -> Ordering
Prelude.compare Prefix
pA Prefix
pB of
Ordering
EQ -> Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
forall a. Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
rebin Prefix
pA (Radix1Tree a -> Radix1Tree a -> Radix1Tree a
anyAny Radix1Tree a
lA Radix1Tree a
lB) (Radix1Tree a -> Radix1Tree a -> Radix1Tree a
anyAny Radix1Tree a
rA Radix1Tree a
rB)
Ordering
LT | Prefix
pB Prefix -> Prefix -> Bool
forall a. Ord a => a -> a -> Bool
<= Prefix -> Prefix
upper Prefix
pA -> (# Prefix, Radix1Tree a, Radix1Tree a #)
-> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
binAny (# Prefix, Radix1Tree a, Radix1Tree a #)
uB Radix1Tree a
tB Radix1Tree a
rA
| Prefix
pA Prefix -> Prefix -> Bool
forall a. Ord a => a -> a -> Bool
>= Prefix -> Prefix
lower Prefix
pB -> (# Prefix, Radix1Tree a, Radix1Tree a #)
-> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
binAny (# Prefix, Radix1Tree a, Radix1Tree a #)
uA Radix1Tree a
tA Radix1Tree a
lB
| Bool
otherwise -> Radix1Tree a
forall a. Radix1Tree a
Nil
Ordering
GT | Prefix
pA Prefix -> Prefix -> Bool
forall a. Ord a => a -> a -> Bool
<= Prefix -> Prefix
upper Prefix
pB -> (# Prefix, Radix1Tree a, Radix1Tree a #)
-> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
binAny (# Prefix, Radix1Tree a, Radix1Tree a #)
uA Radix1Tree a
tA Radix1Tree a
rB
| Prefix
pB Prefix -> Prefix -> Bool
forall a. Ord a => a -> a -> Bool
>= Prefix -> Prefix
lower Prefix
pA -> (# Prefix, Radix1Tree a, Radix1Tree a #)
-> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
binAny (# Prefix, Radix1Tree a, Radix1Tree a #)
uB Radix1Tree a
tB Radix1Tree a
lA
| Bool
otherwise -> Radix1Tree a
forall a. Radix1Tree a
Nil
intersectionL0 :: RadixTree a -> RadixTree b -> RadixTree a
intersectionL0 :: forall a b. RadixTree a -> RadixTree b -> RadixTree a
intersectionL0 (RadixTree Maybe a
mA Radix1Tree a
tA) (RadixTree Maybe b
mB Radix1Tree b
tB) =
let mC :: Maybe a
mC | Just a
_ <- Maybe a
mA, Just b
_ <- Maybe b
mB = Maybe a
mA
| Bool
otherwise = Maybe a
forall a. Maybe a
Nothing
in Maybe a -> Radix1Tree a -> RadixTree a
forall a. Maybe a -> Radix1Tree a -> RadixTree a
RadixTree Maybe a
mC (Radix1Tree a -> Radix1Tree b -> Radix1Tree a
forall a b. Radix1Tree a -> Radix1Tree b -> Radix1Tree a
intersectionL1 Radix1Tree a
tA Radix1Tree b
tB)
intersectionL1 :: Radix1Tree a -> Radix1Tree b -> Radix1Tree a
intersectionL1 :: forall a b. Radix1Tree a -> Radix1Tree b -> Radix1Tree a
intersectionL1 =
(forall x y. S x y a b -> x -> y -> Maybe a)
-> Radix1Tree a -> Radix1Tree b -> Radix1Tree a
forall a b c.
(forall x y. S x y a b -> x -> y -> Maybe c)
-> Radix1Tree a -> Radix1Tree b -> Radix1Tree c
intersection_ ((forall x y. S x y a b -> x -> y -> Maybe a)
-> Radix1Tree a -> Radix1Tree b -> Radix1Tree a)
-> (forall x y. S x y a b -> x -> y -> Maybe a)
-> Radix1Tree a
-> Radix1Tree b
-> Radix1Tree a
forall a b. (a -> b) -> a -> b
$ \S x y a b
s x
a y
b ->
let !(# a
c #) = case S x y a b
s of
S x y a b
L -> (# x
a #)
S x y a b
R -> (# y
b #)
in a -> Maybe a
forall a. a -> Maybe a
Just a
c
intersectionWith0 :: (a -> b -> c) -> RadixTree a -> RadixTree b -> RadixTree c
intersectionWith0 :: forall a b c.
(a -> b -> c) -> RadixTree a -> RadixTree b -> RadixTree c
intersectionWith0 a -> b -> c
f (RadixTree Maybe a
mA Radix1Tree a
tA) (RadixTree Maybe b
mB Radix1Tree b
tB) =
let mC :: Maybe c
mC | Just a
a <- Maybe a
mA, Just b
b <- Maybe b
mB = c -> Maybe c
forall a. a -> Maybe a
Just (c -> Maybe c) -> c -> Maybe c
forall a b. (a -> b) -> a -> b
$ a -> b -> c
f a
a b
b
| Bool
otherwise = Maybe c
forall a. Maybe a
Nothing
in Maybe c -> Radix1Tree c -> RadixTree c
forall a. Maybe a -> Radix1Tree a -> RadixTree a
RadixTree Maybe c
mC ((a -> b -> c) -> Radix1Tree a -> Radix1Tree b -> Radix1Tree c
forall a b c.
(a -> b -> c) -> Radix1Tree a -> Radix1Tree b -> Radix1Tree c
intersectionWith1 a -> b -> c
f Radix1Tree a
tA Radix1Tree b
tB)
intersectionWith1 :: (a -> b -> c) -> Radix1Tree a -> Radix1Tree b -> Radix1Tree c
intersectionWith1 :: forall a b c.
(a -> b -> c) -> Radix1Tree a -> Radix1Tree b -> Radix1Tree c
intersectionWith1 a -> b -> c
f =
(forall x y. S x y a b -> x -> y -> Maybe c)
-> Radix1Tree a -> Radix1Tree b -> Radix1Tree c
forall a b c.
(forall x y. S x y a b -> x -> y -> Maybe c)
-> Radix1Tree a -> Radix1Tree b -> Radix1Tree c
intersection_ ((forall x y. S x y a b -> x -> y -> Maybe c)
-> Radix1Tree a -> Radix1Tree b -> Radix1Tree c)
-> (forall x y. S x y a b -> x -> y -> Maybe c)
-> Radix1Tree a
-> Radix1Tree b
-> Radix1Tree c
forall a b. (a -> b) -> a -> b
$ \S x y a b
s x
a y
b ->
let !(# c
c #) = case S x y a b
s of
S x y a b
L -> (# a -> b -> c
f a
x
a b
y
b #)
S x y a b
R -> (# a -> b -> c
f a
y
b b
x
a #)
in c -> Maybe c
forall a. a -> Maybe a
Just c
c
{-# INLINE intersection_ #-}
intersection_
:: (forall x y. S x y a b -> x -> y -> Maybe c)
-> Radix1Tree a
-> Radix1Tree b
-> Radix1Tree c
intersection_ :: forall a b c.
(forall x y. S x y a b -> x -> y -> Maybe c)
-> Radix1Tree a -> Radix1Tree b -> Radix1Tree c
intersection_ (forall x y. S x y a b -> x -> y -> Maybe c
f :: forall n o. S n o x y -> n -> o -> Maybe c) = S a b a b -> Radix1Tree a -> Radix1Tree b -> Radix1Tree c
forall a b.
S a b a b -> Radix1Tree a -> Radix1Tree b -> Radix1Tree c
anyAny S a b a b
forall a b. S a b a b
L
where
anyAny :: forall a b. S a b x y -> Radix1Tree a -> Radix1Tree b -> Radix1Tree c
anyAny :: forall a b.
S a b a b -> Radix1Tree a -> Radix1Tree b -> Radix1Tree c
anyAny S a b a b
s Radix1Tree a
tA Radix1Tree b
tB =
case Radix1Tree a
tA of
Bin Prefix
pA Radix1Tree a
lA Radix1Tree a
rA -> S a b a b -> UBin a -> Radix1Tree a -> Radix1Tree b -> Radix1Tree c
forall a b.
S a b a b -> UBin a -> Radix1Tree a -> Radix1Tree b -> Radix1Tree c
binAny S a b a b
s (# Prefix
pA, Radix1Tree a
lA, Radix1Tree a
rA #) Radix1Tree a
tA Radix1Tree b
tB
Tip ByteArray
arrA Maybe a
mA Radix1Tree a
dA -> let !wA :: Prefix
wA = ByteArray -> Int -> Prefix
forall a. Prim a => ByteArray -> Int -> a
indexByteArray ByteArray
arrA Int
0
in S a b a b -> UTip a -> Radix1Tree a -> Radix1Tree b -> Radix1Tree c
forall a b.
S a b a b -> UTip a -> Radix1Tree a -> Radix1Tree b -> Radix1Tree c
tipAny S a b a b
s (# Prefix
wA, Int
0, ByteArray
arrA, Maybe a
mA, Radix1Tree a
dA #) Radix1Tree a
tA Radix1Tree b
tB
Radix1Tree a
Nil -> Radix1Tree c
forall a. Radix1Tree a
Nil
tipAny
:: forall a b. S a b x y -> UTip a -> Radix1Tree a -> Radix1Tree b -> Radix1Tree c
tipAny :: forall a b.
S a b a b -> UTip a -> Radix1Tree a -> Radix1Tree b -> Radix1Tree c
tipAny S a b a b
s uA :: UTip a
uA@(# Prefix
_, Int
nA, ByteArray
arrA, Maybe a
_, Radix1Tree a
_ #) Radix1Tree a
tA Radix1Tree b
tB =
case Radix1Tree b
tB of
Bin Prefix
pB Radix1Tree b
lB Radix1Tree b
rB -> S a b a b -> UTip a -> Radix1Tree a -> UBin b -> Radix1Tree c
forall a b.
S a b a b -> UTip a -> Radix1Tree a -> UBin b -> Radix1Tree c
tipBin S a b a b
s UTip a
uA Radix1Tree a
tA (# Prefix
pB, Radix1Tree b
lB, Radix1Tree b
rB #)
Tip ByteArray
arrB Maybe b
mB Radix1Tree b
dB -> let !wB :: Prefix
wB = ByteArray -> Int -> Prefix
forall a. Prim a => ByteArray -> Int -> a
indexByteArray ByteArray
arrB Int
0
uB :: (# Prefix, Int, ByteArray, Maybe b, Radix1Tree b #)
uB = (# Prefix
wB, Int
0, ByteArray
arrB, Maybe b
mB, Radix1Tree b
dB #)
!lenA :: Int
lenA = ByteArray -> Int
sizeofByteArray ByteArray
arrA Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
nA
!lenB :: Int
lenB = ByteArray -> Int
sizeofByteArray ByteArray
arrB
in if Int
lenB Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
lenA
then S a b a b
-> UTip a
-> (# Prefix, Int, ByteArray, Maybe b, Radix1Tree b #)
-> Radix1Tree b
-> Int
-> Radix1Tree c
forall a b.
S a b a b
-> UTip a -> UTip b -> Radix1Tree b -> Int -> Radix1Tree c
tipTip S a b a b
s UTip a
uA (# Prefix, Int, ByteArray, Maybe b, Radix1Tree b #)
uB Radix1Tree b
tB Int
lenA
else let !(# S b a a b
s' #) = S a b a b -> (# S b a a b #)
forall a b x y. S a b x y -> (# S b a x y #)
other S a b a b
s
in S b a a b
-> (# Prefix, Int, ByteArray, Maybe b, Radix1Tree b #)
-> UTip a
-> Radix1Tree a
-> Int
-> Radix1Tree c
forall a b.
S a b a b
-> UTip a -> UTip b -> Radix1Tree b -> Int -> Radix1Tree c
tipTip S b a a b
s' (# Prefix, Int, ByteArray, Maybe b, Radix1Tree b #)
uB UTip a
uA Radix1Tree a
tA Int
lenB
Radix1Tree b
Nil -> Radix1Tree c
forall a. Radix1Tree a
Nil
tipTip
:: forall a b. S a b x y -> UTip a -> UTip b -> Radix1Tree b -> Int -> Radix1Tree c
tipTip :: forall a b.
S a b a b
-> UTip a -> UTip b -> Radix1Tree b -> Int -> Radix1Tree c
tipTip S a b a b
s (# Prefix
wA0, Int
nA, ByteArray
arrA, Maybe a
mA, Radix1Tree a
dA #) (# Prefix
wB0, Int
nB, ByteArray
arrB, Maybe b
mB, Radix1Tree b
dB #) Radix1Tree b
tB Int
len =
Prefix -> Prefix -> Int -> Radix1Tree c
go Prefix
wA0 Prefix
wB0 Int
1
where
go :: Prefix -> Prefix -> Int -> Radix1Tree c
go Prefix
wA Prefix
wB !Int
o
| Prefix
wA Prefix -> Prefix -> Bool
forall a. Eq a => a -> a -> Bool
== Prefix
wB =
let !nB' :: Int
nB' = Int
nB Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
o
!wB' :: Prefix
wB' = ByteArray -> Int -> Prefix
forall a. Prim a => ByteArray -> Int -> a
indexByteArray ByteArray
arrB Int
nB'
in if Int
o Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
len
then let !arrA' :: ByteArray
arrA' | Int
nA Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
0 = ByteArray
arrA
| Bool
otherwise = Int -> ByteArray -> ByteArray
dropByteArray Int
nA ByteArray
arrA
in if Int
nB' Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== ByteArray -> Int
sizeofByteArray ByteArray
arrB
then let mC :: Maybe c
mC | Just a
xA <- Maybe a
mA, Just b
xB <- Maybe b
mB = S a b a b -> a -> b -> Maybe c
forall x y. S x y a b -> x -> y -> Maybe c
f S a b a b
s a
xA b
xB
| Bool
otherwise = Maybe c
forall a. Maybe a
Nothing
in ByteArray -> Maybe c -> Radix1Tree c -> Radix1Tree c
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
retip ByteArray
arrA' Maybe c
mC (S a b a b -> Radix1Tree a -> Radix1Tree b -> Radix1Tree c
forall a b.
S a b a b -> Radix1Tree a -> Radix1Tree b -> Radix1Tree c
anyAny S a b a b
s Radix1Tree a
dA Radix1Tree b
dB)
else ByteArray -> Maybe c -> Radix1Tree c -> Radix1Tree c
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
retip ByteArray
arrA' Maybe c
forall a. Maybe a
Nothing (Radix1Tree c -> Radix1Tree c) -> Radix1Tree c -> Radix1Tree c
forall a b. (a -> b) -> a -> b
$
let !(# S b a a b
s' #) = S a b a b -> (# S b a a b #)
forall a b x y. S a b x y -> (# S b a x y #)
other S a b a b
s
in S b a a b
-> (# Prefix, Int, ByteArray, Maybe b, Radix1Tree b #)
-> Radix1Tree b
-> Radix1Tree a
-> Radix1Tree c
forall a b.
S a b a b -> UTip a -> Radix1Tree a -> Radix1Tree b -> Radix1Tree c
tipAny S b a a b
s' (# Prefix
wB', Int
nB', ByteArray
arrB, Maybe b
mB, Radix1Tree b
dB #) Radix1Tree b
tB Radix1Tree a
dA
else let !nA' :: Int
nA' = Int
nA Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
o
!wA' :: Prefix
wA' = ByteArray -> Int -> Prefix
forall a. Prim a => ByteArray -> Int -> a
indexByteArray ByteArray
arrA Int
nA'
in Prefix -> Prefix -> Int -> Radix1Tree c
go Prefix
wA' Prefix
wB' (Int
o Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1)
| Bool
otherwise = Radix1Tree c
forall a. Radix1Tree a
Nil
binAny
:: forall a b. S a b x y -> UBin a -> Radix1Tree a -> Radix1Tree b -> Radix1Tree c
binAny :: forall a b.
S a b a b -> UBin a -> Radix1Tree a -> Radix1Tree b -> Radix1Tree c
binAny S a b a b
s UBin a
uA Radix1Tree a
tA Radix1Tree b
tB =
case Radix1Tree b
tB of
Bin Prefix
pB Radix1Tree b
lB Radix1Tree b
rB -> S a b a b
-> UBin a -> Radix1Tree a -> UBin b -> Radix1Tree b -> Radix1Tree c
forall a b.
S a b a b
-> UBin a -> Radix1Tree a -> UBin b -> Radix1Tree b -> Radix1Tree c
binBin S a b a b
s UBin a
uA Radix1Tree a
tA (# Prefix
pB, Radix1Tree b
lB, Radix1Tree b
rB #) Radix1Tree b
tB
Tip ByteArray
arrB Maybe b
mB Radix1Tree b
dB -> let !(# S b a a b
s' #) = S a b a b -> (# S b a a b #)
forall a b x y. S a b x y -> (# S b a x y #)
other S a b a b
s
!wB :: Prefix
wB = ByteArray -> Int -> Prefix
forall a. Prim a => ByteArray -> Int -> a
indexByteArray ByteArray
arrB Int
0
in S b a a b -> UTip b -> Radix1Tree b -> UBin a -> Radix1Tree c
forall a b.
S a b a b -> UTip a -> Radix1Tree a -> UBin b -> Radix1Tree c
tipBin S b a a b
s' (# Prefix
wB, Int
0, ByteArray
arrB, Maybe b
mB, Radix1Tree b
dB #) Radix1Tree b
tB UBin a
uA
Radix1Tree b
Nil -> Radix1Tree c
forall a. Radix1Tree a
Nil
tipBin :: forall a b. S a b x y -> UTip a -> Radix1Tree a -> UBin b -> Radix1Tree c
tipBin :: forall a b.
S a b a b -> UTip a -> Radix1Tree a -> UBin b -> Radix1Tree c
tipBin S a b a b
s uA :: UTip a
uA@(# Prefix
wA, Int
_, ByteArray
_, Maybe a
_, Radix1Tree a
_ #) Radix1Tree a
tA (# Prefix
pB, Radix1Tree b
lB, Radix1Tree b
rB #)
| Prefix -> Prefix -> Bool
beyond Prefix
pB Prefix
wA = Radix1Tree c
forall a. Radix1Tree a
Nil
| Bool
otherwise = S a b a b -> UTip a -> Radix1Tree a -> Radix1Tree b -> Radix1Tree c
forall a b.
S a b a b -> UTip a -> Radix1Tree a -> Radix1Tree b -> Radix1Tree c
tipAny S a b a b
s UTip a
uA Radix1Tree a
tA (Radix1Tree b -> Radix1Tree c) -> Radix1Tree b -> Radix1Tree c
forall a b. (a -> b) -> a -> b
$ if Prefix
wA Prefix -> Prefix -> Bool
forall a. Ord a => a -> a -> Bool
< Prefix
pB
then Radix1Tree b
lB
else Radix1Tree b
rB
binBin
:: forall a b. S a b x y
-> UBin a -> Radix1Tree a -> UBin b -> Radix1Tree b -> Radix1Tree c
binBin :: forall a b.
S a b a b
-> UBin a -> Radix1Tree a -> UBin b -> Radix1Tree b -> Radix1Tree c
binBin S a b a b
s uA :: UBin a
uA@(# Prefix
pA, Radix1Tree a
lA, Radix1Tree a
rA #) Radix1Tree a
tA uB :: UBin b
uB@(# Prefix
pB, Radix1Tree b
lB, Radix1Tree b
rB #) Radix1Tree b
tB =
case Prefix -> Prefix -> Ordering
forall a. Ord a => a -> a -> Ordering
Prelude.compare Prefix
pA Prefix
pB of
Ordering
EQ -> Prefix -> Radix1Tree c -> Radix1Tree c -> Radix1Tree c
forall a. Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
rebin Prefix
pA (S a b a b -> Radix1Tree a -> Radix1Tree b -> Radix1Tree c
forall a b.
S a b a b -> Radix1Tree a -> Radix1Tree b -> Radix1Tree c
anyAny S a b a b
s Radix1Tree a
lA Radix1Tree b
lB) (S a b a b -> Radix1Tree a -> Radix1Tree b -> Radix1Tree c
forall a b.
S a b a b -> Radix1Tree a -> Radix1Tree b -> Radix1Tree c
anyAny S a b a b
s Radix1Tree a
rA Radix1Tree b
rB)
Ordering
LT | Prefix
pB Prefix -> Prefix -> Bool
forall a. Ord a => a -> a -> Bool
<= Prefix -> Prefix
upper Prefix
pA -> let !(# S b a a b
s' #) = S a b a b -> (# S b a a b #)
forall a b x y. S a b x y -> (# S b a x y #)
other S a b a b
s
in S b a a b -> UBin b -> Radix1Tree b -> Radix1Tree a -> Radix1Tree c
forall a b.
S a b a b -> UBin a -> Radix1Tree a -> Radix1Tree b -> Radix1Tree c
binAny S b a a b
s' UBin b
uB Radix1Tree b
tB Radix1Tree a
rA
| Prefix
pA Prefix -> Prefix -> Bool
forall a. Ord a => a -> a -> Bool
>= Prefix -> Prefix
lower Prefix
pB -> S a b a b -> UBin a -> Radix1Tree a -> Radix1Tree b -> Radix1Tree c
forall a b.
S a b a b -> UBin a -> Radix1Tree a -> Radix1Tree b -> Radix1Tree c
binAny S a b a b
s UBin a
uA Radix1Tree a
tA Radix1Tree b
lB
| Bool
otherwise -> Radix1Tree c
forall a. Radix1Tree a
Nil
Ordering
GT | Prefix
pA Prefix -> Prefix -> Bool
forall a. Ord a => a -> a -> Bool
<= Prefix -> Prefix
upper Prefix
pB -> S a b a b -> UBin a -> Radix1Tree a -> Radix1Tree b -> Radix1Tree c
forall a b.
S a b a b -> UBin a -> Radix1Tree a -> Radix1Tree b -> Radix1Tree c
binAny S a b a b
s UBin a
uA Radix1Tree a
tA Radix1Tree b
rB
| Prefix
pB Prefix -> Prefix -> Bool
forall a. Ord a => a -> a -> Bool
>= Prefix -> Prefix
lower Prefix
pA -> let !(# S b a a b
s' #) = S a b a b -> (# S b a a b #)
forall a b x y. S a b x y -> (# S b a x y #)
other S a b a b
s
in S b a a b -> UBin b -> Radix1Tree b -> Radix1Tree a -> Radix1Tree c
forall a b.
S a b a b -> UBin a -> Radix1Tree a -> Radix1Tree b -> Radix1Tree c
binAny S b a a b
s' UBin b
uB Radix1Tree b
tB Radix1Tree a
lA
| Bool
otherwise -> Radix1Tree c
forall a. Radix1Tree a
Nil
intersectionWithKey0
:: (Build -> a -> b -> c) -> RadixTree a -> RadixTree b -> RadixTree c
intersectionWithKey0 :: forall a b c.
(Build -> a -> b -> c) -> RadixTree a -> RadixTree b -> RadixTree c
intersectionWithKey0 Build -> a -> b -> c
f (RadixTree Maybe a
mA Radix1Tree a
tA) (RadixTree Maybe b
mB Radix1Tree b
tB) =
let mC :: Maybe c
mC | Just a
a <- Maybe a
mA, Just b
b <- Maybe b
mB = c -> Maybe c
forall a. a -> Maybe a
Just (c -> Maybe c) -> c -> Maybe c
forall a b. (a -> b) -> a -> b
$ Build -> a -> b -> c
f (Tsil ByteArray -> Build
Build Tsil ByteArray
forall a. Tsil a
Lin) a
a b
b
| Bool
otherwise = Maybe c
forall a. Maybe a
Nothing
in Maybe c -> Radix1Tree c -> RadixTree c
forall a. Maybe a -> Radix1Tree a -> RadixTree a
RadixTree Maybe c
mC (Radix1Tree c -> RadixTree c) -> Radix1Tree c -> RadixTree c
forall a b. (a -> b) -> a -> b
$ (forall x y.
S x y a b -> Tsil ByteArray -> ByteArray -> x -> y -> Maybe c)
-> Radix1Tree a -> Radix1Tree b -> Radix1Tree c
forall a b c.
(forall x y.
S x y a b -> Tsil ByteArray -> ByteArray -> x -> y -> Maybe c)
-> Radix1Tree a -> Radix1Tree b -> Radix1Tree c
intersectionWithKey_
( \S x y a b
s Tsil ByteArray
b ByteArray
arr x
vA y
vB ->
let b0 :: Build
b0 = Tsil ByteArray -> Build
Build (Tsil ByteArray -> Build) -> Tsil ByteArray -> Build
forall a b. (a -> b) -> a -> b
$ Tsil ByteArray -> ByteArray -> Tsil ByteArray
forall a. Tsil a -> a -> Tsil a
Snoc Tsil ByteArray
b ByteArray
arr
!(# c
c #) = case S x y a b
s of
S x y a b
L -> (# Build -> a -> b -> c
f Build
b0 a
x
vA b
y
vB #)
S x y a b
R -> (# Build -> a -> b -> c
f Build
b0 a
y
vB b
x
vA #)
in c -> Maybe c
forall a. a -> Maybe a
Just c
c
)
Radix1Tree a
tA Radix1Tree b
tB
intersectionWithKey1
:: (Build1 -> a -> b -> c) -> Radix1Tree a -> Radix1Tree b -> Radix1Tree c
intersectionWithKey1 :: forall a b c.
(Build1 -> a -> b -> c)
-> Radix1Tree a -> Radix1Tree b -> Radix1Tree c
intersectionWithKey1 Build1 -> a -> b -> c
f =
(forall x y.
S x y a b -> Tsil ByteArray -> ByteArray -> x -> y -> Maybe c)
-> Radix1Tree a -> Radix1Tree b -> Radix1Tree c
forall a b c.
(forall x y.
S x y a b -> Tsil ByteArray -> ByteArray -> x -> y -> Maybe c)
-> Radix1Tree a -> Radix1Tree b -> Radix1Tree c
intersectionWithKey_ ((forall x y.
S x y a b -> Tsil ByteArray -> ByteArray -> x -> y -> Maybe c)
-> Radix1Tree a -> Radix1Tree b -> Radix1Tree c)
-> (forall x y.
S x y a b -> Tsil ByteArray -> ByteArray -> x -> y -> Maybe c)
-> Radix1Tree a
-> Radix1Tree b
-> Radix1Tree c
forall a b. (a -> b) -> a -> b
$ \S x y a b
s Tsil ByteArray
b ByteArray
arr x
vA y
vB ->
let b1 :: Build1
b1 = YtpmeNon ByteArray -> Build1
Build1 (YtpmeNon ByteArray -> Build1) -> YtpmeNon ByteArray -> Build1
forall a b. (a -> b) -> a -> b
$ Tsil ByteArray
b Tsil ByteArray -> ByteArray -> YtpmeNon ByteArray
forall a. Tsil a -> a -> YtpmeNon a
:/ ByteArray
arr
!(# c
c #) = case S x y a b
s of
S x y a b
L -> (# Build1 -> a -> b -> c
f Build1
b1 a
x
vA b
y
vB #)
S x y a b
R -> (# Build1 -> a -> b -> c
f Build1
b1 a
y
vB b
x
vA #)
in c -> Maybe c
forall a. a -> Maybe a
Just c
c
{-# INLINE intersectionWithKey_ #-}
intersectionWithKey_
:: (forall x y. S x y a b -> Tsil ByteArray -> ByteArray -> x -> y -> Maybe c)
-> Radix1Tree a
-> Radix1Tree b
-> Radix1Tree c
intersectionWithKey_ :: forall a b c.
(forall x y.
S x y a b -> Tsil ByteArray -> ByteArray -> x -> y -> Maybe c)
-> Radix1Tree a -> Radix1Tree b -> Radix1Tree c
intersectionWithKey_
(forall x y.
S x y a b -> Tsil ByteArray -> ByteArray -> x -> y -> Maybe c
f :: forall n o. S n o x y -> Tsil ByteArray -> ByteArray -> n -> o -> Maybe c) =
S a b a b
-> Tsil ByteArray -> Radix1Tree a -> Radix1Tree b -> Radix1Tree c
forall a b.
S a b a b
-> Tsil ByteArray -> Radix1Tree a -> Radix1Tree b -> Radix1Tree c
anyAny S a b a b
forall a b. S a b a b
L Tsil ByteArray
forall a. Tsil a
Lin
where
anyAny
:: forall a b. S a b x y -> Tsil ByteArray
-> Radix1Tree a -> Radix1Tree b -> Radix1Tree c
anyAny :: forall a b.
S a b a b
-> Tsil ByteArray -> Radix1Tree a -> Radix1Tree b -> Radix1Tree c
anyAny S a b a b
s Tsil ByteArray
b Radix1Tree a
tA Radix1Tree b
tB =
case Radix1Tree a
tA of
Bin Prefix
pA Radix1Tree a
lA Radix1Tree a
rA -> S a b a b
-> Tsil ByteArray
-> UBin a
-> Radix1Tree a
-> Radix1Tree b
-> Radix1Tree c
forall a b.
S a b a b
-> Tsil ByteArray
-> UBin a
-> Radix1Tree a
-> Radix1Tree b
-> Radix1Tree c
binAny S a b a b
s Tsil ByteArray
b (# Prefix
pA, Radix1Tree a
lA, Radix1Tree a
rA #) Radix1Tree a
tA Radix1Tree b
tB
Tip ByteArray
arrA Maybe a
mA Radix1Tree a
dA -> let !wA :: Prefix
wA = ByteArray -> Int -> Prefix
forall a. Prim a => ByteArray -> Int -> a
indexByteArray ByteArray
arrA Int
0
in S a b a b
-> Tsil ByteArray
-> UTip a
-> Radix1Tree a
-> Radix1Tree b
-> Radix1Tree c
forall a b.
S a b a b
-> Tsil ByteArray
-> UTip a
-> Radix1Tree a
-> Radix1Tree b
-> Radix1Tree c
tipAny S a b a b
s Tsil ByteArray
b (# Prefix
wA, Int
0, ByteArray
arrA, Maybe a
mA, Radix1Tree a
dA #) Radix1Tree a
tA Radix1Tree b
tB
Radix1Tree a
Nil -> Radix1Tree c
forall a. Radix1Tree a
Nil
tipAny
:: forall a b. S a b x y -> Tsil ByteArray
-> UTip a -> Radix1Tree a -> Radix1Tree b -> Radix1Tree c
tipAny :: forall a b.
S a b a b
-> Tsil ByteArray
-> UTip a
-> Radix1Tree a
-> Radix1Tree b
-> Radix1Tree c
tipAny S a b a b
s Tsil ByteArray
b uA :: UTip a
uA@(# Prefix
_, Int
nA, ByteArray
arrA, Maybe a
_, Radix1Tree a
_ #) Radix1Tree a
tA Radix1Tree b
tB =
case Radix1Tree b
tB of
Bin Prefix
pB Radix1Tree b
lB Radix1Tree b
rB -> S a b a b
-> Tsil ByteArray
-> UTip a
-> Radix1Tree a
-> UBin b
-> Radix1Tree c
forall a b.
S a b a b
-> Tsil ByteArray
-> UTip a
-> Radix1Tree a
-> UBin b
-> Radix1Tree c
tipBin S a b a b
s Tsil ByteArray
b UTip a
uA Radix1Tree a
tA (# Prefix
pB, Radix1Tree b
lB, Radix1Tree b
rB #)
Tip ByteArray
arrB Maybe b
mB Radix1Tree b
dB -> let !wB :: Prefix
wB = ByteArray -> Int -> Prefix
forall a. Prim a => ByteArray -> Int -> a
indexByteArray ByteArray
arrB Int
0
uB :: (# Prefix, Int, ByteArray, Maybe b, Radix1Tree b #)
uB = (# Prefix
wB, Int
0, ByteArray
arrB, Maybe b
mB, Radix1Tree b
dB #)
!lenA :: Int
lenA = ByteArray -> Int
sizeofByteArray ByteArray
arrA Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
nA
!lenB :: Int
lenB = ByteArray -> Int
sizeofByteArray ByteArray
arrB
in if Int
lenB Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
lenA
then S a b a b
-> Tsil ByteArray
-> UTip a
-> (# Prefix, Int, ByteArray, Maybe b, Radix1Tree b #)
-> Radix1Tree b
-> Int
-> Radix1Tree c
forall a b.
S a b a b
-> Tsil ByteArray
-> UTip a
-> UTip b
-> Radix1Tree b
-> Int
-> Radix1Tree c
tipTip S a b a b
s Tsil ByteArray
b UTip a
uA (# Prefix, Int, ByteArray, Maybe b, Radix1Tree b #)
uB Radix1Tree b
tB Int
lenA
else let !(# S b a a b
s' #) = S a b a b -> (# S b a a b #)
forall a b x y. S a b x y -> (# S b a x y #)
other S a b a b
s
in S b a a b
-> Tsil ByteArray
-> (# Prefix, Int, ByteArray, Maybe b, Radix1Tree b #)
-> UTip a
-> Radix1Tree a
-> Int
-> Radix1Tree c
forall a b.
S a b a b
-> Tsil ByteArray
-> UTip a
-> UTip b
-> Radix1Tree b
-> Int
-> Radix1Tree c
tipTip S b a a b
s' Tsil ByteArray
b (# Prefix, Int, ByteArray, Maybe b, Radix1Tree b #)
uB UTip a
uA Radix1Tree a
tA Int
lenB
Radix1Tree b
Nil -> Radix1Tree c
forall a. Radix1Tree a
Nil
tipTip
:: forall a b. S a b x y -> Tsil ByteArray
-> UTip a -> UTip b -> Radix1Tree b -> Int -> Radix1Tree c
tipTip :: forall a b.
S a b a b
-> Tsil ByteArray
-> UTip a
-> UTip b
-> Radix1Tree b
-> Int
-> Radix1Tree c
tipTip S a b a b
s Tsil ByteArray
b (# Prefix
wA0, Int
nA, ByteArray
arrA, Maybe a
mA, Radix1Tree a
dA #) (# Prefix
wB0, Int
nB, ByteArray
arrB, Maybe b
mB, Radix1Tree b
dB #) Radix1Tree b
tB Int
len =
Prefix -> Prefix -> Int -> Radix1Tree c
go Prefix
wA0 Prefix
wB0 Int
1
where
go :: Prefix -> Prefix -> Int -> Radix1Tree c
go Prefix
wA Prefix
wB !Int
o
| Prefix
wA Prefix -> Prefix -> Bool
forall a. Eq a => a -> a -> Bool
== Prefix
wB =
let !nB' :: Int
nB' = Int
nB Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
o
!wB' :: Prefix
wB' = ByteArray -> Int -> Prefix
forall a. Prim a => ByteArray -> Int -> a
indexByteArray ByteArray
arrB Int
nB'
in if Int
o Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
len
then let !arrA' :: ByteArray
arrA' | Int
nA Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
0 = ByteArray
arrA
| Bool
otherwise = Int -> ByteArray -> ByteArray
dropByteArray Int
nA ByteArray
arrA
in if Int
nB' Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== ByteArray -> Int
sizeofByteArray ByteArray
arrB
then let mC :: Maybe c
mC | Just a
xA <- Maybe a
mA, Just b
xB <- Maybe b
mB =
S a b a b -> Tsil ByteArray -> ByteArray -> a -> b -> Maybe c
forall x y.
S x y a b -> Tsil ByteArray -> ByteArray -> x -> y -> Maybe c
f S a b a b
s Tsil ByteArray
b ByteArray
arrA' a
xA b
xB
| Bool
otherwise = Maybe c
forall a. Maybe a
Nothing
in ByteArray -> Maybe c -> Radix1Tree c -> Radix1Tree c
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
retip ByteArray
arrA' Maybe c
mC (S a b a b
-> Tsil ByteArray -> Radix1Tree a -> Radix1Tree b -> Radix1Tree c
forall a b.
S a b a b
-> Tsil ByteArray -> Radix1Tree a -> Radix1Tree b -> Radix1Tree c
anyAny S a b a b
s (Tsil ByteArray -> ByteArray -> Tsil ByteArray
forall a. Tsil a -> a -> Tsil a
Snoc Tsil ByteArray
b ByteArray
arrA') Radix1Tree a
dA Radix1Tree b
dB)
else ByteArray -> Maybe c -> Radix1Tree c -> Radix1Tree c
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
retip ByteArray
arrA' Maybe c
forall a. Maybe a
Nothing (Radix1Tree c -> Radix1Tree c) -> Radix1Tree c -> Radix1Tree c
forall a b. (a -> b) -> a -> b
$
let !(# S b a a b
s' #) = S a b a b -> (# S b a a b #)
forall a b x y. S a b x y -> (# S b a x y #)
other S a b a b
s
in S b a a b
-> Tsil ByteArray
-> (# Prefix, Int, ByteArray, Maybe b, Radix1Tree b #)
-> Radix1Tree b
-> Radix1Tree a
-> Radix1Tree c
forall a b.
S a b a b
-> Tsil ByteArray
-> UTip a
-> Radix1Tree a
-> Radix1Tree b
-> Radix1Tree c
tipAny S b a a b
s' (Tsil ByteArray -> ByteArray -> Tsil ByteArray
forall a. Tsil a -> a -> Tsil a
Snoc Tsil ByteArray
b ByteArray
arrA')
(# Prefix
wB', Int
nB', ByteArray
arrB, Maybe b
mB, Radix1Tree b
dB #) Radix1Tree b
tB Radix1Tree a
dA
else let !nA' :: Int
nA' = Int
nA Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
o
!wA' :: Prefix
wA' = ByteArray -> Int -> Prefix
forall a. Prim a => ByteArray -> Int -> a
indexByteArray ByteArray
arrA Int
nA'
in Prefix -> Prefix -> Int -> Radix1Tree c
go Prefix
wA' Prefix
wB' (Int
o Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1)
| Bool
otherwise = Radix1Tree c
forall a. Radix1Tree a
Nil
binAny
:: forall a b. S a b x y -> Tsil ByteArray
-> UBin a -> Radix1Tree a -> Radix1Tree b -> Radix1Tree c
binAny :: forall a b.
S a b a b
-> Tsil ByteArray
-> UBin a
-> Radix1Tree a
-> Radix1Tree b
-> Radix1Tree c
binAny S a b a b
s Tsil ByteArray
b UBin a
uA Radix1Tree a
tA Radix1Tree b
tB =
case Radix1Tree b
tB of
Bin Prefix
pB Radix1Tree b
lB Radix1Tree b
rB -> S a b a b
-> Tsil ByteArray
-> UBin a
-> Radix1Tree a
-> UBin b
-> Radix1Tree b
-> Radix1Tree c
forall a b.
S a b a b
-> Tsil ByteArray
-> UBin a
-> Radix1Tree a
-> UBin b
-> Radix1Tree b
-> Radix1Tree c
binBin S a b a b
s Tsil ByteArray
b UBin a
uA Radix1Tree a
tA (# Prefix
pB, Radix1Tree b
lB, Radix1Tree b
rB #) Radix1Tree b
tB
Tip ByteArray
arrB Maybe b
mB Radix1Tree b
dB -> let !(# S b a a b
s' #) = S a b a b -> (# S b a a b #)
forall a b x y. S a b x y -> (# S b a x y #)
other S a b a b
s
!wB :: Prefix
wB = ByteArray -> Int -> Prefix
forall a. Prim a => ByteArray -> Int -> a
indexByteArray ByteArray
arrB Int
0
in S b a a b
-> Tsil ByteArray
-> UTip b
-> Radix1Tree b
-> UBin a
-> Radix1Tree c
forall a b.
S a b a b
-> Tsil ByteArray
-> UTip a
-> Radix1Tree a
-> UBin b
-> Radix1Tree c
tipBin S b a a b
s' Tsil ByteArray
b (# Prefix
wB, Int
0, ByteArray
arrB, Maybe b
mB, Radix1Tree b
dB #) Radix1Tree b
tB UBin a
uA
Radix1Tree b
Nil -> Radix1Tree c
forall a. Radix1Tree a
Nil
tipBin
:: forall a b. S a b x y -> Tsil ByteArray
-> UTip a -> Radix1Tree a -> UBin b -> Radix1Tree c
tipBin :: forall a b.
S a b a b
-> Tsil ByteArray
-> UTip a
-> Radix1Tree a
-> UBin b
-> Radix1Tree c
tipBin S a b a b
s Tsil ByteArray
b uA :: UTip a
uA@(# Prefix
wA, Int
_, ByteArray
_, Maybe a
_, Radix1Tree a
_ #) Radix1Tree a
tA (# Prefix
pB, Radix1Tree b
lB, Radix1Tree b
rB #)
| Prefix -> Prefix -> Bool
beyond Prefix
pB Prefix
wA = Radix1Tree c
forall a. Radix1Tree a
Nil
| Bool
otherwise = S a b a b
-> Tsil ByteArray
-> UTip a
-> Radix1Tree a
-> Radix1Tree b
-> Radix1Tree c
forall a b.
S a b a b
-> Tsil ByteArray
-> UTip a
-> Radix1Tree a
-> Radix1Tree b
-> Radix1Tree c
tipAny S a b a b
s Tsil ByteArray
b UTip a
uA Radix1Tree a
tA (Radix1Tree b -> Radix1Tree c) -> Radix1Tree b -> Radix1Tree c
forall a b. (a -> b) -> a -> b
$ if Prefix
wA Prefix -> Prefix -> Bool
forall a. Ord a => a -> a -> Bool
< Prefix
pB
then Radix1Tree b
lB
else Radix1Tree b
rB
binBin
:: forall a b. S a b x y -> Tsil ByteArray
-> UBin a -> Radix1Tree a -> UBin b -> Radix1Tree b -> Radix1Tree c
binBin :: forall a b.
S a b a b
-> Tsil ByteArray
-> UBin a
-> Radix1Tree a
-> UBin b
-> Radix1Tree b
-> Radix1Tree c
binBin S a b a b
s Tsil ByteArray
b uA :: UBin a
uA@(# Prefix
pA, Radix1Tree a
lA, Radix1Tree a
rA #) Radix1Tree a
tA uB :: UBin b
uB@(# Prefix
pB, Radix1Tree b
lB, Radix1Tree b
rB #) Radix1Tree b
tB =
case Prefix -> Prefix -> Ordering
forall a. Ord a => a -> a -> Ordering
Prelude.compare Prefix
pA Prefix
pB of
Ordering
EQ -> Prefix -> Radix1Tree c -> Radix1Tree c -> Radix1Tree c
forall a. Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
rebin Prefix
pA (S a b a b
-> Tsil ByteArray -> Radix1Tree a -> Radix1Tree b -> Radix1Tree c
forall a b.
S a b a b
-> Tsil ByteArray -> Radix1Tree a -> Radix1Tree b -> Radix1Tree c
anyAny S a b a b
s Tsil ByteArray
b Radix1Tree a
lA Radix1Tree b
lB) (S a b a b
-> Tsil ByteArray -> Radix1Tree a -> Radix1Tree b -> Radix1Tree c
forall a b.
S a b a b
-> Tsil ByteArray -> Radix1Tree a -> Radix1Tree b -> Radix1Tree c
anyAny S a b a b
s Tsil ByteArray
b Radix1Tree a
rA Radix1Tree b
rB)
Ordering
LT | Prefix
pB Prefix -> Prefix -> Bool
forall a. Ord a => a -> a -> Bool
<= Prefix -> Prefix
upper Prefix
pA -> let !(# S b a a b
s' #) = S a b a b -> (# S b a a b #)
forall a b x y. S a b x y -> (# S b a x y #)
other S a b a b
s
in S b a a b
-> Tsil ByteArray
-> UBin b
-> Radix1Tree b
-> Radix1Tree a
-> Radix1Tree c
forall a b.
S a b a b
-> Tsil ByteArray
-> UBin a
-> Radix1Tree a
-> Radix1Tree b
-> Radix1Tree c
binAny S b a a b
s' Tsil ByteArray
b UBin b
uB Radix1Tree b
tB Radix1Tree a
rA
| Prefix
pA Prefix -> Prefix -> Bool
forall a. Ord a => a -> a -> Bool
>= Prefix -> Prefix
lower Prefix
pB -> S a b a b
-> Tsil ByteArray
-> UBin a
-> Radix1Tree a
-> Radix1Tree b
-> Radix1Tree c
forall a b.
S a b a b
-> Tsil ByteArray
-> UBin a
-> Radix1Tree a
-> Radix1Tree b
-> Radix1Tree c
binAny S a b a b
s Tsil ByteArray
b UBin a
uA Radix1Tree a
tA Radix1Tree b
lB
| Bool
otherwise -> Radix1Tree c
forall a. Radix1Tree a
Nil
Ordering
GT | Prefix
pA Prefix -> Prefix -> Bool
forall a. Ord a => a -> a -> Bool
<= Prefix -> Prefix
upper Prefix
pB -> S a b a b
-> Tsil ByteArray
-> UBin a
-> Radix1Tree a
-> Radix1Tree b
-> Radix1Tree c
forall a b.
S a b a b
-> Tsil ByteArray
-> UBin a
-> Radix1Tree a
-> Radix1Tree b
-> Radix1Tree c
binAny S a b a b
s Tsil ByteArray
b UBin a
uA Radix1Tree a
tA Radix1Tree b
rB
| Prefix
pB Prefix -> Prefix -> Bool
forall a. Ord a => a -> a -> Bool
>= Prefix -> Prefix
lower Prefix
pA -> let !(# S b a a b
s' #) = S a b a b -> (# S b a a b #)
forall a b x y. S a b x y -> (# S b a x y #)
other S a b a b
s
in S b a a b
-> Tsil ByteArray
-> UBin b
-> Radix1Tree b
-> Radix1Tree a
-> Radix1Tree c
forall a b.
S a b a b
-> Tsil ByteArray
-> UBin a
-> Radix1Tree a
-> Radix1Tree b
-> Radix1Tree c
binAny S b a a b
s' Tsil ByteArray
b UBin b
uB Radix1Tree b
tB Radix1Tree a
lA
| Bool
otherwise -> Radix1Tree c
forall a. Radix1Tree a
Nil
{-# INLINE merge0 #-}
merge0
:: (Build -> a -> b -> Maybe c)
-> (Build -> a -> Maybe c)
-> (Build -> Radix1Tree a -> Radix1Tree c)
-> (Build -> b -> Maybe c)
-> (Build -> Radix1Tree b -> Radix1Tree c)
-> RadixTree a
-> RadixTree b
-> RadixTree c
merge0 :: forall a b c.
(Build -> a -> b -> Maybe c)
-> (Build -> a -> Maybe c)
-> (Build -> Radix1Tree a -> Radix1Tree c)
-> (Build -> b -> Maybe c)
-> (Build -> Radix1Tree b -> Radix1Tree c)
-> RadixTree a
-> RadixTree b
-> RadixTree c
merge0 Build -> a -> b -> Maybe c
f Build -> a -> Maybe c
oneX Build -> Radix1Tree a -> Radix1Tree c
treeX Build -> b -> Maybe c
oneY Build -> Radix1Tree b -> Radix1Tree c
treeY = \(RadixTree Maybe a
mA Radix1Tree a
tA) (RadixTree Maybe b
mB Radix1Tree b
tB) ->
let mC :: Maybe c
mC = case Maybe a
mA of
Just a
xA -> case Maybe b
mB of
Just b
xB -> Build -> a -> b -> Maybe c
f (Tsil ByteArray -> Build
Build Tsil ByteArray
forall a. Tsil a
Lin) a
xA b
xB
Maybe b
Nothing -> Build -> a -> Maybe c
oneX (Tsil ByteArray -> Build
Build Tsil ByteArray
forall a. Tsil a
Lin) a
xA
Maybe a
Nothing -> case Maybe b
mB of
Just b
xB -> Build -> b -> Maybe c
oneY (Tsil ByteArray -> Build
Build Tsil ByteArray
forall a. Tsil a
Lin) b
xB
Maybe b
Nothing -> Maybe c
forall a. Maybe a
Nothing
in Maybe c -> Radix1Tree c -> RadixTree c
forall a. Maybe a -> Radix1Tree a -> RadixTree a
RadixTree Maybe c
mC (Radix1Tree c -> RadixTree c) -> Radix1Tree c -> RadixTree c
forall a b. (a -> b) -> a -> b
$
(Tsil ByteArray -> ByteArray -> a -> b -> Maybe c)
-> (Tsil ByteArray -> ByteArray -> a -> Maybe c)
-> (Build -> Radix1Tree a -> Radix1Tree c)
-> (Tsil ByteArray -> ByteArray -> b -> Maybe c)
-> (Build -> Radix1Tree b -> Radix1Tree c)
-> Radix1Tree a
-> Radix1Tree b
-> Radix1Tree c
forall a b c.
(Tsil ByteArray -> ByteArray -> a -> b -> Maybe c)
-> (Tsil ByteArray -> ByteArray -> a -> Maybe c)
-> (Build -> Radix1Tree a -> Radix1Tree c)
-> (Tsil ByteArray -> ByteArray -> b -> Maybe c)
-> (Build -> Radix1Tree b -> Radix1Tree c)
-> Radix1Tree a
-> Radix1Tree b
-> Radix1Tree c
merge_ (\Tsil ByteArray
b ByteArray
arr -> Build -> a -> b -> Maybe c
f (Tsil ByteArray -> Build
Build (Tsil ByteArray -> Build) -> Tsil ByteArray -> Build
forall a b. (a -> b) -> a -> b
$ Tsil ByteArray -> ByteArray -> Tsil ByteArray
forall a. Tsil a -> a -> Tsil a
Snoc Tsil ByteArray
b ByteArray
arr))
(\Tsil ByteArray
b ByteArray
arr -> Build -> a -> Maybe c
oneX (Tsil ByteArray -> Build
Build (Tsil ByteArray -> Build) -> Tsil ByteArray -> Build
forall a b. (a -> b) -> a -> b
$ Tsil ByteArray -> ByteArray -> Tsil ByteArray
forall a. Tsil a -> a -> Tsil a
Snoc Tsil ByteArray
b ByteArray
arr)) Build -> Radix1Tree a -> Radix1Tree c
treeX
(\Tsil ByteArray
b ByteArray
arr -> Build -> b -> Maybe c
oneY (Tsil ByteArray -> Build
Build (Tsil ByteArray -> Build) -> Tsil ByteArray -> Build
forall a b. (a -> b) -> a -> b
$ Tsil ByteArray -> ByteArray -> Tsil ByteArray
forall a. Tsil a -> a -> Tsil a
Snoc Tsil ByteArray
b ByteArray
arr)) Build -> Radix1Tree b -> Radix1Tree c
treeY
Radix1Tree a
tA Radix1Tree b
tB
{-# INLINE merge1 #-}
merge1
:: (Build1 -> a -> b -> Maybe c)
-> (Build1 -> a -> Maybe c)
-> (Build -> Radix1Tree a -> Radix1Tree c)
-> (Build1 -> b -> Maybe c)
-> (Build -> Radix1Tree b -> Radix1Tree c)
-> Radix1Tree a
-> Radix1Tree b
-> Radix1Tree c
merge1 :: forall a b c.
(Build1 -> a -> b -> Maybe c)
-> (Build1 -> a -> Maybe c)
-> (Build -> Radix1Tree a -> Radix1Tree c)
-> (Build1 -> b -> Maybe c)
-> (Build -> Radix1Tree b -> Radix1Tree c)
-> Radix1Tree a
-> Radix1Tree b
-> Radix1Tree c
merge1 Build1 -> a -> b -> Maybe c
f Build1 -> a -> Maybe c
oneX Build -> Radix1Tree a -> Radix1Tree c
treeX Build1 -> b -> Maybe c
oneY Build -> Radix1Tree b -> Radix1Tree c
treeY =
(Tsil ByteArray -> ByteArray -> a -> b -> Maybe c)
-> (Tsil ByteArray -> ByteArray -> a -> Maybe c)
-> (Build -> Radix1Tree a -> Radix1Tree c)
-> (Tsil ByteArray -> ByteArray -> b -> Maybe c)
-> (Build -> Radix1Tree b -> Radix1Tree c)
-> Radix1Tree a
-> Radix1Tree b
-> Radix1Tree c
forall a b c.
(Tsil ByteArray -> ByteArray -> a -> b -> Maybe c)
-> (Tsil ByteArray -> ByteArray -> a -> Maybe c)
-> (Build -> Radix1Tree a -> Radix1Tree c)
-> (Tsil ByteArray -> ByteArray -> b -> Maybe c)
-> (Build -> Radix1Tree b -> Radix1Tree c)
-> Radix1Tree a
-> Radix1Tree b
-> Radix1Tree c
merge_ (\Tsil ByteArray
b ByteArray
arr -> Build1 -> a -> b -> Maybe c
f (YtpmeNon ByteArray -> Build1
Build1 (YtpmeNon ByteArray -> Build1) -> YtpmeNon ByteArray -> Build1
forall a b. (a -> b) -> a -> b
$ Tsil ByteArray
b Tsil ByteArray -> ByteArray -> YtpmeNon ByteArray
forall a. Tsil a -> a -> YtpmeNon a
:/ ByteArray
arr))
(\Tsil ByteArray
b ByteArray
arr -> Build1 -> a -> Maybe c
oneX (YtpmeNon ByteArray -> Build1
Build1 (YtpmeNon ByteArray -> Build1) -> YtpmeNon ByteArray -> Build1
forall a b. (a -> b) -> a -> b
$ Tsil ByteArray
b Tsil ByteArray -> ByteArray -> YtpmeNon ByteArray
forall a. Tsil a -> a -> YtpmeNon a
:/ ByteArray
arr)) Build -> Radix1Tree a -> Radix1Tree c
treeX
(\Tsil ByteArray
b ByteArray
arr -> Build1 -> b -> Maybe c
oneY (YtpmeNon ByteArray -> Build1
Build1 (YtpmeNon ByteArray -> Build1) -> YtpmeNon ByteArray -> Build1
forall a b. (a -> b) -> a -> b
$ Tsil ByteArray
b Tsil ByteArray -> ByteArray -> YtpmeNon ByteArray
forall a. Tsil a -> a -> YtpmeNon a
:/ ByteArray
arr)) Build -> Radix1Tree b -> Radix1Tree c
treeY
{-# INLINE merge_ #-}
merge_
:: (Tsil ByteArray -> ByteArray -> a -> b -> Maybe c)
-> (Tsil ByteArray -> ByteArray -> a -> Maybe c)
-> (Build -> Radix1Tree a -> Radix1Tree c)
-> (Tsil ByteArray -> ByteArray -> b -> Maybe c)
-> (Build -> Radix1Tree b -> Radix1Tree c)
-> Radix1Tree a
-> Radix1Tree b
-> Radix1Tree c
merge_ :: forall a b c.
(Tsil ByteArray -> ByteArray -> a -> b -> Maybe c)
-> (Tsil ByteArray -> ByteArray -> a -> Maybe c)
-> (Build -> Radix1Tree a -> Radix1Tree c)
-> (Tsil ByteArray -> ByteArray -> b -> Maybe c)
-> (Build -> Radix1Tree b -> Radix1Tree c)
-> Radix1Tree a
-> Radix1Tree b
-> Radix1Tree c
merge_ (Tsil ByteArray -> ByteArray -> a -> b -> Maybe c
f :: Tsil ByteArray -> ByteArray -> x -> y -> Maybe c) Tsil ByteArray -> ByteArray -> a -> Maybe c
oneX Build -> Radix1Tree a -> Radix1Tree c
treeX Tsil ByteArray -> ByteArray -> b -> Maybe c
oneY Build -> Radix1Tree b -> Radix1Tree c
treeY =
S a b a b
-> Tsil ByteArray -> Radix1Tree a -> Radix1Tree b -> Radix1Tree c
forall a b.
S a b a b
-> Tsil ByteArray -> Radix1Tree a -> Radix1Tree b -> Radix1Tree c
anyAny S a b a b
forall a b. S a b a b
L Tsil ByteArray
forall a. Tsil a
Lin
where
sideA :: forall a b. S a b x y -> Tsil ByteArray -> Radix1Tree a -> Radix1Tree c
sideA :: forall a b.
S a b a b -> Tsil ByteArray -> Radix1Tree a -> Radix1Tree c
sideA S a b a b
s Tsil ByteArray
b Radix1Tree a
tA = case S a b a b
s of
S a b a b
L -> Build -> Radix1Tree a -> Radix1Tree c
treeX (Tsil ByteArray -> Build
Build Tsil ByteArray
b) Radix1Tree a
Radix1Tree a
tA
S a b a b
R -> Build -> Radix1Tree b -> Radix1Tree c
treeY (Tsil ByteArray -> Build
Build Tsil ByteArray
b) Radix1Tree b
Radix1Tree a
tA
sideB :: forall a b. S a b x y -> Tsil ByteArray -> Radix1Tree b -> Radix1Tree c
sideB :: forall a b.
S a b a b -> Tsil ByteArray -> Radix1Tree b -> Radix1Tree c
sideB S a b a b
s Tsil ByteArray
b Radix1Tree b
tB = case S a b a b
s of
S a b a b
L -> Build -> Radix1Tree b -> Radix1Tree c
treeY (Tsil ByteArray -> Build
Build Tsil ByteArray
b) Radix1Tree b
Radix1Tree b
tB
S a b a b
R -> Build -> Radix1Tree a -> Radix1Tree c
treeX (Tsil ByteArray -> Build
Build Tsil ByteArray
b) Radix1Tree a
Radix1Tree b
tB
anyAny
:: forall a b. S a b x y -> Tsil ByteArray
-> Radix1Tree a -> Radix1Tree b -> Radix1Tree c
anyAny :: forall a b.
S a b a b
-> Tsil ByteArray -> Radix1Tree a -> Radix1Tree b -> Radix1Tree c
anyAny S a b a b
s Tsil ByteArray
b Radix1Tree a
tA Radix1Tree b
tB =
case Radix1Tree a
tA of
Bin Prefix
pA Radix1Tree a
lA Radix1Tree a
rA -> S a b a b
-> Tsil ByteArray
-> UBin a
-> Radix1Tree a
-> Radix1Tree b
-> Radix1Tree c
forall a b.
S a b a b
-> Tsil ByteArray
-> UBin a
-> Radix1Tree a
-> Radix1Tree b
-> Radix1Tree c
binAny S a b a b
s Tsil ByteArray
b (# Prefix
pA, Radix1Tree a
lA, Radix1Tree a
rA #) Radix1Tree a
tA Radix1Tree b
tB
Tip ByteArray
arrA Maybe a
mA Radix1Tree a
dA -> let !wA :: Prefix
wA = ByteArray -> Int -> Prefix
forall a. Prim a => ByteArray -> Int -> a
indexByteArray ByteArray
arrA Int
0
in S a b a b
-> Tsil ByteArray
-> UTip a
-> Radix1Tree a
-> Radix1Tree b
-> Radix1Tree c
forall a b.
S a b a b
-> Tsil ByteArray
-> UTip a
-> Radix1Tree a
-> Radix1Tree b
-> Radix1Tree c
tipAny S a b a b
s Tsil ByteArray
b (# Prefix
wA, Int
0, ByteArray
arrA, Maybe a
mA, Radix1Tree a
dA #) Radix1Tree a
tA Radix1Tree b
tB
Radix1Tree a
Nil -> S a b a b -> Tsil ByteArray -> Radix1Tree b -> Radix1Tree c
forall a b.
S a b a b -> Tsil ByteArray -> Radix1Tree b -> Radix1Tree c
sideB S a b a b
s Tsil ByteArray
b Radix1Tree b
tB
tipAny
:: forall a b. S a b x y -> Tsil ByteArray
-> UTip a -> Radix1Tree a -> Radix1Tree b -> Radix1Tree c
tipAny :: forall a b.
S a b a b
-> Tsil ByteArray
-> UTip a
-> Radix1Tree a
-> Radix1Tree b
-> Radix1Tree c
tipAny S a b a b
s Tsil ByteArray
b uA :: UTip a
uA@(# Prefix
_, Int
nA, ByteArray
arrA, Maybe a
mA, Radix1Tree a
dA #) Radix1Tree a
tA Radix1Tree b
tB =
case Radix1Tree b
tB of
Bin Prefix
pB Radix1Tree b
lB Radix1Tree b
rB -> S a b a b
-> Tsil ByteArray
-> UTip a
-> Radix1Tree a
-> UBin b
-> Radix1Tree b
-> Radix1Tree c
forall a b.
S a b a b
-> Tsil ByteArray
-> UTip a
-> Radix1Tree a
-> UBin b
-> Radix1Tree b
-> Radix1Tree c
tipBin S a b a b
s Tsil ByteArray
b UTip a
uA Radix1Tree a
tA (# Prefix
pB, Radix1Tree b
lB, Radix1Tree b
rB #) Radix1Tree b
tB
Tip ByteArray
arrB Maybe b
mB Radix1Tree b
dB -> let !wB :: Prefix
wB = ByteArray -> Int -> Prefix
forall a. Prim a => ByteArray -> Int -> a
indexByteArray ByteArray
arrB Int
0
uB :: (# Prefix, Int, ByteArray, Maybe b, Radix1Tree b #)
uB = (# Prefix
wB, Int
0, ByteArray
arrB, Maybe b
mB, Radix1Tree b
dB #)
!lenA :: Int
lenA = ByteArray -> Int
sizeofByteArray ByteArray
arrA Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
nA
!lenB :: Int
lenB = ByteArray -> Int
sizeofByteArray ByteArray
arrB
in if Int
lenB Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
lenA
then S a b a b
-> Tsil ByteArray
-> UTip a
-> Radix1Tree a
-> (# Prefix, Int, ByteArray, Maybe b, Radix1Tree b #)
-> Radix1Tree b
-> Int
-> Radix1Tree c
forall a b.
S a b a b
-> Tsil ByteArray
-> UTip a
-> Radix1Tree a
-> UTip b
-> Radix1Tree b
-> Int
-> Radix1Tree c
tipTip S a b a b
s Tsil ByteArray
b UTip a
uA Radix1Tree a
tA (# Prefix, Int, ByteArray, Maybe b, Radix1Tree b #)
uB Radix1Tree b
tB Int
lenA
else let !(# S b a a b
s' #) = S a b a b -> (# S b a a b #)
forall a b x y. S a b x y -> (# S b a x y #)
other S a b a b
s
in S b a a b
-> Tsil ByteArray
-> (# Prefix, Int, ByteArray, Maybe b, Radix1Tree b #)
-> Radix1Tree b
-> UTip a
-> Radix1Tree a
-> Int
-> Radix1Tree c
forall a b.
S a b a b
-> Tsil ByteArray
-> UTip a
-> Radix1Tree a
-> UTip b
-> Radix1Tree b
-> Int
-> Radix1Tree c
tipTip S b a a b
s' Tsil ByteArray
b (# Prefix, Int, ByteArray, Maybe b, Radix1Tree b #)
uB Radix1Tree b
tB UTip a
uA Radix1Tree a
tA Int
lenB
Radix1Tree b
Nil -> S a b a b -> Tsil ByteArray -> Radix1Tree a -> Radix1Tree c
forall a b.
S a b a b -> Tsil ByteArray -> Radix1Tree a -> Radix1Tree c
sideA S a b a b
s Tsil ByteArray
b (Radix1Tree a -> Radix1Tree c) -> Radix1Tree a -> Radix1Tree c
forall a b. (a -> b) -> a -> b
$ if Int
nA Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
0
then Radix1Tree a
tA
else ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
Tip (Int -> ByteArray -> ByteArray
dropByteArray Int
nA ByteArray
arrA) Maybe a
mA Radix1Tree a
dA
tipTip
:: forall a b. S a b x y -> Tsil ByteArray
-> UTip a -> Radix1Tree a -> UTip b -> Radix1Tree b -> Int -> Radix1Tree c
tipTip :: forall a b.
S a b a b
-> Tsil ByteArray
-> UTip a
-> Radix1Tree a
-> UTip b
-> Radix1Tree b
-> Int
-> Radix1Tree c
tipTip S a b a b
s Tsil ByteArray
b (# Prefix
wA0, Int
nA, ByteArray
arrA, Maybe a
mA, Radix1Tree a
dA #) Radix1Tree a
tA (# Prefix
wB0, Int
nB, ByteArray
arrB, Maybe b
mB, Radix1Tree b
dB #) Radix1Tree b
tB Int
len =
Prefix -> Prefix -> Int -> Radix1Tree c
go Prefix
wA0 Prefix
wB0 Int
1
where
go :: Prefix -> Prefix -> Int -> Radix1Tree c
go Prefix
wA Prefix
wB !Int
o
| Prefix
wA Prefix -> Prefix -> Bool
forall a. Eq a => a -> a -> Bool
== Prefix
wB =
let !nB' :: Int
nB' = Int
nB Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
o
!wB' :: Prefix
wB' = ByteArray -> Int -> Prefix
forall a. Prim a => ByteArray -> Int -> a
indexByteArray ByteArray
arrB Int
nB'
in if Int
o Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
len
then let !arrA' :: ByteArray
arrA' | Int
nA Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
0 = ByteArray
arrA
| Bool
otherwise = Int -> ByteArray -> ByteArray
dropByteArray Int
nA ByteArray
arrA
in if Int
nB' Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== ByteArray -> Int
sizeofByteArray ByteArray
arrB
then let mC :: Maybe c
mC = case Maybe a
mA of
Just a
xA ->
case Maybe b
mB of
Just b
xB -> case S a b a b
s of
S a b a b
L -> Tsil ByteArray -> ByteArray -> a -> b -> Maybe c
f Tsil ByteArray
b ByteArray
arrA' a
a
xA b
b
xB
S a b a b
R -> Tsil ByteArray -> ByteArray -> a -> b -> Maybe c
f Tsil ByteArray
b ByteArray
arrA' a
b
xB b
a
xA
Maybe b
Nothing -> case S a b a b
s of
S a b a b
L -> Tsil ByteArray -> ByteArray -> a -> Maybe c
oneX Tsil ByteArray
b ByteArray
arrA' a
a
xA
S a b a b
R -> Tsil ByteArray -> ByteArray -> b -> Maybe c
oneY Tsil ByteArray
b ByteArray
arrA' b
a
xA
Maybe a
Nothing ->
case Maybe b
mB of
Just b
xB -> case S a b a b
s of
S a b a b
L -> Tsil ByteArray -> ByteArray -> b -> Maybe c
oneY Tsil ByteArray
b ByteArray
arrA' b
b
xB
S a b a b
R -> Tsil ByteArray -> ByteArray -> a -> Maybe c
oneX Tsil ByteArray
b ByteArray
arrA' a
b
xB
Maybe b
Nothing -> Maybe c
forall a. Maybe a
Nothing
in ByteArray -> Maybe c -> Radix1Tree c -> Radix1Tree c
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
retip ByteArray
arrA' Maybe c
mC (S a b a b
-> Tsil ByteArray -> Radix1Tree a -> Radix1Tree b -> Radix1Tree c
forall a b.
S a b a b
-> Tsil ByteArray -> Radix1Tree a -> Radix1Tree b -> Radix1Tree c
anyAny S a b a b
s (Tsil ByteArray -> ByteArray -> Tsil ByteArray
forall a. Tsil a -> a -> Tsil a
Snoc Tsil ByteArray
b ByteArray
arrA') Radix1Tree a
dA Radix1Tree b
dB)
else let mC :: Maybe c
mC = case Maybe a
mA of
Just a
xA -> case S a b a b
s of
S a b a b
L -> Tsil ByteArray -> ByteArray -> a -> Maybe c
oneX Tsil ByteArray
b ByteArray
arrA' a
a
xA
S a b a b
R -> Tsil ByteArray -> ByteArray -> b -> Maybe c
oneY Tsil ByteArray
b ByteArray
arrA' b
a
xA
Maybe a
Nothing -> Maybe c
forall a. Maybe a
Nothing
in ByteArray -> Maybe c -> Radix1Tree c -> Radix1Tree c
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
retip ByteArray
arrA' Maybe c
mC (Radix1Tree c -> Radix1Tree c) -> Radix1Tree c -> Radix1Tree c
forall a b. (a -> b) -> a -> b
$
let !(# S b a a b
s' #) = S a b a b -> (# S b a a b #)
forall a b x y. S a b x y -> (# S b a x y #)
other S a b a b
s
in S b a a b
-> Tsil ByteArray
-> (# Prefix, Int, ByteArray, Maybe b, Radix1Tree b #)
-> Radix1Tree b
-> Radix1Tree a
-> Radix1Tree c
forall a b.
S a b a b
-> Tsil ByteArray
-> UTip a
-> Radix1Tree a
-> Radix1Tree b
-> Radix1Tree c
tipAny S b a a b
s' (Tsil ByteArray -> ByteArray -> Tsil ByteArray
forall a. Tsil a -> a -> Tsil a
Snoc Tsil ByteArray
b ByteArray
arrA')
(# Prefix
wB', Int
nB', ByteArray
arrB, Maybe b
mB, Radix1Tree b
dB #) Radix1Tree b
tB Radix1Tree a
dA
else let !nA' :: Int
nA' = Int
nA Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
o
!wA' :: Prefix
wA' = ByteArray -> Int -> Prefix
forall a. Prim a => ByteArray -> Int -> a
indexByteArray ByteArray
arrA Int
nA'
in Prefix -> Prefix -> Int -> Radix1Tree c
go Prefix
wA' Prefix
wB' (Int
o Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1)
| Int
o Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
1 =
Prefix -> Radix1Tree c -> Prefix -> Radix1Tree c -> Radix1Tree c
forall a.
Prefix -> Radix1Tree a -> Prefix -> Radix1Tree a -> Radix1Tree a
safeJoin Prefix
wA ( S a b a b -> Tsil ByteArray -> Radix1Tree a -> Radix1Tree c
forall a b.
S a b a b -> Tsil ByteArray -> Radix1Tree a -> Radix1Tree c
sideA S a b a b
s Tsil ByteArray
b (Radix1Tree a -> Radix1Tree c) -> Radix1Tree a -> Radix1Tree c
forall a b. (a -> b) -> a -> b
$ if Int
nA Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
0
then Radix1Tree a
tA
else ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
Tip (Int -> ByteArray -> ByteArray
dropByteArray Int
nA ByteArray
arrA) Maybe a
mA Radix1Tree a
dA
)
Prefix
wB ( S a b a b -> Tsil ByteArray -> Radix1Tree b -> Radix1Tree c
forall a b.
S a b a b -> Tsil ByteArray -> Radix1Tree b -> Radix1Tree c
sideB S a b a b
s Tsil ByteArray
b (Radix1Tree b -> Radix1Tree c) -> Radix1Tree b -> Radix1Tree c
forall a b. (a -> b) -> a -> b
$ if Int
nB Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
0
then Radix1Tree b
tB
else ByteArray -> Maybe b -> Radix1Tree b -> Radix1Tree b
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
Tip (Int -> ByteArray -> ByteArray
dropByteArray Int
nB ByteArray
arrB) Maybe b
mB Radix1Tree b
dB
)
| Bool
otherwise =
let !o' :: Int
o' = Int
o Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1
!(# !ByteArray
arrC, !ByteArray
arrA' #) = Int -> Int -> ByteArray -> (# ByteArray, ByteArray #)
splitByteArray Int
nA Int
o' ByteArray
arrA
!arrB' :: ByteArray
arrB' = Int -> ByteArray -> ByteArray
dropByteArray (Int
nB Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
o') ByteArray
arrB
in ByteArray -> Maybe c -> Radix1Tree c -> Radix1Tree c
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
retip ByteArray
arrC Maybe c
forall a. Maybe a
Nothing (Radix1Tree c -> Radix1Tree c) -> Radix1Tree c -> Radix1Tree c
forall a b. (a -> b) -> a -> b
$ Prefix -> Radix1Tree c -> Prefix -> Radix1Tree c -> Radix1Tree c
forall a.
Prefix -> Radix1Tree a -> Prefix -> Radix1Tree a -> Radix1Tree a
safeJoin Prefix
wA (S a b a b -> Tsil ByteArray -> Radix1Tree a -> Radix1Tree c
forall a b.
S a b a b -> Tsil ByteArray -> Radix1Tree a -> Radix1Tree c
sideA S a b a b
s Tsil ByteArray
b (Radix1Tree a -> Radix1Tree c) -> Radix1Tree a -> Radix1Tree c
forall a b. (a -> b) -> a -> b
$ ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
Tip ByteArray
arrA' Maybe a
mA Radix1Tree a
dA)
Prefix
wB (S a b a b -> Tsil ByteArray -> Radix1Tree b -> Radix1Tree c
forall a b.
S a b a b -> Tsil ByteArray -> Radix1Tree b -> Radix1Tree c
sideB S a b a b
s Tsil ByteArray
b (Radix1Tree b -> Radix1Tree c) -> Radix1Tree b -> Radix1Tree c
forall a b. (a -> b) -> a -> b
$ ByteArray -> Maybe b -> Radix1Tree b -> Radix1Tree b
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
Tip ByteArray
arrB' Maybe b
mB Radix1Tree b
dB)
binAny
:: forall a b. S a b x y -> Tsil ByteArray
-> UBin a -> Radix1Tree a -> Radix1Tree b -> Radix1Tree c
binAny :: forall a b.
S a b a b
-> Tsil ByteArray
-> UBin a
-> Radix1Tree a
-> Radix1Tree b
-> Radix1Tree c
binAny S a b a b
s Tsil ByteArray
b UBin a
uA Radix1Tree a
tA Radix1Tree b
tB =
case Radix1Tree b
tB of
Bin Prefix
pB Radix1Tree b
lB Radix1Tree b
rB -> S a b a b
-> Tsil ByteArray
-> UBin a
-> Radix1Tree a
-> UBin b
-> Radix1Tree b
-> Radix1Tree c
forall a b.
S a b a b
-> Tsil ByteArray
-> UBin a
-> Radix1Tree a
-> UBin b
-> Radix1Tree b
-> Radix1Tree c
binBin S a b a b
s Tsil ByteArray
b UBin a
uA Radix1Tree a
tA (# Prefix
pB, Radix1Tree b
lB, Radix1Tree b
rB #) Radix1Tree b
tB
Tip ByteArray
arrB Maybe b
mB Radix1Tree b
dB -> let !(# S b a a b
s' #) = S a b a b -> (# S b a a b #)
forall a b x y. S a b x y -> (# S b a x y #)
other S a b a b
s
!wB :: Prefix
wB = ByteArray -> Int -> Prefix
forall a. Prim a => ByteArray -> Int -> a
indexByteArray ByteArray
arrB Int
0
in S b a a b
-> Tsil ByteArray
-> UTip b
-> Radix1Tree b
-> UBin a
-> Radix1Tree a
-> Radix1Tree c
forall a b.
S a b a b
-> Tsil ByteArray
-> UTip a
-> Radix1Tree a
-> UBin b
-> Radix1Tree b
-> Radix1Tree c
tipBin S b a a b
s' Tsil ByteArray
b (# Prefix
wB, Int
0, ByteArray
arrB, Maybe b
mB, Radix1Tree b
dB #) Radix1Tree b
tB UBin a
uA Radix1Tree a
tA
Radix1Tree b
Nil -> S a b a b -> Tsil ByteArray -> Radix1Tree a -> Radix1Tree c
forall a b.
S a b a b -> Tsil ByteArray -> Radix1Tree a -> Radix1Tree c
sideA S a b a b
s Tsil ByteArray
b Radix1Tree a
tA
tipBin
:: forall a b. S a b x y -> Tsil ByteArray
-> UTip a -> Radix1Tree a -> UBin b -> Radix1Tree b -> Radix1Tree c
tipBin :: forall a b.
S a b a b
-> Tsil ByteArray
-> UTip a
-> Radix1Tree a
-> UBin b
-> Radix1Tree b
-> Radix1Tree c
tipBin S a b a b
s Tsil ByteArray
b uA :: UTip a
uA@(# Prefix
wA, Int
nA, ByteArray
arrA, Maybe a
mA, Radix1Tree a
dA #) Radix1Tree a
tA (# Prefix
pB, Radix1Tree b
lB, Radix1Tree b
rB #) Radix1Tree b
tB
| Prefix -> Prefix -> Bool
beyond Prefix
pB Prefix
wA = Prefix -> Radix1Tree c -> Prefix -> Radix1Tree c -> Radix1Tree c
forall a.
Prefix -> Radix1Tree a -> Prefix -> Radix1Tree a -> Radix1Tree a
safeJoin Prefix
wA (S a b a b -> Tsil ByteArray -> Radix1Tree a -> Radix1Tree c
forall a b.
S a b a b -> Tsil ByteArray -> Radix1Tree a -> Radix1Tree c
sideA S a b a b
s Tsil ByteArray
b (Radix1Tree a -> Radix1Tree c) -> Radix1Tree a -> Radix1Tree c
forall a b. (a -> b) -> a -> b
$ if Int
nA Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
0
then Radix1Tree a
tA
else ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
Tip (Int -> ByteArray -> ByteArray
dropByteArray Int
nA ByteArray
arrA) Maybe a
mA Radix1Tree a
dA
)
Prefix
pB (S a b a b -> Tsil ByteArray -> Radix1Tree b -> Radix1Tree c
forall a b.
S a b a b -> Tsil ByteArray -> Radix1Tree b -> Radix1Tree c
sideB S a b a b
s Tsil ByteArray
b Radix1Tree b
tB)
| Prefix
wA Prefix -> Prefix -> Bool
forall a. Ord a => a -> a -> Bool
< Prefix
pB = Prefix -> Radix1Tree c -> Radix1Tree c -> Radix1Tree c
forall a. Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
rebin Prefix
pB (S a b a b
-> Tsil ByteArray
-> UTip a
-> Radix1Tree a
-> Radix1Tree b
-> Radix1Tree c
forall a b.
S a b a b
-> Tsil ByteArray
-> UTip a
-> Radix1Tree a
-> Radix1Tree b
-> Radix1Tree c
tipAny S a b a b
s Tsil ByteArray
b UTip a
uA Radix1Tree a
tA Radix1Tree b
lB) (S a b a b -> Tsil ByteArray -> Radix1Tree b -> Radix1Tree c
forall a b.
S a b a b -> Tsil ByteArray -> Radix1Tree b -> Radix1Tree c
sideB S a b a b
s Tsil ByteArray
b Radix1Tree b
rB)
| Bool
otherwise = Prefix -> Radix1Tree c -> Radix1Tree c -> Radix1Tree c
forall a. Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
rebin Prefix
pB (S a b a b -> Tsil ByteArray -> Radix1Tree b -> Radix1Tree c
forall a b.
S a b a b -> Tsil ByteArray -> Radix1Tree b -> Radix1Tree c
sideB S a b a b
s Tsil ByteArray
b Radix1Tree b
lB) (S a b a b
-> Tsil ByteArray
-> UTip a
-> Radix1Tree a
-> Radix1Tree b
-> Radix1Tree c
forall a b.
S a b a b
-> Tsil ByteArray
-> UTip a
-> Radix1Tree a
-> Radix1Tree b
-> Radix1Tree c
tipAny S a b a b
s Tsil ByteArray
b UTip a
uA Radix1Tree a
tA Radix1Tree b
rB)
binBin
:: forall a b. S a b x y -> Tsil ByteArray
-> UBin a -> Radix1Tree a -> UBin b -> Radix1Tree b -> Radix1Tree c
binBin :: forall a b.
S a b a b
-> Tsil ByteArray
-> UBin a
-> Radix1Tree a
-> UBin b
-> Radix1Tree b
-> Radix1Tree c
binBin S a b a b
s Tsil ByteArray
b uA :: UBin a
uA@(# Prefix
pA, Radix1Tree a
lA, Radix1Tree a
rA #) Radix1Tree a
tA uB :: UBin b
uB@(# Prefix
pB, Radix1Tree b
lB, Radix1Tree b
rB #) Radix1Tree b
tB =
let {-# NOINLINE no #-}
no :: Radix1Tree c
no = Prefix -> Radix1Tree c -> Prefix -> Radix1Tree c -> Radix1Tree c
forall a.
Prefix -> Radix1Tree a -> Prefix -> Radix1Tree a -> Radix1Tree a
safeJoin Prefix
pA (S a b a b -> Tsil ByteArray -> Radix1Tree a -> Radix1Tree c
forall a b.
S a b a b -> Tsil ByteArray -> Radix1Tree a -> Radix1Tree c
sideA S a b a b
s Tsil ByteArray
b Radix1Tree a
tA) Prefix
pB (S a b a b -> Tsil ByteArray -> Radix1Tree b -> Radix1Tree c
forall a b.
S a b a b -> Tsil ByteArray -> Radix1Tree b -> Radix1Tree c
sideB S a b a b
s Tsil ByteArray
b Radix1Tree b
tB)
in case Prefix -> Prefix -> Ordering
forall a. Ord a => a -> a -> Ordering
Prelude.compare Prefix
pA Prefix
pB of
Ordering
EQ -> Prefix -> Radix1Tree c -> Radix1Tree c -> Radix1Tree c
forall a. Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
rebin Prefix
pA (S a b a b
-> Tsil ByteArray -> Radix1Tree a -> Radix1Tree b -> Radix1Tree c
forall a b.
S a b a b
-> Tsil ByteArray -> Radix1Tree a -> Radix1Tree b -> Radix1Tree c
anyAny S a b a b
s Tsil ByteArray
b Radix1Tree a
lA Radix1Tree b
lB) (S a b a b
-> Tsil ByteArray -> Radix1Tree a -> Radix1Tree b -> Radix1Tree c
forall a b.
S a b a b
-> Tsil ByteArray -> Radix1Tree a -> Radix1Tree b -> Radix1Tree c
anyAny S a b a b
s Tsil ByteArray
b Radix1Tree a
rA Radix1Tree b
rB)
Ordering
LT | Prefix
pB Prefix -> Prefix -> Bool
forall a. Ord a => a -> a -> Bool
<= Prefix -> Prefix
upper Prefix
pA -> let !(# S b a a b
s' #) = S a b a b -> (# S b a a b #)
forall a b x y. S a b x y -> (# S b a x y #)
other S a b a b
s
in Prefix -> Radix1Tree c -> Radix1Tree c -> Radix1Tree c
forall a. Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
rebin Prefix
pA (S a b a b -> Tsil ByteArray -> Radix1Tree a -> Radix1Tree c
forall a b.
S a b a b -> Tsil ByteArray -> Radix1Tree a -> Radix1Tree c
sideA S a b a b
s Tsil ByteArray
b Radix1Tree a
lA) (S b a a b
-> Tsil ByteArray
-> UBin b
-> Radix1Tree b
-> Radix1Tree a
-> Radix1Tree c
forall a b.
S a b a b
-> Tsil ByteArray
-> UBin a
-> Radix1Tree a
-> Radix1Tree b
-> Radix1Tree c
binAny S b a a b
s' Tsil ByteArray
b UBin b
uB Radix1Tree b
tB Radix1Tree a
rA)
| Prefix
pA Prefix -> Prefix -> Bool
forall a. Ord a => a -> a -> Bool
>= Prefix -> Prefix
lower Prefix
pB -> Prefix -> Radix1Tree c -> Radix1Tree c -> Radix1Tree c
forall a. Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
rebin Prefix
pB (S a b a b
-> Tsil ByteArray
-> UBin a
-> Radix1Tree a
-> Radix1Tree b
-> Radix1Tree c
forall a b.
S a b a b
-> Tsil ByteArray
-> UBin a
-> Radix1Tree a
-> Radix1Tree b
-> Radix1Tree c
binAny S a b a b
s Tsil ByteArray
b UBin a
uA Radix1Tree a
tA Radix1Tree b
lB) (S a b a b -> Tsil ByteArray -> Radix1Tree b -> Radix1Tree c
forall a b.
S a b a b -> Tsil ByteArray -> Radix1Tree b -> Radix1Tree c
sideB S a b a b
s Tsil ByteArray
b Radix1Tree b
rB)
| Bool
otherwise -> Radix1Tree c
no
Ordering
GT | Prefix
pA Prefix -> Prefix -> Bool
forall a. Ord a => a -> a -> Bool
<= Prefix -> Prefix
upper Prefix
pB -> Prefix -> Radix1Tree c -> Radix1Tree c -> Radix1Tree c
forall a. Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
rebin Prefix
pB (S a b a b -> Tsil ByteArray -> Radix1Tree b -> Radix1Tree c
forall a b.
S a b a b -> Tsil ByteArray -> Radix1Tree b -> Radix1Tree c
sideB S a b a b
s Tsil ByteArray
b Radix1Tree b
lB) (S a b a b
-> Tsil ByteArray
-> UBin a
-> Radix1Tree a
-> Radix1Tree b
-> Radix1Tree c
forall a b.
S a b a b
-> Tsil ByteArray
-> UBin a
-> Radix1Tree a
-> Radix1Tree b
-> Radix1Tree c
binAny S a b a b
s Tsil ByteArray
b UBin a
uA Radix1Tree a
tA Radix1Tree b
rB)
| Prefix
pB Prefix -> Prefix -> Bool
forall a. Ord a => a -> a -> Bool
>= Prefix -> Prefix
lower Prefix
pA -> let !(# S b a a b
s' #) = S a b a b -> (# S b a a b #)
forall a b x y. S a b x y -> (# S b a x y #)
other S a b a b
s
in Prefix -> Radix1Tree c -> Radix1Tree c -> Radix1Tree c
forall a. Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
rebin Prefix
pA (S b a a b
-> Tsil ByteArray
-> UBin b
-> Radix1Tree b
-> Radix1Tree a
-> Radix1Tree c
forall a b.
S a b a b
-> Tsil ByteArray
-> UBin a
-> Radix1Tree a
-> Radix1Tree b
-> Radix1Tree c
binAny S b a a b
s' Tsil ByteArray
b UBin b
uB Radix1Tree b
tB Radix1Tree a
lA) (S a b a b -> Tsil ByteArray -> Radix1Tree a -> Radix1Tree c
forall a b.
S a b a b -> Tsil ByteArray -> Radix1Tree a -> Radix1Tree c
sideA S a b a b
s Tsil ByteArray
b Radix1Tree a
rA)
| Bool
otherwise -> Radix1Tree c
no
{-# INLINE insert0 #-}
insert0 :: Feed -> a -> RadixTree a -> RadixTree a
insert0 :: forall a. Feed -> a -> RadixTree a -> RadixTree a
insert0 (Feed forall a. (forall x. (x -> Step Prefix x) -> x -> a) -> a
feed) a
a = \(RadixTree Maybe a
mx Radix1Tree a
t) ->
(forall x. (x -> Step Prefix x) -> x -> RadixTree a) -> RadixTree a
forall a. (forall x. (x -> Step Prefix x) -> x -> a) -> a
feed ((forall x. (x -> Step Prefix x) -> x -> RadixTree a)
-> RadixTree a)
-> (forall x. (x -> Step Prefix x) -> x -> RadixTree a)
-> RadixTree a
forall a b. (a -> b) -> a -> b
$ \x -> Step Prefix x
step x
s ->
case x -> Step Prefix x
step x
s of
More Prefix
w x
z -> Maybe a -> Radix1Tree a -> RadixTree a
forall a. Maybe a -> Radix1Tree a -> RadixTree a
RadixTree Maybe a
mx (Radix1Tree a -> RadixTree a) -> Radix1Tree a -> RadixTree a
forall a b. (a -> b) -> a -> b
$ a
-> (x -> Step Prefix x)
-> Prefix
-> x
-> Radix1Tree a
-> Radix1Tree a
forall a x.
a
-> (x -> Step Prefix x)
-> Prefix
-> x
-> Radix1Tree a
-> Radix1Tree a
insert_ a
a x -> Step Prefix x
step Prefix
w x
z Radix1Tree a
t
Step Prefix x
Done -> Maybe a -> Radix1Tree a -> RadixTree a
forall a. Maybe a -> Radix1Tree a -> RadixTree a
RadixTree (a -> Maybe a
forall a. a -> Maybe a
Just a
a) Radix1Tree a
t
{-# INLINE insert1 #-}
insert1 :: Feed1 -> a -> Radix1Tree a -> Radix1Tree a
insert1 :: forall a. Feed1 -> a -> Radix1Tree a -> Radix1Tree a
insert1 (Feed1 Prefix
w forall a. (forall x. (x -> Step Prefix x) -> x -> a) -> a
feed) a
a =
(forall x.
(x -> Step Prefix x) -> x -> Radix1Tree a -> Radix1Tree a)
-> Radix1Tree a -> Radix1Tree a
forall a. (forall x. (x -> Step Prefix x) -> x -> a) -> a
feed ((forall x.
(x -> Step Prefix x) -> x -> Radix1Tree a -> Radix1Tree a)
-> Radix1Tree a -> Radix1Tree a)
-> (forall x.
(x -> Step Prefix x) -> x -> Radix1Tree a -> Radix1Tree a)
-> Radix1Tree a
-> Radix1Tree a
forall a b. (a -> b) -> a -> b
$ \x -> Step Prefix x
step -> a
-> (x -> Step Prefix x)
-> Prefix
-> x
-> Radix1Tree a
-> Radix1Tree a
forall a x.
a
-> (x -> Step Prefix x)
-> Prefix
-> x
-> Radix1Tree a
-> Radix1Tree a
insert_ a
a x -> Step Prefix x
step Prefix
w
{-# INLINE insert_ #-}
insert_ :: a -> (x -> Step Word8 x) -> Word8 -> x -> Radix1Tree a -> Radix1Tree a
insert_ :: forall a x.
a
-> (x -> Step Prefix x)
-> Prefix
-> x
-> Radix1Tree a
-> Radix1Tree a
insert_ a
a x -> Step Prefix x
step = Prefix -> x -> Radix1Tree a -> Radix1Tree a
go
where
go :: Prefix -> x -> Radix1Tree a -> Radix1Tree a
go Prefix
w x
s Radix1Tree a
t =
case Radix1Tree a
t of
Bin Prefix
p Radix1Tree a
l Radix1Tree a
r
| Prefix -> Prefix -> Bool
beyond Prefix
p Prefix
w -> Prefix -> Radix1Tree a -> Prefix -> Radix1Tree a -> Radix1Tree a
forall a.
Prefix -> Radix1Tree a -> Prefix -> Radix1Tree a -> Radix1Tree a
join
Prefix
w ((x -> Step Prefix x) -> Prefix -> x -> a -> Radix1Tree a
forall b a.
(b -> Step Prefix b) -> Prefix -> b -> a -> Radix1Tree a
singleton_ x -> Step Prefix x
step Prefix
w x
s a
a)
Prefix
p Radix1Tree a
t
| Prefix
w Prefix -> Prefix -> Bool
forall a. Ord a => a -> a -> Bool
< Prefix
p -> Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
forall a. Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
Bin Prefix
p (Prefix -> x -> Radix1Tree a -> Radix1Tree a
go Prefix
w x
s Radix1Tree a
l) Radix1Tree a
r
| Bool
otherwise -> Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
forall a. Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
Bin Prefix
p Radix1Tree a
l (Prefix -> x -> Radix1Tree a -> Radix1Tree a
go Prefix
w x
s Radix1Tree a
r)
Tip ByteArray
arr Maybe a
mx Radix1Tree a
dx -> Prefix -> x -> Int -> Radix1Tree a
goarr Prefix
w x
s Int
0
where
goarr :: Prefix -> x -> Int -> Radix1Tree a
goarr Prefix
v x
z Int
n
| Prefix
v Prefix -> Prefix -> Bool
forall a. Eq a => a -> a -> Bool
== ByteArray -> Int -> Prefix
forall a. Prim a => ByteArray -> Int -> a
indexByteArray ByteArray
arr Int
n =
if Int
n Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1 Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= ByteArray -> Int
sizeofByteArray ByteArray
arr
then case x -> Step Prefix x
step x
z of
More Prefix
u x
z' -> ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
Tip ByteArray
arr Maybe a
mx (Prefix -> x -> Radix1Tree a -> Radix1Tree a
go Prefix
u x
z' Radix1Tree a
dx)
Step Prefix x
Done -> ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
Tip ByteArray
arr (a -> Maybe a
forall a. a -> Maybe a
Just a
a) Radix1Tree a
dx
else case x -> Step Prefix x
step x
z of
More Prefix
u x
z' -> Prefix -> x -> Int -> Radix1Tree a
goarr Prefix
u x
z' (Int
n Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1)
Step Prefix x
Done ->
let !(# !ByteArray
brr, !ByteArray
crr #) = Int -> Int -> ByteArray -> (# ByteArray, ByteArray #)
splitByteArray Int
0 (Int
n Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1) ByteArray
arr
in ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
Tip ByteArray
brr (a -> Maybe a
forall a. a -> Maybe a
Just a
a) (ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
Tip ByteArray
crr Maybe a
mx Radix1Tree a
dx)
| Int
n Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
0 =
Prefix -> Radix1Tree a -> Prefix -> Radix1Tree a -> Radix1Tree a
forall a.
Prefix -> Radix1Tree a -> Prefix -> Radix1Tree a -> Radix1Tree a
join
(ByteArray -> Int -> Prefix
forall a. Prim a => ByteArray -> Int -> a
indexByteArray ByteArray
arr Int
0) Radix1Tree a
t
Prefix
w ((x -> Step Prefix x) -> Prefix -> x -> a -> Radix1Tree a
forall b a.
(b -> Step Prefix b) -> Prefix -> b -> a -> Radix1Tree a
singleton_ x -> Step Prefix x
step Prefix
w x
s a
a)
| Bool
otherwise =
let !(# !ByteArray
brr, !ByteArray
crr #) = Int -> Int -> ByteArray -> (# ByteArray, ByteArray #)
splitByteArray Int
0 Int
n ByteArray
arr
in ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
Tip ByteArray
brr Maybe a
forall a. Maybe a
Nothing (Radix1Tree a -> Radix1Tree a) -> Radix1Tree a -> Radix1Tree a
forall a b. (a -> b) -> a -> b
$
Prefix -> Radix1Tree a -> Prefix -> Radix1Tree a -> Radix1Tree a
forall a.
Prefix -> Radix1Tree a -> Prefix -> Radix1Tree a -> Radix1Tree a
join
(ByteArray -> Int -> Prefix
forall a. Prim a => ByteArray -> Int -> a
indexByteArray ByteArray
crr Int
0) (ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
Tip ByteArray
crr Maybe a
mx Radix1Tree a
dx)
Prefix
v ((x -> Step Prefix x) -> Prefix -> x -> a -> Radix1Tree a
forall b a.
(b -> Step Prefix b) -> Prefix -> b -> a -> Radix1Tree a
singleton_ x -> Step Prefix x
step Prefix
v x
z a
a)
Radix1Tree a
Nil -> (x -> Step Prefix x) -> Prefix -> x -> a -> Radix1Tree a
forall b a.
(b -> Step Prefix b) -> Prefix -> b -> a -> Radix1Tree a
singleton_ x -> Step Prefix x
step Prefix
w x
s a
a
{-# INLINE insertWith0 #-}
insertWith0 :: (a -> a) -> Feed -> a -> RadixTree a -> RadixTree a
insertWith0 :: forall a. (a -> a) -> Feed -> a -> RadixTree a -> RadixTree a
insertWith0 a -> a
f (Feed forall a. (forall x. (x -> Step Prefix x) -> x -> a) -> a
feed) a
a = \(RadixTree Maybe a
mx Radix1Tree a
t) ->
(forall x. (x -> Step Prefix x) -> x -> RadixTree a) -> RadixTree a
forall a. (forall x. (x -> Step Prefix x) -> x -> a) -> a
feed ((forall x. (x -> Step Prefix x) -> x -> RadixTree a)
-> RadixTree a)
-> (forall x. (x -> Step Prefix x) -> x -> RadixTree a)
-> RadixTree a
forall a b. (a -> b) -> a -> b
$ \x -> Step Prefix x
step x
s ->
case x -> Step Prefix x
step x
s of
More Prefix
w x
z -> Maybe a -> Radix1Tree a -> RadixTree a
forall a. Maybe a -> Radix1Tree a -> RadixTree a
RadixTree Maybe a
mx (Radix1Tree a -> RadixTree a) -> Radix1Tree a -> RadixTree a
forall a b. (a -> b) -> a -> b
$ (a -> a)
-> a
-> (x -> Step Prefix x)
-> Prefix
-> x
-> Radix1Tree a
-> Radix1Tree a
forall a x.
(a -> a)
-> a
-> (x -> Step Prefix x)
-> Prefix
-> x
-> Radix1Tree a
-> Radix1Tree a
insertWith_ a -> a
f a
a x -> Step Prefix x
step Prefix
w x
z Radix1Tree a
t
Step Prefix x
Done ->
let y :: a
y = case Maybe a
mx of
Just a
x -> a -> a
f a
x
Maybe a
Nothing -> a
a
in Maybe a -> Radix1Tree a -> RadixTree a
forall a. Maybe a -> Radix1Tree a -> RadixTree a
RadixTree (a -> Maybe a
forall a. a -> Maybe a
Just a
y) Radix1Tree a
t
{-# INLINE insertWith1 #-}
insertWith1 :: (a -> a) -> Feed1 -> a -> Radix1Tree a -> Radix1Tree a
insertWith1 :: forall a. (a -> a) -> Feed1 -> a -> Radix1Tree a -> Radix1Tree a
insertWith1 a -> a
f (Feed1 Prefix
w forall a. (forall x. (x -> Step Prefix x) -> x -> a) -> a
feed) a
a =
(forall x.
(x -> Step Prefix x) -> x -> Radix1Tree a -> Radix1Tree a)
-> Radix1Tree a -> Radix1Tree a
forall a. (forall x. (x -> Step Prefix x) -> x -> a) -> a
feed ((forall x.
(x -> Step Prefix x) -> x -> Radix1Tree a -> Radix1Tree a)
-> Radix1Tree a -> Radix1Tree a)
-> (forall x.
(x -> Step Prefix x) -> x -> Radix1Tree a -> Radix1Tree a)
-> Radix1Tree a
-> Radix1Tree a
forall a b. (a -> b) -> a -> b
$ \x -> Step Prefix x
step -> (a -> a)
-> a
-> (x -> Step Prefix x)
-> Prefix
-> x
-> Radix1Tree a
-> Radix1Tree a
forall a x.
(a -> a)
-> a
-> (x -> Step Prefix x)
-> Prefix
-> x
-> Radix1Tree a
-> Radix1Tree a
insertWith_ a -> a
f a
a x -> Step Prefix x
step Prefix
w
{-# INLINE insertWith_ #-}
insertWith_
:: (a -> a) -> a -> (x -> Step Word8 x) -> Word8 -> x -> Radix1Tree a -> Radix1Tree a
insertWith_ :: forall a x.
(a -> a)
-> a
-> (x -> Step Prefix x)
-> Prefix
-> x
-> Radix1Tree a
-> Radix1Tree a
insertWith_ a -> a
f a
a x -> Step Prefix x
step = Prefix -> x -> Radix1Tree a -> Radix1Tree a
go
where
go :: Prefix -> x -> Radix1Tree a -> Radix1Tree a
go Prefix
w x
s Radix1Tree a
t =
case Radix1Tree a
t of
Bin Prefix
p Radix1Tree a
l Radix1Tree a
r
| Prefix -> Prefix -> Bool
beyond Prefix
p Prefix
w -> Prefix -> Radix1Tree a -> Prefix -> Radix1Tree a -> Radix1Tree a
forall a.
Prefix -> Radix1Tree a -> Prefix -> Radix1Tree a -> Radix1Tree a
join
Prefix
w ((x -> Step Prefix x) -> Prefix -> x -> a -> Radix1Tree a
forall b a.
(b -> Step Prefix b) -> Prefix -> b -> a -> Radix1Tree a
singleton_ x -> Step Prefix x
step Prefix
w x
s a
a)
Prefix
p Radix1Tree a
t
| Prefix
w Prefix -> Prefix -> Bool
forall a. Ord a => a -> a -> Bool
< Prefix
p -> Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
forall a. Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
Bin Prefix
p (Prefix -> x -> Radix1Tree a -> Radix1Tree a
go Prefix
w x
s Radix1Tree a
l) Radix1Tree a
r
| Bool
otherwise -> Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
forall a. Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
Bin Prefix
p Radix1Tree a
l (Prefix -> x -> Radix1Tree a -> Radix1Tree a
go Prefix
w x
s Radix1Tree a
r)
Tip ByteArray
arr Maybe a
mx Radix1Tree a
dx -> Prefix -> x -> Int -> Radix1Tree a
goarr Prefix
w x
s Int
0
where
goarr :: Prefix -> x -> Int -> Radix1Tree a
goarr Prefix
v x
z Int
n
| Prefix
v Prefix -> Prefix -> Bool
forall a. Eq a => a -> a -> Bool
== ByteArray -> Int -> Prefix
forall a. Prim a => ByteArray -> Int -> a
indexByteArray ByteArray
arr Int
n =
if Int
n Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1 Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= ByteArray -> Int
sizeofByteArray ByteArray
arr
then case x -> Step Prefix x
step x
z of
More Prefix
u x
z' -> ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
Tip ByteArray
arr Maybe a
mx (Prefix -> x -> Radix1Tree a -> Radix1Tree a
go Prefix
u x
z' Radix1Tree a
dx)
Step Prefix x
Done -> let y :: a
y = case Maybe a
mx of
Just a
x -> a -> a
f a
x
Maybe a
Nothing -> a
a
in ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
Tip ByteArray
arr (a -> Maybe a
forall a. a -> Maybe a
Just a
y) Radix1Tree a
dx
else case x -> Step Prefix x
step x
z of
More Prefix
u x
z' -> Prefix -> x -> Int -> Radix1Tree a
goarr Prefix
u x
z' (Int
n Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1)
Step Prefix x
Done ->
let !(# !ByteArray
brr, !ByteArray
crr #) = Int -> Int -> ByteArray -> (# ByteArray, ByteArray #)
splitByteArray Int
0 (Int
n Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1) ByteArray
arr
in ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
Tip ByteArray
brr (a -> Maybe a
forall a. a -> Maybe a
Just a
a) (ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
Tip ByteArray
crr Maybe a
mx Radix1Tree a
dx)
| Int
n Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
0 =
Prefix -> Radix1Tree a -> Prefix -> Radix1Tree a -> Radix1Tree a
forall a.
Prefix -> Radix1Tree a -> Prefix -> Radix1Tree a -> Radix1Tree a
join
(ByteArray -> Int -> Prefix
forall a. Prim a => ByteArray -> Int -> a
indexByteArray ByteArray
arr Int
0) Radix1Tree a
t
Prefix
w ((x -> Step Prefix x) -> Prefix -> x -> a -> Radix1Tree a
forall b a.
(b -> Step Prefix b) -> Prefix -> b -> a -> Radix1Tree a
singleton_ x -> Step Prefix x
step Prefix
w x
s a
a)
| Bool
otherwise =
let !(# !ByteArray
brr, !ByteArray
crr #) = Int -> Int -> ByteArray -> (# ByteArray, ByteArray #)
splitByteArray Int
0 Int
n ByteArray
arr
in ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
Tip ByteArray
brr Maybe a
forall a. Maybe a
Nothing (Radix1Tree a -> Radix1Tree a) -> Radix1Tree a -> Radix1Tree a
forall a b. (a -> b) -> a -> b
$
Prefix -> Radix1Tree a -> Prefix -> Radix1Tree a -> Radix1Tree a
forall a.
Prefix -> Radix1Tree a -> Prefix -> Radix1Tree a -> Radix1Tree a
join
(ByteArray -> Int -> Prefix
forall a. Prim a => ByteArray -> Int -> a
indexByteArray ByteArray
crr Int
0) (ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
Tip ByteArray
crr Maybe a
mx Radix1Tree a
dx)
Prefix
v ((x -> Step Prefix x) -> Prefix -> x -> a -> Radix1Tree a
forall b a.
(b -> Step Prefix b) -> Prefix -> b -> a -> Radix1Tree a
singleton_ x -> Step Prefix x
step Prefix
v x
z a
a)
Radix1Tree a
Nil -> (x -> Step Prefix x) -> Prefix -> x -> a -> Radix1Tree a
forall b a.
(b -> Step Prefix b) -> Prefix -> b -> a -> Radix1Tree a
singleton_ x -> Step Prefix x
step Prefix
w x
s a
a
{-# INLINE adjust0 #-}
adjust0 :: (a -> a) -> Feed -> RadixTree a -> RadixTree a
adjust0 :: forall a. (a -> a) -> Feed -> RadixTree a -> RadixTree a
adjust0 a -> a
f (Feed forall a. (forall x. (x -> Step Prefix x) -> x -> a) -> a
feed) = \(RadixTree Maybe a
mx Radix1Tree a
t) ->
(forall x. (x -> Step Prefix x) -> x -> RadixTree a) -> RadixTree a
forall a. (forall x. (x -> Step Prefix x) -> x -> a) -> a
feed ((forall x. (x -> Step Prefix x) -> x -> RadixTree a)
-> RadixTree a)
-> (forall x. (x -> Step Prefix x) -> x -> RadixTree a)
-> RadixTree a
forall a b. (a -> b) -> a -> b
$ \x -> Step Prefix x
step x
s ->
case x -> Step Prefix x
step x
s of
More Prefix
w x
z -> Maybe a -> Radix1Tree a -> RadixTree a
forall a. Maybe a -> Radix1Tree a -> RadixTree a
RadixTree Maybe a
mx (Radix1Tree a -> RadixTree a) -> Radix1Tree a -> RadixTree a
forall a b. (a -> b) -> a -> b
$ (a -> a)
-> (x -> Step Prefix x)
-> Prefix
-> x
-> Radix1Tree a
-> Radix1Tree a
forall a x.
(a -> a)
-> (x -> Step Prefix x)
-> Prefix
-> x
-> Radix1Tree a
-> Radix1Tree a
adjust_ a -> a
f x -> Step Prefix x
step Prefix
w x
z Radix1Tree a
t
Step Prefix x
Done -> Maybe a -> Radix1Tree a -> RadixTree a
forall a. Maybe a -> Radix1Tree a -> RadixTree a
RadixTree ((a -> a) -> Maybe a -> Maybe a
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> a
f Maybe a
mx) Radix1Tree a
t
{-# INLINE adjust1 #-}
adjust1 :: (a -> a) -> Feed1 -> Radix1Tree a -> Radix1Tree a
adjust1 :: forall a. (a -> a) -> Feed1 -> Radix1Tree a -> Radix1Tree a
adjust1 a -> a
f (Feed1 Prefix
w forall a. (forall x. (x -> Step Prefix x) -> x -> a) -> a
feed) =
(forall x.
(x -> Step Prefix x) -> x -> Radix1Tree a -> Radix1Tree a)
-> Radix1Tree a -> Radix1Tree a
forall a. (forall x. (x -> Step Prefix x) -> x -> a) -> a
feed ((forall x.
(x -> Step Prefix x) -> x -> Radix1Tree a -> Radix1Tree a)
-> Radix1Tree a -> Radix1Tree a)
-> (forall x.
(x -> Step Prefix x) -> x -> Radix1Tree a -> Radix1Tree a)
-> Radix1Tree a
-> Radix1Tree a
forall a b. (a -> b) -> a -> b
$ \x -> Step Prefix x
step -> (a -> a)
-> (x -> Step Prefix x)
-> Prefix
-> x
-> Radix1Tree a
-> Radix1Tree a
forall a x.
(a -> a)
-> (x -> Step Prefix x)
-> Prefix
-> x
-> Radix1Tree a
-> Radix1Tree a
adjust_ a -> a
f x -> Step Prefix x
step Prefix
w
{-# INLINE adjust_ #-}
adjust_ :: (a -> a) -> (x -> Step Word8 x) -> Word8 -> x -> Radix1Tree a -> Radix1Tree a
adjust_ :: forall a x.
(a -> a)
-> (x -> Step Prefix x)
-> Prefix
-> x
-> Radix1Tree a
-> Radix1Tree a
adjust_ a -> a
f x -> Step Prefix x
step = Prefix -> x -> Radix1Tree a -> Radix1Tree a
go
where
go :: Prefix -> x -> Radix1Tree a -> Radix1Tree a
go Prefix
w x
s Radix1Tree a
t =
case Radix1Tree a
t of
Bin Prefix
p Radix1Tree a
l Radix1Tree a
r
| Prefix -> Prefix -> Bool
beyond Prefix
p Prefix
w -> Radix1Tree a
t
| Prefix
w Prefix -> Prefix -> Bool
forall a. Ord a => a -> a -> Bool
< Prefix
p -> Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
forall a. Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
Bin Prefix
p (Prefix -> x -> Radix1Tree a -> Radix1Tree a
go Prefix
w x
s Radix1Tree a
l) Radix1Tree a
r
| Bool
otherwise -> Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
forall a. Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
Bin Prefix
p Radix1Tree a
l (Prefix -> x -> Radix1Tree a -> Radix1Tree a
go Prefix
w x
s Radix1Tree a
r)
Tip ByteArray
arr Maybe a
mx Radix1Tree a
dx -> Prefix -> x -> Int -> Radix1Tree a
goarr Prefix
w x
s Int
0
where
goarr :: Prefix -> x -> Int -> Radix1Tree a
goarr Prefix
v x
z Int
n
| Prefix
v Prefix -> Prefix -> Bool
forall a. Eq a => a -> a -> Bool
== ByteArray -> Int -> Prefix
forall a. Prim a => ByteArray -> Int -> a
indexByteArray ByteArray
arr Int
n =
if Int
n Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1 Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= ByteArray -> Int
sizeofByteArray ByteArray
arr
then case x -> Step Prefix x
step x
z of
More Prefix
u x
z' -> ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
Tip ByteArray
arr Maybe a
mx (Prefix -> x -> Radix1Tree a -> Radix1Tree a
go Prefix
u x
z' Radix1Tree a
dx)
Step Prefix x
Done -> ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
Tip ByteArray
arr ((a -> a) -> Maybe a -> Maybe a
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> a
f Maybe a
mx) Radix1Tree a
dx
else case x -> Step Prefix x
step x
z of
More Prefix
u x
z' -> Prefix -> x -> Int -> Radix1Tree a
goarr Prefix
u x
z' (Int
n Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1)
Step Prefix x
Done -> Radix1Tree a
t
| Bool
otherwise = Radix1Tree a
t
Radix1Tree a
Nil -> Radix1Tree a
t
{-# INLINE delete0 #-}
delete0 :: Feed -> RadixTree a -> RadixTree a
delete0 :: forall a. Feed -> RadixTree a -> RadixTree a
delete0 (Feed forall a. (forall x. (x -> Step Prefix x) -> x -> a) -> a
feed) = \(RadixTree Maybe a
mx Radix1Tree a
t) ->
(forall x. (x -> Step Prefix x) -> x -> RadixTree a) -> RadixTree a
forall a. (forall x. (x -> Step Prefix x) -> x -> a) -> a
feed ((forall x. (x -> Step Prefix x) -> x -> RadixTree a)
-> RadixTree a)
-> (forall x. (x -> Step Prefix x) -> x -> RadixTree a)
-> RadixTree a
forall a b. (a -> b) -> a -> b
$ \x -> Step Prefix x
step x
s ->
case x -> Step Prefix x
step x
s of
More Prefix
w x
z -> Maybe a -> Radix1Tree a -> RadixTree a
forall a. Maybe a -> Radix1Tree a -> RadixTree a
RadixTree Maybe a
mx (Radix1Tree a -> RadixTree a) -> Radix1Tree a -> RadixTree a
forall a b. (a -> b) -> a -> b
$ (x -> Step Prefix x) -> Prefix -> x -> Radix1Tree a -> Radix1Tree a
forall x a.
(x -> Step Prefix x) -> Prefix -> x -> Radix1Tree a -> Radix1Tree a
delete_ x -> Step Prefix x
step Prefix
w x
z Radix1Tree a
t
Step Prefix x
Done -> Maybe a -> Radix1Tree a -> RadixTree a
forall a. Maybe a -> Radix1Tree a -> RadixTree a
RadixTree Maybe a
forall a. Maybe a
Nothing Radix1Tree a
t
{-# INLINE delete1 #-}
delete1 :: Feed1 -> Radix1Tree a -> Radix1Tree a
delete1 :: forall a. Feed1 -> Radix1Tree a -> Radix1Tree a
delete1 (Feed1 Prefix
w forall a. (forall x. (x -> Step Prefix x) -> x -> a) -> a
feed) =
(forall x.
(x -> Step Prefix x) -> x -> Radix1Tree a -> Radix1Tree a)
-> Radix1Tree a -> Radix1Tree a
forall a. (forall x. (x -> Step Prefix x) -> x -> a) -> a
feed ((forall x.
(x -> Step Prefix x) -> x -> Radix1Tree a -> Radix1Tree a)
-> Radix1Tree a -> Radix1Tree a)
-> (forall x.
(x -> Step Prefix x) -> x -> Radix1Tree a -> Radix1Tree a)
-> Radix1Tree a
-> Radix1Tree a
forall a b. (a -> b) -> a -> b
$ \x -> Step Prefix x
step -> (x -> Step Prefix x) -> Prefix -> x -> Radix1Tree a -> Radix1Tree a
forall x a.
(x -> Step Prefix x) -> Prefix -> x -> Radix1Tree a -> Radix1Tree a
delete_ x -> Step Prefix x
step Prefix
w
{-# INLINE delete_ #-}
delete_ :: (x -> Step Word8 x) -> Word8 -> x -> Radix1Tree a -> Radix1Tree a
delete_ :: forall x a.
(x -> Step Prefix x) -> Prefix -> x -> Radix1Tree a -> Radix1Tree a
delete_ x -> Step Prefix x
step = Prefix -> x -> Radix1Tree a -> Radix1Tree a
go
where
go :: Prefix -> x -> Radix1Tree a -> Radix1Tree a
go Prefix
w x
s Radix1Tree a
t =
case Radix1Tree a
t of
Bin Prefix
p Radix1Tree a
l Radix1Tree a
r
| Prefix -> Prefix -> Bool
beyond Prefix
p Prefix
w -> Radix1Tree a
t
| Prefix
w Prefix -> Prefix -> Bool
forall a. Ord a => a -> a -> Bool
< Prefix
p -> Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
forall a. Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
rebinL Prefix
p (Prefix -> x -> Radix1Tree a -> Radix1Tree a
go Prefix
w x
s Radix1Tree a
l) Radix1Tree a
r
| Bool
otherwise -> Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
forall a. Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
rebinR Prefix
p Radix1Tree a
l (Prefix -> x -> Radix1Tree a -> Radix1Tree a
go Prefix
w x
s Radix1Tree a
r)
Tip ByteArray
arr Maybe a
mx Radix1Tree a
dx -> Prefix -> x -> Int -> Radix1Tree a
goarr Prefix
w x
s Int
0
where
goarr :: Prefix -> x -> Int -> Radix1Tree a
goarr Prefix
v x
z Int
n
| Prefix
v Prefix -> Prefix -> Bool
forall a. Eq a => a -> a -> Bool
== ByteArray -> Int -> Prefix
forall a. Prim a => ByteArray -> Int -> a
indexByteArray ByteArray
arr Int
n =
if Int
n Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1 Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= ByteArray -> Int
sizeofByteArray ByteArray
arr
then case x -> Step Prefix x
step x
z of
More Prefix
u x
z' -> ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
retip ByteArray
arr Maybe a
mx (Prefix -> x -> Radix1Tree a -> Radix1Tree a
go Prefix
u x
z' Radix1Tree a
dx)
Step Prefix x
Done -> ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
retip ByteArray
arr Maybe a
forall a. Maybe a
Nothing Radix1Tree a
dx
else case x -> Step Prefix x
step x
z of
More Prefix
u x
z' -> Prefix -> x -> Int -> Radix1Tree a
goarr Prefix
u x
z' (Int
n Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1)
Step Prefix x
Done -> Radix1Tree a
t
| Bool
otherwise = Radix1Tree a
t
Radix1Tree a
Nil -> Radix1Tree a
t
{-# INLINE prune0 #-}
prune0 :: Openness -> Feed -> RadixTree a -> RadixTree a
prune0 :: forall a. Openness -> Feed -> RadixTree a -> RadixTree a
prune0 Openness
openness (Feed forall a. (forall x. (x -> Step Prefix x) -> x -> a) -> a
feed) = \(RadixTree Maybe a
mx Radix1Tree a
t) ->
(forall x. (x -> Step Prefix x) -> x -> RadixTree a) -> RadixTree a
forall a. (forall x. (x -> Step Prefix x) -> x -> a) -> a
feed ((forall x. (x -> Step Prefix x) -> x -> RadixTree a)
-> RadixTree a)
-> (forall x. (x -> Step Prefix x) -> x -> RadixTree a)
-> RadixTree a
forall a b. (a -> b) -> a -> b
$ \x -> Step Prefix x
step x
s ->
case x -> Step Prefix x
step x
s of
More Prefix
w x
z -> Maybe a -> Radix1Tree a -> RadixTree a
forall a. Maybe a -> Radix1Tree a -> RadixTree a
RadixTree Maybe a
mx (Radix1Tree a -> RadixTree a) -> Radix1Tree a -> RadixTree a
forall a b. (a -> b) -> a -> b
$ Openness
-> (x -> Step Prefix x)
-> Prefix
-> x
-> Radix1Tree a
-> Radix1Tree a
forall x a.
Openness
-> (x -> Step Prefix x)
-> Prefix
-> x
-> Radix1Tree a
-> Radix1Tree a
prune_ Openness
openness x -> Step Prefix x
step Prefix
w x
z Radix1Tree a
t
Step Prefix x
Done ->
let my :: Maybe a
my = case Openness
openness of
Openness
Open -> Maybe a
mx
Openness
Closed -> Maybe a
forall a. Maybe a
Nothing
in Maybe a -> Radix1Tree a -> RadixTree a
forall a. Maybe a -> Radix1Tree a -> RadixTree a
RadixTree Maybe a
my Radix1Tree a
forall a. Radix1Tree a
Nil
{-# INLINE prune1 #-}
prune1 :: Openness -> Feed1 -> Radix1Tree a -> Radix1Tree a
prune1 :: forall a. Openness -> Feed1 -> Radix1Tree a -> Radix1Tree a
prune1 Openness
openness (Feed1 Prefix
w forall a. (forall x. (x -> Step Prefix x) -> x -> a) -> a
feed) =
(forall x.
(x -> Step Prefix x) -> x -> Radix1Tree a -> Radix1Tree a)
-> Radix1Tree a -> Radix1Tree a
forall a. (forall x. (x -> Step Prefix x) -> x -> a) -> a
feed ((forall x.
(x -> Step Prefix x) -> x -> Radix1Tree a -> Radix1Tree a)
-> Radix1Tree a -> Radix1Tree a)
-> (forall x.
(x -> Step Prefix x) -> x -> Radix1Tree a -> Radix1Tree a)
-> Radix1Tree a
-> Radix1Tree a
forall a b. (a -> b) -> a -> b
$ \x -> Step Prefix x
step -> Openness
-> (x -> Step Prefix x)
-> Prefix
-> x
-> Radix1Tree a
-> Radix1Tree a
forall x a.
Openness
-> (x -> Step Prefix x)
-> Prefix
-> x
-> Radix1Tree a
-> Radix1Tree a
prune_ Openness
openness x -> Step Prefix x
step Prefix
w
{-# INLINE prune_ #-}
prune_ :: Openness -> (x -> Step Word8 x) -> Word8 -> x -> Radix1Tree a -> Radix1Tree a
prune_ :: forall x a.
Openness
-> (x -> Step Prefix x)
-> Prefix
-> x
-> Radix1Tree a
-> Radix1Tree a
prune_ Openness
openness x -> Step Prefix x
step = Prefix -> x -> Radix1Tree a -> Radix1Tree a
go
where
go :: Prefix -> x -> Radix1Tree a -> Radix1Tree a
go Prefix
w x
s Radix1Tree a
t =
case Radix1Tree a
t of
Bin Prefix
p Radix1Tree a
l Radix1Tree a
r
| Prefix -> Prefix -> Bool
beyond Prefix
p Prefix
w -> Radix1Tree a
t
| Prefix
w Prefix -> Prefix -> Bool
forall a. Ord a => a -> a -> Bool
< Prefix
p -> Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
forall a. Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
rebinL Prefix
p (Prefix -> x -> Radix1Tree a -> Radix1Tree a
go Prefix
w x
s Radix1Tree a
l) Radix1Tree a
r
| Bool
otherwise -> Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
forall a. Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
rebinR Prefix
p Radix1Tree a
l (Prefix -> x -> Radix1Tree a -> Radix1Tree a
go Prefix
w x
s Radix1Tree a
r)
Tip ByteArray
arr Maybe a
mx Radix1Tree a
dx -> Prefix -> x -> Int -> Radix1Tree a
goarr Prefix
w x
s Int
0
where
goarr :: Prefix -> x -> Int -> Radix1Tree a
goarr Prefix
v x
z Int
n
| Prefix
v Prefix -> Prefix -> Bool
forall a. Eq a => a -> a -> Bool
== ByteArray -> Int -> Prefix
forall a. Prim a => ByteArray -> Int -> a
indexByteArray ByteArray
arr Int
n =
if Int
n Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1 Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= ByteArray -> Int
sizeofByteArray ByteArray
arr
then case x -> Step Prefix x
step x
z of
More Prefix
u x
z' -> ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
retip ByteArray
arr Maybe a
mx (Prefix -> x -> Radix1Tree a -> Radix1Tree a
go Prefix
u x
z' Radix1Tree a
dx)
Step Prefix x
Done ->
case Openness
openness of
Openness
Open -> ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
retip ByteArray
arr Maybe a
mx Radix1Tree a
forall a. Radix1Tree a
Nil
Openness
Closed -> Radix1Tree a
forall a. Radix1Tree a
Nil
else case x -> Step Prefix x
step x
z of
More Prefix
u x
z' -> Prefix -> x -> Int -> Radix1Tree a
goarr Prefix
u x
z' (Int
n Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1)
Step Prefix x
Done -> Radix1Tree a
forall a. Radix1Tree a
Nil
| Bool
otherwise = Radix1Tree a
t
Radix1Tree a
Nil -> Radix1Tree a
t
{-# INLINE update0 #-}
update0 :: (a -> Maybe a) -> Feed -> RadixTree a -> RadixTree a
update0 :: forall a. (a -> Maybe a) -> Feed -> RadixTree a -> RadixTree a
update0 a -> Maybe a
f (Feed forall a. (forall x. (x -> Step Prefix x) -> x -> a) -> a
feed) = \(RadixTree Maybe a
mx Radix1Tree a
t) ->
(forall x. (x -> Step Prefix x) -> x -> RadixTree a) -> RadixTree a
forall a. (forall x. (x -> Step Prefix x) -> x -> a) -> a
feed ((forall x. (x -> Step Prefix x) -> x -> RadixTree a)
-> RadixTree a)
-> (forall x. (x -> Step Prefix x) -> x -> RadixTree a)
-> RadixTree a
forall a b. (a -> b) -> a -> b
$ \x -> Step Prefix x
step x
s ->
case x -> Step Prefix x
step x
s of
More Prefix
w x
z -> Maybe a -> Radix1Tree a -> RadixTree a
forall a. Maybe a -> Radix1Tree a -> RadixTree a
RadixTree Maybe a
mx (Radix1Tree a -> RadixTree a) -> Radix1Tree a -> RadixTree a
forall a b. (a -> b) -> a -> b
$ (a -> Maybe a)
-> (x -> Step Prefix x)
-> Prefix
-> x
-> Radix1Tree a
-> Radix1Tree a
forall a x.
(a -> Maybe a)
-> (x -> Step Prefix x)
-> Prefix
-> x
-> Radix1Tree a
-> Radix1Tree a
update_ a -> Maybe a
f x -> Step Prefix x
step Prefix
w x
z Radix1Tree a
t
Step Prefix x
Done -> Maybe a -> Radix1Tree a -> RadixTree a
forall a. Maybe a -> Radix1Tree a -> RadixTree a
RadixTree (a -> Maybe a
f (a -> Maybe a) -> Maybe a -> Maybe a
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Maybe a
mx) Radix1Tree a
t
{-# INLINE update1 #-}
update1 :: (a -> Maybe a) -> Feed1 -> Radix1Tree a -> Radix1Tree a
update1 :: forall a. (a -> Maybe a) -> Feed1 -> Radix1Tree a -> Radix1Tree a
update1 a -> Maybe a
f (Feed1 Prefix
w forall a. (forall x. (x -> Step Prefix x) -> x -> a) -> a
feed) =
(forall x.
(x -> Step Prefix x) -> x -> Radix1Tree a -> Radix1Tree a)
-> Radix1Tree a -> Radix1Tree a
forall a. (forall x. (x -> Step Prefix x) -> x -> a) -> a
feed ((forall x.
(x -> Step Prefix x) -> x -> Radix1Tree a -> Radix1Tree a)
-> Radix1Tree a -> Radix1Tree a)
-> (forall x.
(x -> Step Prefix x) -> x -> Radix1Tree a -> Radix1Tree a)
-> Radix1Tree a
-> Radix1Tree a
forall a b. (a -> b) -> a -> b
$ \x -> Step Prefix x
step -> (a -> Maybe a)
-> (x -> Step Prefix x)
-> Prefix
-> x
-> Radix1Tree a
-> Radix1Tree a
forall a x.
(a -> Maybe a)
-> (x -> Step Prefix x)
-> Prefix
-> x
-> Radix1Tree a
-> Radix1Tree a
update_ a -> Maybe a
f x -> Step Prefix x
step Prefix
w
{-# INLINE update_ #-}
update_
:: (a -> Maybe a) -> (x -> Step Word8 x) -> Word8 -> x -> Radix1Tree a -> Radix1Tree a
update_ :: forall a x.
(a -> Maybe a)
-> (x -> Step Prefix x)
-> Prefix
-> x
-> Radix1Tree a
-> Radix1Tree a
update_ a -> Maybe a
f x -> Step Prefix x
step = Prefix -> x -> Radix1Tree a -> Radix1Tree a
go
where
go :: Prefix -> x -> Radix1Tree a -> Radix1Tree a
go Prefix
w x
s Radix1Tree a
t =
case Radix1Tree a
t of
Bin Prefix
p Radix1Tree a
l Radix1Tree a
r
| Prefix -> Prefix -> Bool
beyond Prefix
p Prefix
w -> Radix1Tree a
t
| Prefix
w Prefix -> Prefix -> Bool
forall a. Ord a => a -> a -> Bool
< Prefix
p -> Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
forall a. Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
rebinL Prefix
p (Prefix -> x -> Radix1Tree a -> Radix1Tree a
go Prefix
w x
s Radix1Tree a
l) Radix1Tree a
r
| Bool
otherwise -> Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
forall a. Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
rebinR Prefix
p Radix1Tree a
l (Prefix -> x -> Radix1Tree a -> Radix1Tree a
go Prefix
w x
s Radix1Tree a
r)
Tip ByteArray
arr Maybe a
mx Radix1Tree a
dx -> Prefix -> x -> Int -> Radix1Tree a
goarr Prefix
w x
s Int
0
where
goarr :: Prefix -> x -> Int -> Radix1Tree a
goarr Prefix
v x
z Int
n
| Prefix
v Prefix -> Prefix -> Bool
forall a. Eq a => a -> a -> Bool
== ByteArray -> Int -> Prefix
forall a. Prim a => ByteArray -> Int -> a
indexByteArray ByteArray
arr Int
n =
if Int
n Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1 Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= ByteArray -> Int
sizeofByteArray ByteArray
arr
then case x -> Step Prefix x
step x
z of
More Prefix
u x
z' -> ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
retip ByteArray
arr Maybe a
mx (Prefix -> x -> Radix1Tree a -> Radix1Tree a
go Prefix
u x
z' Radix1Tree a
dx)
Step Prefix x
Done -> ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
retip ByteArray
arr (a -> Maybe a
f (a -> Maybe a) -> Maybe a -> Maybe a
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Maybe a
mx) Radix1Tree a
dx
else case x -> Step Prefix x
step x
z of
More Prefix
u x
z' -> Prefix -> x -> Int -> Radix1Tree a
goarr Prefix
u x
z' (Int
n Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1)
Step Prefix x
Done -> Radix1Tree a
t
| Bool
otherwise = Radix1Tree a
t
Radix1Tree a
Nil -> Radix1Tree a
t
{-# INLINE alter0 #-}
alter0 :: (Maybe a -> Maybe a) -> Feed -> RadixTree a -> RadixTree a
alter0 :: forall a.
(Maybe a -> Maybe a) -> Feed -> RadixTree a -> RadixTree a
alter0 Maybe a -> Maybe a
f (Feed forall a. (forall x. (x -> Step Prefix x) -> x -> a) -> a
feed) = \(RadixTree Maybe a
mx Radix1Tree a
t) ->
(forall x. (x -> Step Prefix x) -> x -> RadixTree a) -> RadixTree a
forall a. (forall x. (x -> Step Prefix x) -> x -> a) -> a
feed ((forall x. (x -> Step Prefix x) -> x -> RadixTree a)
-> RadixTree a)
-> (forall x. (x -> Step Prefix x) -> x -> RadixTree a)
-> RadixTree a
forall a b. (a -> b) -> a -> b
$ \x -> Step Prefix x
step x
s ->
case x -> Step Prefix x
step x
s of
More Prefix
w x
z -> Maybe a -> Radix1Tree a -> RadixTree a
forall a. Maybe a -> Radix1Tree a -> RadixTree a
RadixTree Maybe a
mx (Radix1Tree a -> RadixTree a) -> Radix1Tree a -> RadixTree a
forall a b. (a -> b) -> a -> b
$ (Maybe a -> Maybe a)
-> (x -> Step Prefix x)
-> Prefix
-> x
-> Radix1Tree a
-> Radix1Tree a
forall a x.
(Maybe a -> Maybe a)
-> (x -> Step Prefix x)
-> Prefix
-> x
-> Radix1Tree a
-> Radix1Tree a
alter_ Maybe a -> Maybe a
f x -> Step Prefix x
step Prefix
w x
z Radix1Tree a
t
Step Prefix x
Done -> Maybe a -> Radix1Tree a -> RadixTree a
forall a. Maybe a -> Radix1Tree a -> RadixTree a
RadixTree (Maybe a -> Maybe a
f Maybe a
mx) Radix1Tree a
t
{-# INLINE alter1 #-}
alter1 :: (Maybe a -> Maybe a) -> Feed1 -> Radix1Tree a -> Radix1Tree a
alter1 :: forall a.
(Maybe a -> Maybe a) -> Feed1 -> Radix1Tree a -> Radix1Tree a
alter1 Maybe a -> Maybe a
f (Feed1 Prefix
w forall a. (forall x. (x -> Step Prefix x) -> x -> a) -> a
feed) =
(forall x.
(x -> Step Prefix x) -> x -> Radix1Tree a -> Radix1Tree a)
-> Radix1Tree a -> Radix1Tree a
forall a. (forall x. (x -> Step Prefix x) -> x -> a) -> a
feed ((forall x.
(x -> Step Prefix x) -> x -> Radix1Tree a -> Radix1Tree a)
-> Radix1Tree a -> Radix1Tree a)
-> (forall x.
(x -> Step Prefix x) -> x -> Radix1Tree a -> Radix1Tree a)
-> Radix1Tree a
-> Radix1Tree a
forall a b. (a -> b) -> a -> b
$ \x -> Step Prefix x
step -> (Maybe a -> Maybe a)
-> (x -> Step Prefix x)
-> Prefix
-> x
-> Radix1Tree a
-> Radix1Tree a
forall a x.
(Maybe a -> Maybe a)
-> (x -> Step Prefix x)
-> Prefix
-> x
-> Radix1Tree a
-> Radix1Tree a
alter_ Maybe a -> Maybe a
f x -> Step Prefix x
step Prefix
w
{-# INLINE alter_ #-}
alter_
:: (Maybe a -> Maybe a)
-> (x -> Step Word8 x) -> Word8 -> x -> Radix1Tree a -> Radix1Tree a
alter_ :: forall a x.
(Maybe a -> Maybe a)
-> (x -> Step Prefix x)
-> Prefix
-> x
-> Radix1Tree a
-> Radix1Tree a
alter_ Maybe a -> Maybe a
f x -> Step Prefix x
step = Prefix -> x -> Radix1Tree a -> Radix1Tree a
go
where
go :: Prefix -> x -> Radix1Tree a -> Radix1Tree a
go Prefix
w x
s Radix1Tree a
t =
case Radix1Tree a
t of
Bin Prefix
p Radix1Tree a
l Radix1Tree a
r
| Prefix -> Prefix -> Bool
beyond Prefix
p Prefix
w -> case Maybe a -> Maybe a
f Maybe a
forall a. Maybe a
Nothing of
Maybe a
Nothing -> Radix1Tree a
t
Just a
a -> Prefix -> Radix1Tree a -> Prefix -> Radix1Tree a -> Radix1Tree a
forall a.
Prefix -> Radix1Tree a -> Prefix -> Radix1Tree a -> Radix1Tree a
join
Prefix
w ((x -> Step Prefix x) -> Prefix -> x -> a -> Radix1Tree a
forall b a.
(b -> Step Prefix b) -> Prefix -> b -> a -> Radix1Tree a
singleton_ x -> Step Prefix x
step Prefix
w x
s a
a)
Prefix
p Radix1Tree a
t
| Prefix
w Prefix -> Prefix -> Bool
forall a. Ord a => a -> a -> Bool
< Prefix
p -> Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
forall a. Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
rebinL Prefix
p (Prefix -> x -> Radix1Tree a -> Radix1Tree a
go Prefix
w x
s Radix1Tree a
l) Radix1Tree a
r
| Bool
otherwise -> Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
forall a. Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
rebinR Prefix
p Radix1Tree a
l (Prefix -> x -> Radix1Tree a -> Radix1Tree a
go Prefix
w x
s Radix1Tree a
r)
Tip ByteArray
arr Maybe a
mx Radix1Tree a
dx -> Prefix -> x -> Int -> Radix1Tree a
goarr Prefix
w x
s Int
0
where
goarr :: Prefix -> x -> Int -> Radix1Tree a
goarr Prefix
v x
z Int
n
| Prefix
v Prefix -> Prefix -> Bool
forall a. Eq a => a -> a -> Bool
== ByteArray -> Int -> Prefix
forall a. Prim a => ByteArray -> Int -> a
indexByteArray ByteArray
arr Int
n =
if Int
n Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1 Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= ByteArray -> Int
sizeofByteArray ByteArray
arr
then case x -> Step Prefix x
step x
z of
More Prefix
u x
z' -> ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
retip ByteArray
arr Maybe a
mx (Prefix -> x -> Radix1Tree a -> Radix1Tree a
go Prefix
u x
z' Radix1Tree a
dx)
Step Prefix x
Done -> ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
retip ByteArray
arr (Maybe a -> Maybe a
f Maybe a
mx) Radix1Tree a
dx
else case x -> Step Prefix x
step x
z of
More Prefix
u x
z' -> Prefix -> x -> Int -> Radix1Tree a
goarr Prefix
u x
z' (Int
n Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1)
Step Prefix x
Done ->
case Maybe a -> Maybe a
f Maybe a
forall a. Maybe a
Nothing of
Maybe a
Nothing -> Radix1Tree a
t
Just a
a ->
let !(# !ByteArray
brr, !ByteArray
crr #) = Int -> Int -> ByteArray -> (# ByteArray, ByteArray #)
splitByteArray Int
0 (Int
n Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1) ByteArray
arr
in ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
Tip ByteArray
brr (a -> Maybe a
forall a. a -> Maybe a
Just a
a) (ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
Tip ByteArray
crr Maybe a
mx Radix1Tree a
dx)
| Bool
otherwise =
case Maybe a -> Maybe a
f Maybe a
forall a. Maybe a
Nothing of
Maybe a
Nothing -> Radix1Tree a
t
Just a
a ->
if Int
n Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
0
then Prefix -> Radix1Tree a -> Prefix -> Radix1Tree a -> Radix1Tree a
forall a.
Prefix -> Radix1Tree a -> Prefix -> Radix1Tree a -> Radix1Tree a
join
(ByteArray -> Int -> Prefix
forall a. Prim a => ByteArray -> Int -> a
indexByteArray ByteArray
arr Int
0) (ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
Tip ByteArray
arr Maybe a
mx Radix1Tree a
dx)
Prefix
w ((x -> Step Prefix x) -> Prefix -> x -> a -> Radix1Tree a
forall b a.
(b -> Step Prefix b) -> Prefix -> b -> a -> Radix1Tree a
singleton_ x -> Step Prefix x
step Prefix
v x
z a
a)
else let !(# !ByteArray
brr, !ByteArray
crr #) = Int -> Int -> ByteArray -> (# ByteArray, ByteArray #)
splitByteArray Int
0 Int
n ByteArray
arr
in ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
Tip ByteArray
brr Maybe a
forall a. Maybe a
Nothing (Radix1Tree a -> Radix1Tree a) -> Radix1Tree a -> Radix1Tree a
forall a b. (a -> b) -> a -> b
$
Prefix -> Radix1Tree a -> Prefix -> Radix1Tree a -> Radix1Tree a
forall a.
Prefix -> Radix1Tree a -> Prefix -> Radix1Tree a -> Radix1Tree a
join
(ByteArray -> Int -> Prefix
forall a. Prim a => ByteArray -> Int -> a
indexByteArray ByteArray
crr Int
0) (ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
Tip ByteArray
crr Maybe a
mx Radix1Tree a
dx)
Prefix
v ((x -> Step Prefix x) -> Prefix -> x -> a -> Radix1Tree a
forall b a.
(b -> Step Prefix b) -> Prefix -> b -> a -> Radix1Tree a
singleton_ x -> Step Prefix x
step Prefix
v x
z a
a)
Radix1Tree a
Nil ->
case Maybe a -> Maybe a
f Maybe a
forall a. Maybe a
Nothing of
Maybe a
Nothing -> Radix1Tree a
t
Just a
a -> (x -> Step Prefix x) -> Prefix -> x -> a -> Radix1Tree a
forall b a.
(b -> Step Prefix b) -> Prefix -> b -> a -> Radix1Tree a
singleton_ x -> Step Prefix x
step Prefix
w x
s a
a
{-# INLINE shape0 #-}
shape0 :: (RadixTree a -> RadixTree a) -> Feed -> RadixTree a -> RadixTree a
shape0 :: forall a.
(RadixTree a -> RadixTree a) -> Feed -> RadixTree a -> RadixTree a
shape0 RadixTree a -> RadixTree a
f (Feed forall a. (forall x. (x -> Step Prefix x) -> x -> a) -> a
feed) = \t0 :: RadixTree a
t0@(RadixTree Maybe a
mx Radix1Tree a
t) ->
(forall x. (x -> Step Prefix x) -> x -> RadixTree a) -> RadixTree a
forall a. (forall x. (x -> Step Prefix x) -> x -> a) -> a
feed ((forall x. (x -> Step Prefix x) -> x -> RadixTree a)
-> RadixTree a)
-> (forall x. (x -> Step Prefix x) -> x -> RadixTree a)
-> RadixTree a
forall a b. (a -> b) -> a -> b
$ \x -> Step Prefix x
step x
s ->
case x -> Step Prefix x
step x
s of
More Prefix
w x
z -> Maybe a -> Radix1Tree a -> RadixTree a
forall a. Maybe a -> Radix1Tree a -> RadixTree a
RadixTree Maybe a
mx (Radix1Tree a -> RadixTree a) -> Radix1Tree a -> RadixTree a
forall a b. (a -> b) -> a -> b
$ (RadixTree a -> RadixTree a)
-> (x -> Step Prefix x)
-> Prefix
-> x
-> Radix1Tree a
-> Radix1Tree a
forall a x.
(RadixTree a -> RadixTree a)
-> (x -> Step Prefix x)
-> Prefix
-> x
-> Radix1Tree a
-> Radix1Tree a
shape_ RadixTree a -> RadixTree a
f x -> Step Prefix x
step Prefix
w x
z Radix1Tree a
t
Step Prefix x
Done -> RadixTree a -> RadixTree a
f RadixTree a
t0
{-# INLINE shape1 #-}
shape1 :: (RadixTree a -> RadixTree a) -> Feed1 -> Radix1Tree a -> Radix1Tree a
shape1 :: forall a.
(RadixTree a -> RadixTree a)
-> Feed1 -> Radix1Tree a -> Radix1Tree a
shape1 RadixTree a -> RadixTree a
f (Feed1 Prefix
w forall a. (forall x. (x -> Step Prefix x) -> x -> a) -> a
feed) =
(forall x.
(x -> Step Prefix x) -> x -> Radix1Tree a -> Radix1Tree a)
-> Radix1Tree a -> Radix1Tree a
forall a. (forall x. (x -> Step Prefix x) -> x -> a) -> a
feed ((forall x.
(x -> Step Prefix x) -> x -> Radix1Tree a -> Radix1Tree a)
-> Radix1Tree a -> Radix1Tree a)
-> (forall x.
(x -> Step Prefix x) -> x -> Radix1Tree a -> Radix1Tree a)
-> Radix1Tree a
-> Radix1Tree a
forall a b. (a -> b) -> a -> b
$ \x -> Step Prefix x
step -> (RadixTree a -> RadixTree a)
-> (x -> Step Prefix x)
-> Prefix
-> x
-> Radix1Tree a
-> Radix1Tree a
forall a x.
(RadixTree a -> RadixTree a)
-> (x -> Step Prefix x)
-> Prefix
-> x
-> Radix1Tree a
-> Radix1Tree a
shape_ RadixTree a -> RadixTree a
f x -> Step Prefix x
step Prefix
w
{-# INLINE shape_ #-}
shape_
:: (RadixTree a -> RadixTree a)
-> (x -> Step Word8 x) -> Word8 -> x -> Radix1Tree a -> Radix1Tree a
shape_ :: forall a x.
(RadixTree a -> RadixTree a)
-> (x -> Step Prefix x)
-> Prefix
-> x
-> Radix1Tree a
-> Radix1Tree a
shape_ RadixTree a -> RadixTree a
f x -> Step Prefix x
step = Prefix -> x -> Radix1Tree a -> Radix1Tree a
go
where
go :: Prefix -> x -> Radix1Tree a -> Radix1Tree a
go Prefix
w x
s Radix1Tree a
t =
case Radix1Tree a
t of
Bin Prefix
p Radix1Tree a
l Radix1Tree a
r
| Prefix -> Prefix -> Bool
beyond Prefix
p Prefix
w -> let !(RadixTree Maybe a
my Radix1Tree a
dy) = RadixTree a -> RadixTree a
f (Maybe a -> Radix1Tree a -> RadixTree a
forall a. Maybe a -> Radix1Tree a -> RadixTree a
RadixTree Maybe a
forall a. Maybe a
Nothing Radix1Tree a
forall a. Radix1Tree a
Nil)
in case ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
retip ((x -> Step Prefix x) -> Prefix -> x -> ByteArray
forall x. (x -> Step Prefix x) -> Prefix -> x -> ByteArray
fromStep x -> Step Prefix x
step Prefix
w x
s) Maybe a
my Radix1Tree a
dy of
Radix1Tree a
Nil -> Radix1Tree a
t
Radix1Tree a
dz -> Prefix -> Radix1Tree a -> Prefix -> Radix1Tree a -> Radix1Tree a
forall a.
Prefix -> Radix1Tree a -> Prefix -> Radix1Tree a -> Radix1Tree a
join
Prefix
w Radix1Tree a
dz
Prefix
p Radix1Tree a
t
| Prefix
w Prefix -> Prefix -> Bool
forall a. Ord a => a -> a -> Bool
< Prefix
p -> Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
forall a. Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
rebinL Prefix
p (Prefix -> x -> Radix1Tree a -> Radix1Tree a
go Prefix
w x
s Radix1Tree a
l) Radix1Tree a
r
| Bool
otherwise -> Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
forall a. Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
rebinR Prefix
p Radix1Tree a
l (Prefix -> x -> Radix1Tree a -> Radix1Tree a
go Prefix
w x
s Radix1Tree a
r)
Tip ByteArray
arr Maybe a
mx Radix1Tree a
dx -> Prefix -> x -> Int -> Radix1Tree a
goarr Prefix
w x
s Int
0
where
goarr :: Prefix -> x -> Int -> Radix1Tree a
goarr Prefix
v x
z Int
n
| Prefix
v Prefix -> Prefix -> Bool
forall a. Eq a => a -> a -> Bool
== ByteArray -> Int -> Prefix
forall a. Prim a => ByteArray -> Int -> a
indexByteArray ByteArray
arr Int
n =
let n' :: Int
n' = Int
n Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1
in if Int
n' Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= ByteArray -> Int
sizeofByteArray ByteArray
arr
then case x -> Step Prefix x
step x
z of
More Prefix
u x
z' -> ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
retip ByteArray
arr Maybe a
mx (Prefix -> x -> Radix1Tree a -> Radix1Tree a
go Prefix
u x
z' Radix1Tree a
dx)
Step Prefix x
Done -> let !(RadixTree Maybe a
my Radix1Tree a
dy) = RadixTree a -> RadixTree a
f (Maybe a -> Radix1Tree a -> RadixTree a
forall a. Maybe a -> Radix1Tree a -> RadixTree a
RadixTree Maybe a
mx Radix1Tree a
dx)
in ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
retip ByteArray
arr Maybe a
my Radix1Tree a
dy
else case x -> Step Prefix x
step x
z of
More Prefix
u x
z' -> Prefix -> x -> Int -> Radix1Tree a
goarr Prefix
u x
z' Int
n'
Step Prefix x
Done ->
let !(# !ByteArray
brr, !ByteArray
crr #) = Int -> Int -> ByteArray -> (# ByteArray, ByteArray #)
splitByteArray Int
0 Int
n' ByteArray
arr
!(RadixTree Maybe a
my Radix1Tree a
dy) = RadixTree a -> RadixTree a
f (Maybe a -> Radix1Tree a -> RadixTree a
forall a. Maybe a -> Radix1Tree a -> RadixTree a
RadixTree Maybe a
forall a. Maybe a
Nothing (ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
Tip ByteArray
crr Maybe a
mx Radix1Tree a
dx))
in ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
retip ByteArray
brr Maybe a
my Radix1Tree a
dy
| Bool
otherwise =
let !(RadixTree Maybe a
my Radix1Tree a
dy) = RadixTree a -> RadixTree a
f (Maybe a -> Radix1Tree a -> RadixTree a
forall a. Maybe a -> Radix1Tree a -> RadixTree a
RadixTree Maybe a
forall a. Maybe a
Nothing Radix1Tree a
forall a. Radix1Tree a
Nil)
in case ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
retip ((x -> Step Prefix x) -> Prefix -> x -> ByteArray
forall x. (x -> Step Prefix x) -> Prefix -> x -> ByteArray
fromStep x -> Step Prefix x
step Prefix
v x
z) Maybe a
my Radix1Tree a
dy of
Radix1Tree a
Nil -> Radix1Tree a
t
Radix1Tree a
dz ->
if Int
n Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
0
then Prefix -> Radix1Tree a -> Prefix -> Radix1Tree a -> Radix1Tree a
forall a.
Prefix -> Radix1Tree a -> Prefix -> Radix1Tree a -> Radix1Tree a
join
(ByteArray -> Int -> Prefix
forall a. Prim a => ByteArray -> Int -> a
indexByteArray ByteArray
arr Int
0) (ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
Tip ByteArray
arr Maybe a
mx Radix1Tree a
dx)
Prefix
v Radix1Tree a
dz
else let !(# !ByteArray
brr, !ByteArray
crr #) = Int -> Int -> ByteArray -> (# ByteArray, ByteArray #)
splitByteArray Int
0 Int
n ByteArray
arr
in ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
Tip ByteArray
brr Maybe a
forall a. Maybe a
Nothing (Radix1Tree a -> Radix1Tree a) -> Radix1Tree a -> Radix1Tree a
forall a b. (a -> b) -> a -> b
$
Prefix -> Radix1Tree a -> Prefix -> Radix1Tree a -> Radix1Tree a
forall a.
Prefix -> Radix1Tree a -> Prefix -> Radix1Tree a -> Radix1Tree a
join
(ByteArray -> Int -> Prefix
forall a. Prim a => ByteArray -> Int -> a
indexByteArray ByteArray
crr Int
0) (ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
Tip ByteArray
crr Maybe a
mx Radix1Tree a
dx)
Prefix
v Radix1Tree a
dz
Radix1Tree a
Nil ->
let !(RadixTree Maybe a
my Radix1Tree a
dy) = RadixTree a -> RadixTree a
f (Maybe a -> Radix1Tree a -> RadixTree a
forall a. Maybe a -> Radix1Tree a -> RadixTree a
RadixTree Maybe a
forall a. Maybe a
Nothing Radix1Tree a
forall a. Radix1Tree a
Nil)
in ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
retip ((x -> Step Prefix x) -> Prefix -> x -> ByteArray
forall x. (x -> Step Prefix x) -> Prefix -> x -> ByteArray
fromStep x -> Step Prefix x
step Prefix
w x
s) Maybe a
my Radix1Tree a
dy
{-# INLINE splitL0 #-}
splitL0 :: Openness -> Feed -> RadixTree a -> (RadixTree a, RadixTree a)
splitL0 :: forall a.
Openness -> Feed -> RadixTree a -> (RadixTree a, RadixTree a)
splitL0 Openness
openness (Feed forall a. (forall x. (x -> Step Prefix x) -> x -> a) -> a
feed) = \(RadixTree Maybe a
mx Radix1Tree a
t) ->
(forall x. (x -> Step Prefix x) -> x -> (RadixTree a, RadixTree a))
-> (RadixTree a, RadixTree a)
forall a. (forall x. (x -> Step Prefix x) -> x -> a) -> a
feed ((forall x.
(x -> Step Prefix x) -> x -> (RadixTree a, RadixTree a))
-> (RadixTree a, RadixTree a))
-> (forall x.
(x -> Step Prefix x) -> x -> (RadixTree a, RadixTree a))
-> (RadixTree a, RadixTree a)
forall a b. (a -> b) -> a -> b
$ \x -> Step Prefix x
step x
s ->
case x -> Step Prefix x
step x
s of
More Prefix
w x
z ->
let !(# Radix1Tree a
l, Radix1Tree a
r #) = Openness
-> (x -> Step Prefix x)
-> Prefix
-> x
-> Radix1Tree a
-> (# Radix1Tree a, Radix1Tree a #)
forall x a.
Openness
-> (x -> Step Prefix x)
-> Prefix
-> x
-> Radix1Tree a
-> (# Radix1Tree a, Radix1Tree a #)
splitL_ Openness
openness x -> Step Prefix x
step Prefix
w x
z Radix1Tree a
t
in (Maybe a -> Radix1Tree a -> RadixTree a
forall a. Maybe a -> Radix1Tree a -> RadixTree a
RadixTree Maybe a
mx Radix1Tree a
l, Maybe a -> Radix1Tree a -> RadixTree a
forall a. Maybe a -> Radix1Tree a -> RadixTree a
RadixTree Maybe a
forall a. Maybe a
Nothing Radix1Tree a
r)
Step Prefix x
Done ->
let !(# Maybe a
my, Maybe a
mz #) = case Openness
openness of
Openness
Open -> (# Maybe a
forall a. Maybe a
Nothing, Maybe a
mx #)
Openness
Closed -> (# Maybe a
mx, Maybe a
forall a. Maybe a
Nothing #)
in (Maybe a -> Radix1Tree a -> RadixTree a
forall a. Maybe a -> Radix1Tree a -> RadixTree a
RadixTree Maybe a
my Radix1Tree a
forall a. Radix1Tree a
Nil, Maybe a -> Radix1Tree a -> RadixTree a
forall a. Maybe a -> Radix1Tree a -> RadixTree a
RadixTree Maybe a
mz Radix1Tree a
t)
{-# INLINE splitL1 #-}
splitL1 :: Openness -> Feed1 -> Radix1Tree a -> (Radix1Tree a, Radix1Tree a)
splitL1 :: forall a.
Openness -> Feed1 -> Radix1Tree a -> (Radix1Tree a, Radix1Tree a)
splitL1 Openness
openness (Feed1 Prefix
w forall a. (forall x. (x -> Step Prefix x) -> x -> a) -> a
feed) = \Radix1Tree a
t ->
(forall x.
(x -> Step Prefix x) -> x -> (Radix1Tree a, Radix1Tree a))
-> (Radix1Tree a, Radix1Tree a)
forall a. (forall x. (x -> Step Prefix x) -> x -> a) -> a
feed ((forall x.
(x -> Step Prefix x) -> x -> (Radix1Tree a, Radix1Tree a))
-> (Radix1Tree a, Radix1Tree a))
-> (forall x.
(x -> Step Prefix x) -> x -> (Radix1Tree a, Radix1Tree a))
-> (Radix1Tree a, Radix1Tree a)
forall a b. (a -> b) -> a -> b
$ \x -> Step Prefix x
step x
s ->
case Openness
-> (x -> Step Prefix x)
-> Prefix
-> x
-> Radix1Tree a
-> (# Radix1Tree a, Radix1Tree a #)
forall x a.
Openness
-> (x -> Step Prefix x)
-> Prefix
-> x
-> Radix1Tree a
-> (# Radix1Tree a, Radix1Tree a #)
splitL_ Openness
openness x -> Step Prefix x
step Prefix
w x
s Radix1Tree a
t of
(# Radix1Tree a
l, Radix1Tree a
r #) -> (Radix1Tree a
l, Radix1Tree a
r)
{-# INLINE splitL_ #-}
splitL_
:: Openness -> (x -> Step Word8 x)
-> Word8 -> x -> Radix1Tree a -> (# Radix1Tree a, Radix1Tree a #)
splitL_ :: forall x a.
Openness
-> (x -> Step Prefix x)
-> Prefix
-> x
-> Radix1Tree a
-> (# Radix1Tree a, Radix1Tree a #)
splitL_ Openness
openness x -> Step Prefix x
step = Prefix -> x -> Radix1Tree a -> (# Radix1Tree a, Radix1Tree a #)
go
where
go :: Prefix -> x -> Radix1Tree a -> (# Radix1Tree a, Radix1Tree a #)
go Prefix
w x
s Radix1Tree a
t =
case Radix1Tree a
t of
Bin Prefix
p Radix1Tree a
l Radix1Tree a
r ->
if Prefix
w Prefix -> Prefix -> Bool
forall a. Ord a => a -> a -> Bool
< Prefix
p
then if Prefix
w Prefix -> Prefix -> Bool
forall a. Ord a => a -> a -> Bool
>= Prefix -> Prefix
lower Prefix
p
then let !(# Radix1Tree a
ll, Radix1Tree a
lr #) = Prefix -> x -> Radix1Tree a -> (# Radix1Tree a, Radix1Tree a #)
go Prefix
w x
s Radix1Tree a
l
in (# Radix1Tree a
ll, Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
forall a. Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
rebinL Prefix
p Radix1Tree a
lr Radix1Tree a
r #)
else (# Radix1Tree a
forall a. Radix1Tree a
Nil, Radix1Tree a
t #)
else if Prefix
w Prefix -> Prefix -> Bool
forall a. Ord a => a -> a -> Bool
<= Prefix -> Prefix
upper Prefix
p
then let !(# Radix1Tree a
rl, Radix1Tree a
rr #) = Prefix -> x -> Radix1Tree a -> (# Radix1Tree a, Radix1Tree a #)
go Prefix
w x
s Radix1Tree a
r
in (# Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
forall a. Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
rebinR Prefix
p Radix1Tree a
l Radix1Tree a
rl, Radix1Tree a
rr #)
else (# Radix1Tree a
t, Radix1Tree a
forall a. Radix1Tree a
Nil #)
Tip ByteArray
arr Maybe a
mx Radix1Tree a
dx -> Prefix -> x -> Int -> (# Radix1Tree a, Radix1Tree a #)
goarr Prefix
w x
s Int
0
where
goarr :: Prefix -> x -> Int -> (# Radix1Tree a, Radix1Tree a #)
goarr Prefix
v x
z Int
n =
let n' :: Int
n' = Int
n Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1
in case ByteArray -> Int -> Prefix
forall a. Prim a => ByteArray -> Int -> a
indexByteArray ByteArray
arr Int
n Prefix -> Prefix -> Ordering
forall a. Ord a => a -> a -> Ordering
`compare` Prefix
v of
Ordering
EQ | Int
n' Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= ByteArray -> Int
sizeofByteArray ByteArray
arr ->
case x -> Step Prefix x
step x
z of
More Prefix
u x
z' ->
let !(# Radix1Tree a
dl, Radix1Tree a
dr #) = Prefix -> x -> Radix1Tree a -> (# Radix1Tree a, Radix1Tree a #)
go Prefix
u x
z' Radix1Tree a
dx
in (# ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
retip ByteArray
arr Maybe a
mx Radix1Tree a
dl, ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
retip ByteArray
arr Maybe a
forall a. Maybe a
Nothing Radix1Tree a
dr #)
Step Prefix x
Done ->
let !(# Radix1Tree a
my, Maybe a
mz #) =
case Openness
openness of
Openness
Open -> (# Radix1Tree a
forall a. Radix1Tree a
Nil , Maybe a
mx #)
Openness
Closed -> (# ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
retip ByteArray
arr Maybe a
mx Radix1Tree a
forall a. Radix1Tree a
Nil, Maybe a
forall a. Maybe a
Nothing #)
in (# Radix1Tree a
my, ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
retip ByteArray
arr Maybe a
mz Radix1Tree a
dx #)
| Bool
otherwise ->
case x -> Step Prefix x
step x
z of
More Prefix
u x
z' -> Prefix -> x -> Int -> (# Radix1Tree a, Radix1Tree a #)
goarr Prefix
u x
z' Int
n'
Step Prefix x
Done -> (# Radix1Tree a
forall a. Radix1Tree a
Nil, Radix1Tree a
t #)
Ordering
LT -> (# Radix1Tree a
t, Radix1Tree a
forall a. Radix1Tree a
Nil #)
Ordering
GT -> (# Radix1Tree a
forall a. Radix1Tree a
Nil, Radix1Tree a
t #)
Radix1Tree a
Nil -> (# Radix1Tree a
forall a. Radix1Tree a
Nil, Radix1Tree a
forall a. Radix1Tree a
Nil #)
{-# INLINE splitLookup0 #-}
splitLookup0 :: Feed -> RadixTree a -> (RadixTree a, Maybe a, RadixTree a)
splitLookup0 :: forall a.
Feed -> RadixTree a -> (RadixTree a, Maybe a, RadixTree a)
splitLookup0 (Feed forall a. (forall x. (x -> Step Prefix x) -> x -> a) -> a
feed) = \(RadixTree Maybe a
mx Radix1Tree a
t) ->
(forall x.
(x -> Step Prefix x) -> x -> (RadixTree a, Maybe a, RadixTree a))
-> (RadixTree a, Maybe a, RadixTree a)
forall a. (forall x. (x -> Step Prefix x) -> x -> a) -> a
feed ((forall x.
(x -> Step Prefix x) -> x -> (RadixTree a, Maybe a, RadixTree a))
-> (RadixTree a, Maybe a, RadixTree a))
-> (forall x.
(x -> Step Prefix x) -> x -> (RadixTree a, Maybe a, RadixTree a))
-> (RadixTree a, Maybe a, RadixTree a)
forall a b. (a -> b) -> a -> b
$ \x -> Step Prefix x
step x
s ->
case x -> Step Prefix x
step x
s of
More Prefix
w x
z ->
let !(# Radix1Tree a
l, Maybe a
my, Radix1Tree a
r #) = (x -> Step Prefix x)
-> Prefix
-> x
-> Radix1Tree a
-> (# Radix1Tree a, Maybe a, Radix1Tree a #)
forall x a.
(x -> Step Prefix x)
-> Prefix
-> x
-> Radix1Tree a
-> (# Radix1Tree a, Maybe a, Radix1Tree a #)
splitLookup_ x -> Step Prefix x
step Prefix
w x
z Radix1Tree a
t
in (Maybe a -> Radix1Tree a -> RadixTree a
forall a. Maybe a -> Radix1Tree a -> RadixTree a
RadixTree Maybe a
mx Radix1Tree a
l, Maybe a
my, Maybe a -> Radix1Tree a -> RadixTree a
forall a. Maybe a -> Radix1Tree a -> RadixTree a
RadixTree Maybe a
forall a. Maybe a
Nothing Radix1Tree a
r)
Step Prefix x
Done -> (Maybe a -> Radix1Tree a -> RadixTree a
forall a. Maybe a -> Radix1Tree a -> RadixTree a
RadixTree Maybe a
forall a. Maybe a
Nothing Radix1Tree a
forall a. Radix1Tree a
Nil, Maybe a
mx, Maybe a -> Radix1Tree a -> RadixTree a
forall a. Maybe a -> Radix1Tree a -> RadixTree a
RadixTree Maybe a
forall a. Maybe a
Nothing Radix1Tree a
t)
{-# INLINE splitLookup1 #-}
splitLookup1 :: Feed1 -> Radix1Tree a -> (Radix1Tree a, Maybe a, Radix1Tree a)
splitLookup1 :: forall a.
Feed1 -> Radix1Tree a -> (Radix1Tree a, Maybe a, Radix1Tree a)
splitLookup1 (Feed1 Prefix
w forall a. (forall x. (x -> Step Prefix x) -> x -> a) -> a
feed) = \Radix1Tree a
t ->
(forall x.
(x -> Step Prefix x) -> x -> (Radix1Tree a, Maybe a, Radix1Tree a))
-> (Radix1Tree a, Maybe a, Radix1Tree a)
forall a. (forall x. (x -> Step Prefix x) -> x -> a) -> a
feed ((forall x.
(x -> Step Prefix x) -> x -> (Radix1Tree a, Maybe a, Radix1Tree a))
-> (Radix1Tree a, Maybe a, Radix1Tree a))
-> (forall x.
(x -> Step Prefix x) -> x -> (Radix1Tree a, Maybe a, Radix1Tree a))
-> (Radix1Tree a, Maybe a, Radix1Tree a)
forall a b. (a -> b) -> a -> b
$ \x -> Step Prefix x
step x
s ->
case (x -> Step Prefix x)
-> Prefix
-> x
-> Radix1Tree a
-> (# Radix1Tree a, Maybe a, Radix1Tree a #)
forall x a.
(x -> Step Prefix x)
-> Prefix
-> x
-> Radix1Tree a
-> (# Radix1Tree a, Maybe a, Radix1Tree a #)
splitLookup_ x -> Step Prefix x
step Prefix
w x
s Radix1Tree a
t of
(# Radix1Tree a
l, Maybe a
mx, Radix1Tree a
r #) -> (Radix1Tree a
l, Maybe a
mx, Radix1Tree a
r)
{-# INLINE splitLookup_ #-}
splitLookup_
:: (x -> Step Word8 x)
-> Word8 -> x -> Radix1Tree a -> (# Radix1Tree a, Maybe a, Radix1Tree a #)
splitLookup_ :: forall x a.
(x -> Step Prefix x)
-> Prefix
-> x
-> Radix1Tree a
-> (# Radix1Tree a, Maybe a, Radix1Tree a #)
splitLookup_ x -> Step Prefix x
step = Prefix
-> x -> Radix1Tree a -> (# Radix1Tree a, Maybe a, Radix1Tree a #)
go
where
go :: Prefix
-> x -> Radix1Tree a -> (# Radix1Tree a, Maybe a, Radix1Tree a #)
go Prefix
w x
s Radix1Tree a
t =
case Radix1Tree a
t of
Bin Prefix
p Radix1Tree a
l Radix1Tree a
r ->
if Prefix
w Prefix -> Prefix -> Bool
forall a. Ord a => a -> a -> Bool
< Prefix
p
then if Prefix
w Prefix -> Prefix -> Bool
forall a. Ord a => a -> a -> Bool
>= Prefix -> Prefix
lower Prefix
p
then let !(# Radix1Tree a
ll, Maybe a
my, Radix1Tree a
lr #) = Prefix
-> x -> Radix1Tree a -> (# Radix1Tree a, Maybe a, Radix1Tree a #)
go Prefix
w x
s Radix1Tree a
l
in (# Radix1Tree a
ll, Maybe a
my, Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
forall a. Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
rebinL Prefix
p Radix1Tree a
lr Radix1Tree a
r #)
else (# Radix1Tree a
forall a. Radix1Tree a
Nil, Maybe a
forall a. Maybe a
Nothing, Radix1Tree a
t #)
else if Prefix
w Prefix -> Prefix -> Bool
forall a. Ord a => a -> a -> Bool
<= Prefix -> Prefix
upper Prefix
p
then let !(# Radix1Tree a
rl, Maybe a
my, Radix1Tree a
rr #) = Prefix
-> x -> Radix1Tree a -> (# Radix1Tree a, Maybe a, Radix1Tree a #)
go Prefix
w x
s Radix1Tree a
r
in (# Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
forall a. Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
rebinR Prefix
p Radix1Tree a
l Radix1Tree a
rl, Maybe a
my, Radix1Tree a
rr #)
else (# Radix1Tree a
t, Maybe a
forall a. Maybe a
Nothing, Radix1Tree a
forall a. Radix1Tree a
Nil #)
Tip ByteArray
arr Maybe a
mx Radix1Tree a
dx -> Prefix -> x -> Int -> (# Radix1Tree a, Maybe a, Radix1Tree a #)
goarr Prefix
w x
s Int
0
where
goarr :: Prefix -> x -> Int -> (# Radix1Tree a, Maybe a, Radix1Tree a #)
goarr Prefix
v x
z Int
n =
let n' :: Int
n' = Int
n Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1
in case ByteArray -> Int -> Prefix
forall a. Prim a => ByteArray -> Int -> a
indexByteArray ByteArray
arr Int
n Prefix -> Prefix -> Ordering
forall a. Ord a => a -> a -> Ordering
`compare` Prefix
v of
Ordering
EQ | Int
n' Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= ByteArray -> Int
sizeofByteArray ByteArray
arr ->
case x -> Step Prefix x
step x
z of
More Prefix
u x
z' ->
let !(# Radix1Tree a
dl, Maybe a
my, Radix1Tree a
dr #) = Prefix
-> x -> Radix1Tree a -> (# Radix1Tree a, Maybe a, Radix1Tree a #)
go Prefix
u x
z' Radix1Tree a
dx
in (# ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
retip ByteArray
arr Maybe a
mx Radix1Tree a
dl, Maybe a
my, ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
retip ByteArray
arr Maybe a
forall a. Maybe a
Nothing Radix1Tree a
dr #)
Step Prefix x
Done ->
(# Radix1Tree a
forall a. Radix1Tree a
Nil, Maybe a
mx, ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
retip ByteArray
arr Maybe a
forall a. Maybe a
Nothing Radix1Tree a
dx #)
| Bool
otherwise ->
case x -> Step Prefix x
step x
z of
More Prefix
u x
z' -> Prefix -> x -> Int -> (# Radix1Tree a, Maybe a, Radix1Tree a #)
goarr Prefix
u x
z' Int
n'
Step Prefix x
Done -> (# Radix1Tree a
forall a. Radix1Tree a
Nil, Maybe a
forall a. Maybe a
Nothing, Radix1Tree a
t #)
Ordering
LT -> (# Radix1Tree a
t, Maybe a
forall a. Maybe a
Nothing, Radix1Tree a
forall a. Radix1Tree a
Nil #)
Ordering
GT -> (# Radix1Tree a
forall a. Radix1Tree a
Nil, Maybe a
forall a. Maybe a
Nothing, Radix1Tree a
t #)
Radix1Tree a
Nil -> (# Radix1Tree a
forall a. Radix1Tree a
Nil, Maybe a
forall a. Maybe a
Nothing, Radix1Tree a
forall a. Radix1Tree a
Nil #)
{-# INLINE filterMaybe #-}
filterMaybe :: (a -> Bool) -> Maybe a -> Maybe a
filterMaybe :: forall a. (a -> Bool) -> Maybe a -> Maybe a
filterMaybe a -> Bool
f Maybe a
mx =
case Maybe a
mx of
Just a
x | a -> Bool
f a
x -> a -> Maybe a
forall a. a -> Maybe a
Just a
x
Maybe a
_ -> Maybe a
forall a. Maybe a
Nothing
filter0 :: (a -> Bool) -> RadixTree a -> RadixTree a
filter0 :: forall a. (a -> Bool) -> RadixTree a -> RadixTree a
filter0 a -> Bool
f (RadixTree Maybe a
mx Radix1Tree a
t) = Maybe a -> Radix1Tree a -> RadixTree a
forall a. Maybe a -> Radix1Tree a -> RadixTree a
RadixTree ((a -> Bool) -> Maybe a -> Maybe a
forall a. (a -> Bool) -> Maybe a -> Maybe a
filterMaybe a -> Bool
f Maybe a
mx) ((a -> Bool) -> Radix1Tree a -> Radix1Tree a
forall a. (a -> Bool) -> Radix1Tree a -> Radix1Tree a
filter1 a -> Bool
f Radix1Tree a
t)
filter1 :: (a -> Bool) -> Radix1Tree a -> Radix1Tree a
filter1 :: forall a. (a -> Bool) -> Radix1Tree a -> Radix1Tree a
filter1 a -> Bool
f = Radix1Tree a -> Radix1Tree a
go
where
go :: Radix1Tree a -> Radix1Tree a
go Radix1Tree a
t =
case Radix1Tree a
t of
Bin Prefix
p Radix1Tree a
l Radix1Tree a
r -> Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
forall a. Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
rebin Prefix
p (Radix1Tree a -> Radix1Tree a
go Radix1Tree a
l) (Radix1Tree a -> Radix1Tree a
go Radix1Tree a
r)
Tip ByteArray
arr Maybe a
mx Radix1Tree a
dx -> ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
retip ByteArray
arr ((a -> Bool) -> Maybe a -> Maybe a
forall a. (a -> Bool) -> Maybe a -> Maybe a
filterMaybe a -> Bool
f Maybe a
mx) (Radix1Tree a -> Radix1Tree a
go Radix1Tree a
dx)
Radix1Tree a
Nil -> Radix1Tree a
forall a. Radix1Tree a
Nil
filterWithKey0 :: (Build -> a -> Bool) -> RadixTree a -> RadixTree a
filterWithKey0 :: forall a. (Build -> a -> Bool) -> RadixTree a -> RadixTree a
filterWithKey0 Build -> a -> Bool
f (RadixTree Maybe a
mx Radix1Tree a
t) =
Maybe a -> Radix1Tree a -> RadixTree a
forall a. Maybe a -> Radix1Tree a -> RadixTree a
RadixTree ((a -> Bool) -> Maybe a -> Maybe a
forall a. (a -> Bool) -> Maybe a -> Maybe a
filterMaybe (Build -> a -> Bool
f (Tsil ByteArray -> Build
Build Tsil ByteArray
forall a. Tsil a
Lin)) Maybe a
mx) (Radix1Tree a -> RadixTree a) -> Radix1Tree a -> RadixTree a
forall a b. (a -> b) -> a -> b
$
(Tsil ByteArray -> ByteArray -> a -> Bool)
-> Radix1Tree a -> Radix1Tree a
forall a.
(Tsil ByteArray -> ByteArray -> a -> Bool)
-> Radix1Tree a -> Radix1Tree a
filterWithKey_ (\Tsil ByteArray
b ByteArray
arr -> Build -> a -> Bool
f (Tsil ByteArray -> Build
Build (Tsil ByteArray -> Build) -> Tsil ByteArray -> Build
forall a b. (a -> b) -> a -> b
$ Tsil ByteArray -> ByteArray -> Tsil ByteArray
forall a. Tsil a -> a -> Tsil a
Snoc Tsil ByteArray
b ByteArray
arr)) Radix1Tree a
t
filterWithKey1 :: (Build1 -> a -> Bool) -> Radix1Tree a -> Radix1Tree a
filterWithKey1 :: forall a. (Build1 -> a -> Bool) -> Radix1Tree a -> Radix1Tree a
filterWithKey1 Build1 -> a -> Bool
f = (Tsil ByteArray -> ByteArray -> a -> Bool)
-> Radix1Tree a -> Radix1Tree a
forall a.
(Tsil ByteArray -> ByteArray -> a -> Bool)
-> Radix1Tree a -> Radix1Tree a
filterWithKey_ (\Tsil ByteArray
b ByteArray
arr -> Build1 -> a -> Bool
f (YtpmeNon ByteArray -> Build1
Build1 (YtpmeNon ByteArray -> Build1) -> YtpmeNon ByteArray -> Build1
forall a b. (a -> b) -> a -> b
$ Tsil ByteArray
b Tsil ByteArray -> ByteArray -> YtpmeNon ByteArray
forall a. Tsil a -> a -> YtpmeNon a
:/ ByteArray
arr))
{-# INLINE filterWithKey_ #-}
filterWithKey_
:: (Tsil ByteArray -> ByteArray -> a -> Bool) -> Radix1Tree a -> Radix1Tree a
filterWithKey_ :: forall a.
(Tsil ByteArray -> ByteArray -> a -> Bool)
-> Radix1Tree a -> Radix1Tree a
filterWithKey_ Tsil ByteArray -> ByteArray -> a -> Bool
f = Tsil ByteArray -> Radix1Tree a -> Radix1Tree a
go Tsil ByteArray
forall a. Tsil a
Lin
where
go :: Tsil ByteArray -> Radix1Tree a -> Radix1Tree a
go Tsil ByteArray
b Radix1Tree a
t =
case Radix1Tree a
t of
Bin Prefix
p Radix1Tree a
l Radix1Tree a
r -> Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
forall a. Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
rebin Prefix
p (Tsil ByteArray -> Radix1Tree a -> Radix1Tree a
go Tsil ByteArray
b Radix1Tree a
l) (Tsil ByteArray -> Radix1Tree a -> Radix1Tree a
go Tsil ByteArray
b Radix1Tree a
r)
Tip ByteArray
arr Maybe a
mx Radix1Tree a
dx -> ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
retip ByteArray
arr ((a -> Bool) -> Maybe a -> Maybe a
forall a. (a -> Bool) -> Maybe a -> Maybe a
filterMaybe (Tsil ByteArray -> ByteArray -> a -> Bool
f Tsil ByteArray
b ByteArray
arr) Maybe a
mx) (Tsil ByteArray -> Radix1Tree a -> Radix1Tree a
go (Tsil ByteArray -> ByteArray -> Tsil ByteArray
forall a. Tsil a -> a -> Tsil a
Snoc Tsil ByteArray
b ByteArray
arr) Radix1Tree a
dx)
Radix1Tree a
Nil -> Radix1Tree a
forall a. Radix1Tree a
Nil
mapMaybe0 :: (a -> Maybe b) -> RadixTree a -> RadixTree b
mapMaybe0 :: forall a b. (a -> Maybe b) -> RadixTree a -> RadixTree b
mapMaybe0 a -> Maybe b
f (RadixTree Maybe a
mx Radix1Tree a
t) = Maybe b -> Radix1Tree b -> RadixTree b
forall a. Maybe a -> Radix1Tree a -> RadixTree a
RadixTree (a -> Maybe b
f (a -> Maybe b) -> Maybe a -> Maybe b
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Maybe a
mx) ((a -> Maybe b) -> Radix1Tree a -> Radix1Tree b
forall a b. (a -> Maybe b) -> Radix1Tree a -> Radix1Tree b
mapMaybe1 a -> Maybe b
f Radix1Tree a
t)
mapMaybe1 :: (a -> Maybe b) -> Radix1Tree a -> Radix1Tree b
mapMaybe1 :: forall a b. (a -> Maybe b) -> Radix1Tree a -> Radix1Tree b
mapMaybe1 a -> Maybe b
f = Radix1Tree a -> Radix1Tree b
go
where
go :: Radix1Tree a -> Radix1Tree b
go Radix1Tree a
t =
case Radix1Tree a
t of
Bin Prefix
p Radix1Tree a
l Radix1Tree a
r -> Prefix -> Radix1Tree b -> Radix1Tree b -> Radix1Tree b
forall a. Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
rebin Prefix
p (Radix1Tree a -> Radix1Tree b
go Radix1Tree a
l) (Radix1Tree a -> Radix1Tree b
go Radix1Tree a
r)
Tip ByteArray
arr Maybe a
mx Radix1Tree a
dx -> ByteArray -> Maybe b -> Radix1Tree b -> Radix1Tree b
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
retip ByteArray
arr (a -> Maybe b
f (a -> Maybe b) -> Maybe a -> Maybe b
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Maybe a
mx) (Radix1Tree a -> Radix1Tree b
go Radix1Tree a
dx)
Radix1Tree a
Nil -> Radix1Tree b
forall a. Radix1Tree a
Nil
mapMaybeWithKey0 :: (Build -> a -> Maybe b) -> RadixTree a -> RadixTree b
mapMaybeWithKey0 :: forall a b. (Build -> a -> Maybe b) -> RadixTree a -> RadixTree b
mapMaybeWithKey0 Build -> a -> Maybe b
f (RadixTree Maybe a
mx Radix1Tree a
t) =
Maybe b -> Radix1Tree b -> RadixTree b
forall a. Maybe a -> Radix1Tree a -> RadixTree a
RadixTree (Build -> a -> Maybe b
f (Tsil ByteArray -> Build
Build Tsil ByteArray
forall a. Tsil a
Lin) (a -> Maybe b) -> Maybe a -> Maybe b
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Maybe a
mx) (Radix1Tree b -> RadixTree b) -> Radix1Tree b -> RadixTree b
forall a b. (a -> b) -> a -> b
$
(Tsil ByteArray -> ByteArray -> a -> Maybe b)
-> Tsil ByteArray -> Radix1Tree a -> Radix1Tree b
forall a b.
(Tsil ByteArray -> ByteArray -> a -> Maybe b)
-> Tsil ByteArray -> Radix1Tree a -> Radix1Tree b
mapMaybeWithKey_ (\Tsil ByteArray
b ByteArray
arr -> Build -> a -> Maybe b
f (Tsil ByteArray -> Build
Build (Tsil ByteArray -> Build) -> Tsil ByteArray -> Build
forall a b. (a -> b) -> a -> b
$ Tsil ByteArray -> ByteArray -> Tsil ByteArray
forall a. Tsil a -> a -> Tsil a
Snoc Tsil ByteArray
b ByteArray
arr)) Tsil ByteArray
forall a. Tsil a
Lin Radix1Tree a
t
mapMaybeWithKey1 :: (Build1 -> a -> Maybe b) -> Radix1Tree a -> Radix1Tree b
mapMaybeWithKey1 :: forall a b.
(Build1 -> a -> Maybe b) -> Radix1Tree a -> Radix1Tree b
mapMaybeWithKey1 Build1 -> a -> Maybe b
f = (Tsil ByteArray -> ByteArray -> a -> Maybe b)
-> Tsil ByteArray -> Radix1Tree a -> Radix1Tree b
forall a b.
(Tsil ByteArray -> ByteArray -> a -> Maybe b)
-> Tsil ByteArray -> Radix1Tree a -> Radix1Tree b
mapMaybeWithKey_ (\Tsil ByteArray
b ByteArray
arr -> Build1 -> a -> Maybe b
f (YtpmeNon ByteArray -> Build1
Build1 (YtpmeNon ByteArray -> Build1) -> YtpmeNon ByteArray -> Build1
forall a b. (a -> b) -> a -> b
$ Tsil ByteArray
b Tsil ByteArray -> ByteArray -> YtpmeNon ByteArray
forall a. Tsil a -> a -> YtpmeNon a
:/ ByteArray
arr)) Tsil ByteArray
forall a. Tsil a
Lin
{-# INLINE mapMaybeWithKey_ #-}
mapMaybeWithKey_
:: (Tsil ByteArray -> ByteArray -> a -> Maybe b) -> Tsil ByteArray
-> Radix1Tree a -> Radix1Tree b
mapMaybeWithKey_ :: forall a b.
(Tsil ByteArray -> ByteArray -> a -> Maybe b)
-> Tsil ByteArray -> Radix1Tree a -> Radix1Tree b
mapMaybeWithKey_ Tsil ByteArray -> ByteArray -> a -> Maybe b
f = Tsil ByteArray -> Radix1Tree a -> Radix1Tree b
go
where
go :: Tsil ByteArray -> Radix1Tree a -> Radix1Tree b
go Tsil ByteArray
b Radix1Tree a
t =
case Radix1Tree a
t of
Bin Prefix
p Radix1Tree a
l Radix1Tree a
r -> Prefix -> Radix1Tree b -> Radix1Tree b -> Radix1Tree b
forall a. Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
rebin Prefix
p (Tsil ByteArray -> Radix1Tree a -> Radix1Tree b
go Tsil ByteArray
b Radix1Tree a
l) (Tsil ByteArray -> Radix1Tree a -> Radix1Tree b
go Tsil ByteArray
b Radix1Tree a
r)
Tip ByteArray
arr Maybe a
mx Radix1Tree a
dx -> ByteArray -> Maybe b -> Radix1Tree b -> Radix1Tree b
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
retip ByteArray
arr (Tsil ByteArray -> ByteArray -> a -> Maybe b
f Tsil ByteArray
b ByteArray
arr (a -> Maybe b) -> Maybe a -> Maybe b
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Maybe a
mx) (Tsil ByteArray -> Radix1Tree a -> Radix1Tree b
go (Tsil ByteArray -> ByteArray -> Tsil ByteArray
forall a. Tsil a -> a -> Tsil a
Snoc Tsil ByteArray
b ByteArray
arr) Radix1Tree a
dx)
Radix1Tree a
Nil -> Radix1Tree b
forall a. Radix1Tree a
Nil
partition0 :: (a -> Bool) -> RadixTree a -> (RadixTree a, RadixTree a)
partition0 :: forall a. (a -> Bool) -> RadixTree a -> (RadixTree a, RadixTree a)
partition0 a -> Bool
f = \(RadixTree Maybe a
mx Radix1Tree a
t) ->
let !(# Radix1Tree a
l, Radix1Tree a
r #) = (a -> Bool) -> Radix1Tree a -> (# Radix1Tree a, Radix1Tree a #)
forall a.
(a -> Bool) -> Radix1Tree a -> (# Radix1Tree a, Radix1Tree a #)
partition_ a -> Bool
f Radix1Tree a
t
!(# Maybe a
my, Maybe a
mz #) =
case Maybe a
mx of
Just a
x
| a -> Bool
f a
x -> (# Maybe a
mx , Maybe a
forall a. Maybe a
Nothing #)
| Bool
otherwise -> (# Maybe a
forall a. Maybe a
Nothing, Maybe a
mx #)
Maybe a
Nothing -> (# Maybe a
forall a. Maybe a
Nothing, Maybe a
forall a. Maybe a
Nothing #)
in (Maybe a -> Radix1Tree a -> RadixTree a
forall a. Maybe a -> Radix1Tree a -> RadixTree a
RadixTree Maybe a
my Radix1Tree a
l, Maybe a -> Radix1Tree a -> RadixTree a
forall a. Maybe a -> Radix1Tree a -> RadixTree a
RadixTree Maybe a
mz Radix1Tree a
r)
partition1 :: (a -> Bool) -> Radix1Tree a -> (Radix1Tree a, Radix1Tree a)
partition1 :: forall a.
(a -> Bool) -> Radix1Tree a -> (Radix1Tree a, Radix1Tree a)
partition1 a -> Bool
f = \Radix1Tree a
t ->
case (a -> Bool) -> Radix1Tree a -> (# Radix1Tree a, Radix1Tree a #)
forall a.
(a -> Bool) -> Radix1Tree a -> (# Radix1Tree a, Radix1Tree a #)
partition_ a -> Bool
f Radix1Tree a
t of
(# Radix1Tree a
l, Radix1Tree a
r #) -> (Radix1Tree a
l, Radix1Tree a
r)
partition_ :: (a -> Bool) -> Radix1Tree a -> (# Radix1Tree a, Radix1Tree a #)
partition_ :: forall a.
(a -> Bool) -> Radix1Tree a -> (# Radix1Tree a, Radix1Tree a #)
partition_ a -> Bool
f = Radix1Tree a -> (# Radix1Tree a, Radix1Tree a #)
go
where
go :: Radix1Tree a -> (# Radix1Tree a, Radix1Tree a #)
go Radix1Tree a
t =
case Radix1Tree a
t of
Bin Prefix
p Radix1Tree a
l Radix1Tree a
r ->
let !(# Radix1Tree a
ly, Radix1Tree a
lz #) = Radix1Tree a -> (# Radix1Tree a, Radix1Tree a #)
go Radix1Tree a
l
!(# Radix1Tree a
ry, Radix1Tree a
rz #) = Radix1Tree a -> (# Radix1Tree a, Radix1Tree a #)
go Radix1Tree a
r
in (# Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
forall a. Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
rebin Prefix
p Radix1Tree a
ly Radix1Tree a
ry, Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
forall a. Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
rebin Prefix
p Radix1Tree a
lz Radix1Tree a
rz #)
Tip ByteArray
arr Maybe a
mx Radix1Tree a
dx ->
let !(# Radix1Tree a
dy, Radix1Tree a
dz #) = Radix1Tree a -> (# Radix1Tree a, Radix1Tree a #)
go Radix1Tree a
dx
in case Maybe a
mx of
Maybe a
Nothing -> (# ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
retip ByteArray
arr Maybe a
forall a. Maybe a
Nothing Radix1Tree a
dy, ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
retip ByteArray
arr Maybe a
forall a. Maybe a
Nothing Radix1Tree a
dz #)
Just a
x ->
if a -> Bool
f a
x
then (# ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
Tip ByteArray
arr (a -> Maybe a
forall a. a -> Maybe a
Just a
x) Radix1Tree a
dy, ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
retip ByteArray
arr Maybe a
forall a. Maybe a
Nothing Radix1Tree a
dz #)
else (# ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
retip ByteArray
arr Maybe a
forall a. Maybe a
Nothing Radix1Tree a
dy, ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
Tip ByteArray
arr (a -> Maybe a
forall a. a -> Maybe a
Just a
x) Radix1Tree a
dz #)
Radix1Tree a
Nil -> (# Radix1Tree a
forall a. Radix1Tree a
Nil, Radix1Tree a
forall a. Radix1Tree a
Nil #)
partitionWithKey0 :: (Build -> a -> Bool) -> RadixTree a -> (RadixTree a, RadixTree a)
partitionWithKey0 :: forall a.
(Build -> a -> Bool) -> RadixTree a -> (RadixTree a, RadixTree a)
partitionWithKey0 Build -> a -> Bool
f = \(RadixTree Maybe a
mx Radix1Tree a
t) ->
let !(# Radix1Tree a
l, Radix1Tree a
r #) = (Tsil ByteArray -> ByteArray -> a -> Bool)
-> Radix1Tree a -> (# Radix1Tree a, Radix1Tree a #)
forall a.
(Tsil ByteArray -> ByteArray -> a -> Bool)
-> Radix1Tree a -> (# Radix1Tree a, Radix1Tree a #)
partitionWithKey_ (\Tsil ByteArray
b ByteArray
arr -> Build -> a -> Bool
f (Tsil ByteArray -> Build
Build (Tsil ByteArray -> Build) -> Tsil ByteArray -> Build
forall a b. (a -> b) -> a -> b
$ Tsil ByteArray -> ByteArray -> Tsil ByteArray
forall a. Tsil a -> a -> Tsil a
Snoc Tsil ByteArray
b ByteArray
arr)) Radix1Tree a
t
!(# Maybe a
my, Maybe a
mz #) =
case Maybe a
mx of
Just a
x
| Build -> a -> Bool
f (Tsil ByteArray -> Build
Build Tsil ByteArray
forall a. Tsil a
Lin) a
x -> (# Maybe a
mx , Maybe a
forall a. Maybe a
Nothing #)
| Bool
otherwise -> (# Maybe a
forall a. Maybe a
Nothing, Maybe a
mx #)
Maybe a
Nothing -> (# Maybe a
forall a. Maybe a
Nothing, Maybe a
forall a. Maybe a
Nothing #)
in (Maybe a -> Radix1Tree a -> RadixTree a
forall a. Maybe a -> Radix1Tree a -> RadixTree a
RadixTree Maybe a
my Radix1Tree a
l, Maybe a -> Radix1Tree a -> RadixTree a
forall a. Maybe a -> Radix1Tree a -> RadixTree a
RadixTree Maybe a
mz Radix1Tree a
r)
partitionWithKey1 :: (Build1 -> a -> Bool) -> Radix1Tree a -> (Radix1Tree a, Radix1Tree a)
partitionWithKey1 :: forall a.
(Build1 -> a -> Bool)
-> Radix1Tree a -> (Radix1Tree a, Radix1Tree a)
partitionWithKey1 Build1 -> a -> Bool
f = \Radix1Tree a
t ->
case (Tsil ByteArray -> ByteArray -> a -> Bool)
-> Radix1Tree a -> (# Radix1Tree a, Radix1Tree a #)
forall a.
(Tsil ByteArray -> ByteArray -> a -> Bool)
-> Radix1Tree a -> (# Radix1Tree a, Radix1Tree a #)
partitionWithKey_ (\Tsil ByteArray
b ByteArray
arr -> Build1 -> a -> Bool
f (YtpmeNon ByteArray -> Build1
Build1 (YtpmeNon ByteArray -> Build1) -> YtpmeNon ByteArray -> Build1
forall a b. (a -> b) -> a -> b
$ Tsil ByteArray
b Tsil ByteArray -> ByteArray -> YtpmeNon ByteArray
forall a. Tsil a -> a -> YtpmeNon a
:/ ByteArray
arr)) Radix1Tree a
t of
(# !Radix1Tree a
l, !Radix1Tree a
r #) -> (Radix1Tree a
l, Radix1Tree a
r)
{-# INLINE partitionWithKey_ #-}
partitionWithKey_
:: (Tsil ByteArray -> ByteArray -> a -> Bool)
-> Radix1Tree a -> (# Radix1Tree a, Radix1Tree a #)
partitionWithKey_ :: forall a.
(Tsil ByteArray -> ByteArray -> a -> Bool)
-> Radix1Tree a -> (# Radix1Tree a, Radix1Tree a #)
partitionWithKey_ Tsil ByteArray -> ByteArray -> a -> Bool
f = Tsil ByteArray -> Radix1Tree a -> (# Radix1Tree a, Radix1Tree a #)
go Tsil ByteArray
forall a. Tsil a
Lin
where
go :: Tsil ByteArray -> Radix1Tree a -> (# Radix1Tree a, Radix1Tree a #)
go Tsil ByteArray
b Radix1Tree a
t =
case Radix1Tree a
t of
Bin Prefix
p Radix1Tree a
l Radix1Tree a
r ->
let !(# Radix1Tree a
ly, Radix1Tree a
lz #) = Tsil ByteArray -> Radix1Tree a -> (# Radix1Tree a, Radix1Tree a #)
go Tsil ByteArray
b Radix1Tree a
l
!(# Radix1Tree a
ry, Radix1Tree a
rz #) = Tsil ByteArray -> Radix1Tree a -> (# Radix1Tree a, Radix1Tree a #)
go Tsil ByteArray
b Radix1Tree a
r
in (# Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
forall a. Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
rebin Prefix
p Radix1Tree a
ly Radix1Tree a
ry, Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
forall a. Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
rebin Prefix
p Radix1Tree a
lz Radix1Tree a
rz #)
Tip ByteArray
arr Maybe a
mx Radix1Tree a
dx ->
let !(# Radix1Tree a
dy, Radix1Tree a
dz #) = Tsil ByteArray -> Radix1Tree a -> (# Radix1Tree a, Radix1Tree a #)
go (Tsil ByteArray -> ByteArray -> Tsil ByteArray
forall a. Tsil a -> a -> Tsil a
Snoc Tsil ByteArray
b ByteArray
arr) Radix1Tree a
dx
in case Maybe a
mx of
Maybe a
Nothing -> (# ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
retip ByteArray
arr Maybe a
forall a. Maybe a
Nothing Radix1Tree a
dy, ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
retip ByteArray
arr Maybe a
forall a. Maybe a
Nothing Radix1Tree a
dz #)
Just a
x ->
if Tsil ByteArray -> ByteArray -> a -> Bool
f Tsil ByteArray
b ByteArray
arr a
x
then (# ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
Tip ByteArray
arr (a -> Maybe a
forall a. a -> Maybe a
Just a
x) Radix1Tree a
dy, ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
retip ByteArray
arr Maybe a
forall a. Maybe a
Nothing Radix1Tree a
dz #)
else (# ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
retip ByteArray
arr Maybe a
forall a. Maybe a
Nothing Radix1Tree a
dy, ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
Tip ByteArray
arr (a -> Maybe a
forall a. a -> Maybe a
Just a
x) Radix1Tree a
dz #)
Radix1Tree a
Nil -> (# Radix1Tree a
forall a. Radix1Tree a
Nil, Radix1Tree a
forall a. Radix1Tree a
Nil #)
mapEither0 :: (a -> Either b c) -> RadixTree a -> (RadixTree b, RadixTree c)
mapEither0 :: forall a b c.
(a -> Either b c) -> RadixTree a -> (RadixTree b, RadixTree c)
mapEither0 a -> Either b c
f = \(RadixTree Maybe a
mx Radix1Tree a
t) ->
let !(# Radix1Tree b
l, Radix1Tree c
r #) = (a -> Either b c)
-> Radix1Tree a -> (# Radix1Tree b, Radix1Tree c #)
forall a b c.
(a -> Either b c)
-> Radix1Tree a -> (# Radix1Tree b, Radix1Tree c #)
mapEither_ a -> Either b c
f Radix1Tree a
t
!(# Maybe b
my, Maybe c
mz #) =
case Maybe a
mx of
Just a
x ->
case a -> Either b c
f a
x of
Left b
y -> (# b -> Maybe b
forall a. a -> Maybe a
Just b
y , Maybe c
forall a. Maybe a
Nothing #)
Right c
z -> (# Maybe b
forall a. Maybe a
Nothing, c -> Maybe c
forall a. a -> Maybe a
Just c
z #)
Maybe a
Nothing -> (# Maybe b
forall a. Maybe a
Nothing, Maybe c
forall a. Maybe a
Nothing #)
in (Maybe b -> Radix1Tree b -> RadixTree b
forall a. Maybe a -> Radix1Tree a -> RadixTree a
RadixTree Maybe b
my Radix1Tree b
l, Maybe c -> Radix1Tree c -> RadixTree c
forall a. Maybe a -> Radix1Tree a -> RadixTree a
RadixTree Maybe c
mz Radix1Tree c
r)
mapEither1 :: (a -> Either b c) -> Radix1Tree a -> (Radix1Tree b, Radix1Tree c)
mapEither1 :: forall a b c.
(a -> Either b c) -> Radix1Tree a -> (Radix1Tree b, Radix1Tree c)
mapEither1 a -> Either b c
f = \Radix1Tree a
t ->
case (a -> Either b c)
-> Radix1Tree a -> (# Radix1Tree b, Radix1Tree c #)
forall a b c.
(a -> Either b c)
-> Radix1Tree a -> (# Radix1Tree b, Radix1Tree c #)
mapEither_ a -> Either b c
f Radix1Tree a
t of
(# Radix1Tree b
l, Radix1Tree c
r #) -> (Radix1Tree b
l, Radix1Tree c
r)
mapEither_ :: (a -> Either b c) -> Radix1Tree a -> (# Radix1Tree b, Radix1Tree c #)
mapEither_ :: forall a b c.
(a -> Either b c)
-> Radix1Tree a -> (# Radix1Tree b, Radix1Tree c #)
mapEither_ a -> Either b c
f = Radix1Tree a -> (# Radix1Tree b, Radix1Tree c #)
go
where
go :: Radix1Tree a -> (# Radix1Tree b, Radix1Tree c #)
go Radix1Tree a
t =
case Radix1Tree a
t of
Bin Prefix
p Radix1Tree a
l Radix1Tree a
r ->
let !(# Radix1Tree b
ly, Radix1Tree c
lz #) = Radix1Tree a -> (# Radix1Tree b, Radix1Tree c #)
go Radix1Tree a
l
!(# Radix1Tree b
ry, Radix1Tree c
rz #) = Radix1Tree a -> (# Radix1Tree b, Radix1Tree c #)
go Radix1Tree a
r
in (# Prefix -> Radix1Tree b -> Radix1Tree b -> Radix1Tree b
forall a. Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
rebin Prefix
p Radix1Tree b
ly Radix1Tree b
ry, Prefix -> Radix1Tree c -> Radix1Tree c -> Radix1Tree c
forall a. Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
rebin Prefix
p Radix1Tree c
lz Radix1Tree c
rz #)
Tip ByteArray
arr Maybe a
mx Radix1Tree a
dx ->
let !(# Radix1Tree b
dy, Radix1Tree c
dz #) = Radix1Tree a -> (# Radix1Tree b, Radix1Tree c #)
go Radix1Tree a
dx
in case Maybe a
mx of
Maybe a
Nothing -> (# ByteArray -> Maybe b -> Radix1Tree b -> Radix1Tree b
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
retip ByteArray
arr Maybe b
forall a. Maybe a
Nothing Radix1Tree b
dy, ByteArray -> Maybe c -> Radix1Tree c -> Radix1Tree c
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
retip ByteArray
arr Maybe c
forall a. Maybe a
Nothing Radix1Tree c
dz #)
Just a
x ->
case a -> Either b c
f a
x of
Left b
y -> (# ByteArray -> Maybe b -> Radix1Tree b -> Radix1Tree b
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
Tip ByteArray
arr (b -> Maybe b
forall a. a -> Maybe a
Just b
y) Radix1Tree b
dy, ByteArray -> Maybe c -> Radix1Tree c -> Radix1Tree c
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
retip ByteArray
arr Maybe c
forall a. Maybe a
Nothing Radix1Tree c
dz #)
Right c
z -> (# ByteArray -> Maybe b -> Radix1Tree b -> Radix1Tree b
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
retip ByteArray
arr Maybe b
forall a. Maybe a
Nothing Radix1Tree b
dy, ByteArray -> Maybe c -> Radix1Tree c -> Radix1Tree c
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
Tip ByteArray
arr (c -> Maybe c
forall a. a -> Maybe a
Just c
z) Radix1Tree c
dz #)
Radix1Tree a
Nil -> (# Radix1Tree b
forall a. Radix1Tree a
Nil, Radix1Tree c
forall a. Radix1Tree a
Nil #)
mapEitherWithKey0
:: (Build -> a -> Either b c) -> RadixTree a -> (RadixTree b, RadixTree c)
mapEitherWithKey0 :: forall a b c.
(Build -> a -> Either b c)
-> RadixTree a -> (RadixTree b, RadixTree c)
mapEitherWithKey0 Build -> a -> Either b c
f = \(RadixTree Maybe a
mx Radix1Tree a
t) ->
let !(# Radix1Tree b
l, Radix1Tree c
r #) = (Tsil ByteArray -> ByteArray -> a -> Either b c)
-> Radix1Tree a -> (# Radix1Tree b, Radix1Tree c #)
forall a b c.
(Tsil ByteArray -> ByteArray -> a -> Either b c)
-> Radix1Tree a -> (# Radix1Tree b, Radix1Tree c #)
mapEitherWithKey_ (\Tsil ByteArray
b ByteArray
arr -> Build -> a -> Either b c
f (Tsil ByteArray -> Build
Build (Tsil ByteArray -> Build) -> Tsil ByteArray -> Build
forall a b. (a -> b) -> a -> b
$ Tsil ByteArray -> ByteArray -> Tsil ByteArray
forall a. Tsil a -> a -> Tsil a
Snoc Tsil ByteArray
b ByteArray
arr)) Radix1Tree a
t
!(# Maybe b
my, Maybe c
mz #) =
case Maybe a
mx of
Just a
x ->
case Build -> a -> Either b c
f (Tsil ByteArray -> Build
Build Tsil ByteArray
forall a. Tsil a
Lin) a
x of
Left b
y -> (# b -> Maybe b
forall a. a -> Maybe a
Just b
y , Maybe c
forall a. Maybe a
Nothing #)
Right c
z -> (# Maybe b
forall a. Maybe a
Nothing, c -> Maybe c
forall a. a -> Maybe a
Just c
z #)
Maybe a
Nothing -> (# Maybe b
forall a. Maybe a
Nothing, Maybe c
forall a. Maybe a
Nothing #)
in (Maybe b -> Radix1Tree b -> RadixTree b
forall a. Maybe a -> Radix1Tree a -> RadixTree a
RadixTree Maybe b
my Radix1Tree b
l, Maybe c -> Radix1Tree c -> RadixTree c
forall a. Maybe a -> Radix1Tree a -> RadixTree a
RadixTree Maybe c
mz Radix1Tree c
r)
mapEitherWithKey1
:: (Build1 -> a -> Either b c) -> Radix1Tree a -> (Radix1Tree b, Radix1Tree c)
mapEitherWithKey1 :: forall a b c.
(Build1 -> a -> Either b c)
-> Radix1Tree a -> (Radix1Tree b, Radix1Tree c)
mapEitherWithKey1 Build1 -> a -> Either b c
f = \Radix1Tree a
t ->
case (Tsil ByteArray -> ByteArray -> a -> Either b c)
-> Radix1Tree a -> (# Radix1Tree b, Radix1Tree c #)
forall a b c.
(Tsil ByteArray -> ByteArray -> a -> Either b c)
-> Radix1Tree a -> (# Radix1Tree b, Radix1Tree c #)
mapEitherWithKey_ (\Tsil ByteArray
b ByteArray
arr -> Build1 -> a -> Either b c
f (YtpmeNon ByteArray -> Build1
Build1 (YtpmeNon ByteArray -> Build1) -> YtpmeNon ByteArray -> Build1
forall a b. (a -> b) -> a -> b
$ Tsil ByteArray
b Tsil ByteArray -> ByteArray -> YtpmeNon ByteArray
forall a. Tsil a -> a -> YtpmeNon a
:/ ByteArray
arr)) Radix1Tree a
t of
(# Radix1Tree b
l, Radix1Tree c
r #) -> (Radix1Tree b
l, Radix1Tree c
r)
{-# INLINE mapEitherWithKey_ #-}
mapEitherWithKey_
:: (Tsil ByteArray -> ByteArray -> a -> Either b c)
-> Radix1Tree a -> (# Radix1Tree b, Radix1Tree c #)
mapEitherWithKey_ :: forall a b c.
(Tsil ByteArray -> ByteArray -> a -> Either b c)
-> Radix1Tree a -> (# Radix1Tree b, Radix1Tree c #)
mapEitherWithKey_ Tsil ByteArray -> ByteArray -> a -> Either b c
f = Tsil ByteArray -> Radix1Tree a -> (# Radix1Tree b, Radix1Tree c #)
go Tsil ByteArray
forall a. Tsil a
Lin
where
go :: Tsil ByteArray -> Radix1Tree a -> (# Radix1Tree b, Radix1Tree c #)
go Tsil ByteArray
b Radix1Tree a
t =
case Radix1Tree a
t of
Bin Prefix
p Radix1Tree a
l Radix1Tree a
r ->
let !(# Radix1Tree b
ly, Radix1Tree c
lz #) = Tsil ByteArray -> Radix1Tree a -> (# Radix1Tree b, Radix1Tree c #)
go Tsil ByteArray
b Radix1Tree a
l
!(# Radix1Tree b
ry, Radix1Tree c
rz #) = Tsil ByteArray -> Radix1Tree a -> (# Radix1Tree b, Radix1Tree c #)
go Tsil ByteArray
b Radix1Tree a
r
in (# Prefix -> Radix1Tree b -> Radix1Tree b -> Radix1Tree b
forall a. Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
rebin Prefix
p Radix1Tree b
ly Radix1Tree b
ry, Prefix -> Radix1Tree c -> Radix1Tree c -> Radix1Tree c
forall a. Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
rebin Prefix
p Radix1Tree c
lz Radix1Tree c
rz #)
Tip ByteArray
arr Maybe a
mx Radix1Tree a
dx ->
let !(# Radix1Tree b
dy, Radix1Tree c
dz #) = Tsil ByteArray -> Radix1Tree a -> (# Radix1Tree b, Radix1Tree c #)
go (Tsil ByteArray -> ByteArray -> Tsil ByteArray
forall a. Tsil a -> a -> Tsil a
Snoc Tsil ByteArray
b ByteArray
arr) Radix1Tree a
dx
in case Maybe a
mx of
Maybe a
Nothing -> (# ByteArray -> Maybe b -> Radix1Tree b -> Radix1Tree b
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
retip ByteArray
arr Maybe b
forall a. Maybe a
Nothing Radix1Tree b
dy, ByteArray -> Maybe c -> Radix1Tree c -> Radix1Tree c
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
retip ByteArray
arr Maybe c
forall a. Maybe a
Nothing Radix1Tree c
dz #)
Just a
x ->
case Tsil ByteArray -> ByteArray -> a -> Either b c
f Tsil ByteArray
b ByteArray
arr a
x of
Left b
y -> (# ByteArray -> Maybe b -> Radix1Tree b -> Radix1Tree b
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
Tip ByteArray
arr (b -> Maybe b
forall a. a -> Maybe a
Just b
y) Radix1Tree b
dy, ByteArray -> Maybe c -> Radix1Tree c -> Radix1Tree c
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
retip ByteArray
arr Maybe c
forall a. Maybe a
Nothing Radix1Tree c
dz #)
Right c
z -> (# ByteArray -> Maybe b -> Radix1Tree b -> Radix1Tree b
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
retip ByteArray
arr Maybe b
forall a. Maybe a
Nothing Radix1Tree b
dy, ByteArray -> Maybe c -> Radix1Tree c -> Radix1Tree c
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
Tip ByteArray
arr (c -> Maybe c
forall a. a -> Maybe a
Just c
z) Radix1Tree c
dz #)
Radix1Tree a
Nil -> (# Radix1Tree b
forall a. Radix1Tree a
Nil, Radix1Tree c
forall a. Radix1Tree a
Nil #)
moduleLoc1 :: String
moduleLoc1 :: String
moduleLoc1 = String
"Radix1Tree.Word8.Lazy"
lookupMin0 :: RadixTree a -> Maybe a
lookupMin0 :: forall a. RadixTree a -> Maybe a
lookupMin0 (RadixTree Maybe a
mx Radix1Tree a
t) =
case Maybe a
mx of
Just a
x -> a -> Maybe a
forall a. a -> Maybe a
Just a
x
Maybe a
Nothing -> Radix1Tree a -> Maybe a
forall a. Radix1Tree a -> Maybe a
lookupMin1 Radix1Tree a
t
lookupMin1 :: Radix1Tree a -> Maybe a
lookupMin1 :: forall a. Radix1Tree a -> Maybe a
lookupMin1 Radix1Tree a
Nil = Maybe a
forall a. Maybe a
Nothing
lookupMin1 Radix1Tree a
t = let !(# a
a #) = Radix1Tree a -> (# a #)
forall a. Radix1Tree a -> (# a #)
unsafeLookupMin1 Radix1Tree a
t
in a -> Maybe a
forall a. a -> Maybe a
Just a
a
unsafeLookupMin1 :: Radix1Tree a -> (# a #)
unsafeLookupMin1 :: forall a. Radix1Tree a -> (# a #)
unsafeLookupMin1 Radix1Tree a
t =
case Radix1Tree a
t of
Bin Prefix
_ Radix1Tree a
l Radix1Tree a
_ -> Radix1Tree a -> (# a #)
forall a. Radix1Tree a -> (# a #)
unsafeLookupMin1 Radix1Tree a
l
Tip ByteArray
_ Maybe a
mx Radix1Tree a
dx -> case Maybe a
mx of
Just a
x -> (# a
x #)
Maybe a
Nothing -> Radix1Tree a -> (# a #)
forall a. Radix1Tree a -> (# a #)
unsafeLookupMin1 Radix1Tree a
dx
Radix1Tree a
Nil -> MalformedTree -> (# a #)
forall a e. Exception e => e -> a
throw (MalformedTree -> (# a #)) -> MalformedTree -> (# a #)
forall a b. (a -> b) -> a -> b
$ String -> String -> MalformedTree
MalformedTree String
moduleLoc1 String
"lookupMin"
lookupMinWithKey0 :: RadixTree a -> Maybe (Lookup a)
lookupMinWithKey0 :: forall a. RadixTree a -> Maybe (Lookup a)
lookupMinWithKey0 (RadixTree Maybe a
mx Radix1Tree a
t) =
case Maybe a
mx of
Just a
x -> Lookup a -> Maybe (Lookup a)
forall a. a -> Maybe a
Just (Build -> a -> Lookup a
forall a. Build -> a -> Lookup a
Lookup (Tsil ByteArray -> Build
Build Tsil ByteArray
forall a. Tsil a
Lin) a
x)
Maybe a
Nothing ->
case Radix1Tree a
t of
Radix1Tree a
Nil -> Maybe (Lookup a)
forall a. Maybe a
Nothing
Radix1Tree a
_ -> let !(# Tsil ByteArray
b, ByteArray
arr, a
a #) = Tsil ByteArray
-> Radix1Tree a -> (# Tsil ByteArray, ByteArray, a #)
forall a.
Tsil ByteArray
-> Radix1Tree a -> (# Tsil ByteArray, ByteArray, a #)
unsafeLookupMinWithKey_ Tsil ByteArray
forall a. Tsil a
Lin Radix1Tree a
t
in Lookup a -> Maybe (Lookup a)
forall a. a -> Maybe a
Just (Lookup a -> Maybe (Lookup a)) -> Lookup a -> Maybe (Lookup a)
forall a b. (a -> b) -> a -> b
$! Build -> a -> Lookup a
forall a. Build -> a -> Lookup a
Lookup (Tsil ByteArray -> Build
Build (Tsil ByteArray -> Build) -> Tsil ByteArray -> Build
forall a b. (a -> b) -> a -> b
$ Tsil ByteArray -> ByteArray -> Tsil ByteArray
forall a. Tsil a -> a -> Tsil a
Snoc Tsil ByteArray
b ByteArray
arr) a
a
lookupMinWithKey1 :: Radix1Tree a -> Maybe (Lookup1 a)
lookupMinWithKey1 :: forall a. Radix1Tree a -> Maybe (Lookup1 a)
lookupMinWithKey1 Radix1Tree a
Nil = Maybe (Lookup1 a)
forall a. Maybe a
Nothing
lookupMinWithKey1 Radix1Tree a
t = Lookup1 a -> Maybe (Lookup1 a)
forall a. a -> Maybe a
Just (Lookup1 a -> Maybe (Lookup1 a)) -> Lookup1 a -> Maybe (Lookup1 a)
forall a b. (a -> b) -> a -> b
$! Radix1Tree a -> Lookup1 a
forall a. Radix1Tree a -> Lookup1 a
unsafeLookupMinWithKey1 Radix1Tree a
t
unsafeLookupMinWithKey1 :: Radix1Tree a -> Lookup1 a
unsafeLookupMinWithKey1 :: forall a. Radix1Tree a -> Lookup1 a
unsafeLookupMinWithKey1 Radix1Tree a
t =
let !(# Tsil ByteArray
b, ByteArray
arr, a
a #) = Tsil ByteArray
-> Radix1Tree a -> (# Tsil ByteArray, ByteArray, a #)
forall a.
Tsil ByteArray
-> Radix1Tree a -> (# Tsil ByteArray, ByteArray, a #)
unsafeLookupMinWithKey_ Tsil ByteArray
forall a. Tsil a
Lin Radix1Tree a
t
in Build1 -> a -> Lookup1 a
forall a. Build1 -> a -> Lookup1 a
Lookup1 (YtpmeNon ByteArray -> Build1
Build1 (YtpmeNon ByteArray -> Build1) -> YtpmeNon ByteArray -> Build1
forall a b. (a -> b) -> a -> b
$ Tsil ByteArray
b Tsil ByteArray -> ByteArray -> YtpmeNon ByteArray
forall a. Tsil a -> a -> YtpmeNon a
:/ ByteArray
arr) a
a
unsafeLookupMinWithKey_
:: Tsil ByteArray -> Radix1Tree a -> (# Tsil ByteArray, ByteArray, a #)
unsafeLookupMinWithKey_ :: forall a.
Tsil ByteArray
-> Radix1Tree a -> (# Tsil ByteArray, ByteArray, a #)
unsafeLookupMinWithKey_ = Tsil ByteArray
-> Radix1Tree a -> (# Tsil ByteArray, ByteArray, a #)
forall a.
Tsil ByteArray
-> Radix1Tree a -> (# Tsil ByteArray, ByteArray, a #)
go
where
go :: Tsil ByteArray
-> Radix1Tree c -> (# Tsil ByteArray, ByteArray, c #)
go Tsil ByteArray
b Radix1Tree c
t =
case Radix1Tree c
t of
Bin Prefix
_ Radix1Tree c
l Radix1Tree c
_ -> Tsil ByteArray
-> Radix1Tree c -> (# Tsil ByteArray, ByteArray, c #)
go Tsil ByteArray
b Radix1Tree c
l
Tip ByteArray
arr Maybe c
mx Radix1Tree c
dx -> case Maybe c
mx of
Just c
x -> (# Tsil ByteArray
b, ByteArray
arr, c
x #)
Maybe c
Nothing -> Tsil ByteArray
-> Radix1Tree c -> (# Tsil ByteArray, ByteArray, c #)
go (Tsil ByteArray -> ByteArray -> Tsil ByteArray
forall a. Tsil a -> a -> Tsil a
Snoc Tsil ByteArray
b ByteArray
arr) Radix1Tree c
dx
Radix1Tree c
Nil -> MalformedTree -> (# Tsil ByteArray, ByteArray, c #)
forall a e. Exception e => e -> a
throw (MalformedTree -> (# Tsil ByteArray, ByteArray, c #))
-> MalformedTree -> (# Tsil ByteArray, ByteArray, c #)
forall a b. (a -> b) -> a -> b
$ String -> String -> MalformedTree
MalformedTree String
moduleLoc1 String
"lookupMinWithKey"
lookupMax0 :: RadixTree a -> Maybe a
lookupMax0 :: forall a. RadixTree a -> Maybe a
lookupMax0 (RadixTree Maybe a
mx Radix1Tree a
t) =
case Radix1Tree a
t of
Radix1Tree a
Nil -> Maybe a
mx
Radix1Tree a
_ -> let !(# a
a #) = Radix1Tree a -> (# a #)
forall a. Radix1Tree a -> (# a #)
unsafeLookupMax1 Radix1Tree a
t
in a -> Maybe a
forall a. a -> Maybe a
Just a
a
lookupMax1 :: Radix1Tree a -> Maybe a
lookupMax1 :: forall a. Radix1Tree a -> Maybe a
lookupMax1 Radix1Tree a
Nil = Maybe a
forall a. Maybe a
Nothing
lookupMax1 Radix1Tree a
t = let !(# a
a #) = Radix1Tree a -> (# a #)
forall a. Radix1Tree a -> (# a #)
unsafeLookupMax1 Radix1Tree a
t
in a -> Maybe a
forall a. a -> Maybe a
Just a
a
unsafeLookupMax1 :: Radix1Tree a -> (# a #)
unsafeLookupMax1 :: forall a. Radix1Tree a -> (# a #)
unsafeLookupMax1 Radix1Tree a
t =
case Radix1Tree a
t of
Bin Prefix
_ Radix1Tree a
_ Radix1Tree a
r -> Radix1Tree a -> (# a #)
forall a. Radix1Tree a -> (# a #)
unsafeLookupMax1 Radix1Tree a
r
Tip ByteArray
_ Maybe a
mx Radix1Tree a
dx -> case Radix1Tree a
dx of
Radix1Tree a
Nil | Just a
x <- Maybe a
mx -> (# a
x #)
Radix1Tree a
_ -> Radix1Tree a -> (# a #)
forall a. Radix1Tree a -> (# a #)
unsafeLookupMax1 Radix1Tree a
dx
Radix1Tree a
Nil -> MalformedTree -> (# a #)
forall a e. Exception e => e -> a
throw (MalformedTree -> (# a #)) -> MalformedTree -> (# a #)
forall a b. (a -> b) -> a -> b
$ String -> String -> MalformedTree
MalformedTree String
moduleLoc1 String
"lookupMin"
lookupMaxWithKey0 :: RadixTree a -> Maybe (Lookup a)
lookupMaxWithKey0 :: forall a. RadixTree a -> Maybe (Lookup a)
lookupMaxWithKey0 (RadixTree Maybe a
mx Radix1Tree a
t) =
case Radix1Tree a
t of
Radix1Tree a
Nil -> Build -> a -> Lookup a
forall a. Build -> a -> Lookup a
Lookup (Tsil ByteArray -> Build
Build Tsil ByteArray
forall a. Tsil a
Lin) (a -> Lookup a) -> Maybe a -> Maybe (Lookup a)
forall a b. (a -> b) -> Maybe a -> Maybe b
`fmap'` Maybe a
mx
Radix1Tree a
_ -> let !(# Tsil ByteArray
b, ByteArray
arr, a
a #) = Tsil ByteArray
-> Radix1Tree a -> (# Tsil ByteArray, ByteArray, a #)
forall a.
Tsil ByteArray
-> Radix1Tree a -> (# Tsil ByteArray, ByteArray, a #)
unsafeLookupMaxWithKey_ Tsil ByteArray
forall a. Tsil a
Lin Radix1Tree a
t
in Lookup a -> Maybe (Lookup a)
forall a. a -> Maybe a
Just (Lookup a -> Maybe (Lookup a)) -> Lookup a -> Maybe (Lookup a)
forall a b. (a -> b) -> a -> b
$! Build -> a -> Lookup a
forall a. Build -> a -> Lookup a
Lookup (Tsil ByteArray -> Build
Build (Tsil ByteArray -> Build) -> Tsil ByteArray -> Build
forall a b. (a -> b) -> a -> b
$ Tsil ByteArray -> ByteArray -> Tsil ByteArray
forall a. Tsil a -> a -> Tsil a
Snoc Tsil ByteArray
b ByteArray
arr) a
a
lookupMaxWithKey1 :: Radix1Tree a -> Maybe (Lookup1 a)
lookupMaxWithKey1 :: forall a. Radix1Tree a -> Maybe (Lookup1 a)
lookupMaxWithKey1 Radix1Tree a
Nil = Maybe (Lookup1 a)
forall a. Maybe a
Nothing
lookupMaxWithKey1 Radix1Tree a
t = Lookup1 a -> Maybe (Lookup1 a)
forall a. a -> Maybe a
Just (Lookup1 a -> Maybe (Lookup1 a)) -> Lookup1 a -> Maybe (Lookup1 a)
forall a b. (a -> b) -> a -> b
$! Radix1Tree a -> Lookup1 a
forall a. Radix1Tree a -> Lookup1 a
unsafeLookupMaxWithKey1 Radix1Tree a
t
unsafeLookupMaxWithKey1 :: Radix1Tree a -> Lookup1 a
unsafeLookupMaxWithKey1 :: forall a. Radix1Tree a -> Lookup1 a
unsafeLookupMaxWithKey1 Radix1Tree a
t =
let !(# Tsil ByteArray
b, ByteArray
arr, a
a #) = Tsil ByteArray
-> Radix1Tree a -> (# Tsil ByteArray, ByteArray, a #)
forall a.
Tsil ByteArray
-> Radix1Tree a -> (# Tsil ByteArray, ByteArray, a #)
unsafeLookupMaxWithKey_ Tsil ByteArray
forall a. Tsil a
Lin Radix1Tree a
t
in Build1 -> a -> Lookup1 a
forall a. Build1 -> a -> Lookup1 a
Lookup1 (YtpmeNon ByteArray -> Build1
Build1 (YtpmeNon ByteArray -> Build1) -> YtpmeNon ByteArray -> Build1
forall a b. (a -> b) -> a -> b
$ Tsil ByteArray
b Tsil ByteArray -> ByteArray -> YtpmeNon ByteArray
forall a. Tsil a -> a -> YtpmeNon a
:/ ByteArray
arr) a
a
unsafeLookupMaxWithKey_
:: Tsil ByteArray -> Radix1Tree a -> (# Tsil ByteArray, ByteArray, a #)
unsafeLookupMaxWithKey_ :: forall a.
Tsil ByteArray
-> Radix1Tree a -> (# Tsil ByteArray, ByteArray, a #)
unsafeLookupMaxWithKey_ = Tsil ByteArray
-> Radix1Tree a -> (# Tsil ByteArray, ByteArray, a #)
forall a.
Tsil ByteArray
-> Radix1Tree a -> (# Tsil ByteArray, ByteArray, a #)
go
where
go :: Tsil ByteArray
-> Radix1Tree c -> (# Tsil ByteArray, ByteArray, c #)
go Tsil ByteArray
b Radix1Tree c
t =
case Radix1Tree c
t of
Bin Prefix
_ Radix1Tree c
_ Radix1Tree c
r -> Tsil ByteArray
-> Radix1Tree c -> (# Tsil ByteArray, ByteArray, c #)
go Tsil ByteArray
b Radix1Tree c
r
Tip ByteArray
arr Maybe c
mx Radix1Tree c
dx -> case Radix1Tree c
dx of
Radix1Tree c
Nil | Just c
x <- Maybe c
mx -> (# Tsil ByteArray
b, ByteArray
arr, c
x #)
Radix1Tree c
_ -> Tsil ByteArray
-> Radix1Tree c -> (# Tsil ByteArray, ByteArray, c #)
go (Tsil ByteArray -> ByteArray -> Tsil ByteArray
forall a. Tsil a -> a -> Tsil a
Snoc Tsil ByteArray
b ByteArray
arr) Radix1Tree c
dx
Radix1Tree c
Nil -> MalformedTree -> (# Tsil ByteArray, ByteArray, c #)
forall a e. Exception e => e -> a
throw (MalformedTree -> (# Tsil ByteArray, ByteArray, c #))
-> MalformedTree -> (# Tsil ByteArray, ByteArray, c #)
forall a b. (a -> b) -> a -> b
$ String -> String -> MalformedTree
MalformedTree String
moduleLoc1 String
"lookupMaxWithKey"
deleteMin0 :: RadixTree a -> RadixTree a
deleteMin0 :: forall a. RadixTree a -> RadixTree a
deleteMin0 (RadixTree Maybe a
mx Radix1Tree a
t) =
case Maybe a
mx of
Just a
_ -> Maybe a -> Radix1Tree a -> RadixTree a
forall a. Maybe a -> Radix1Tree a -> RadixTree a
RadixTree Maybe a
forall a. Maybe a
Nothing Radix1Tree a
t
Maybe a
Nothing -> Maybe a -> Radix1Tree a -> RadixTree a
forall a. Maybe a -> Radix1Tree a -> RadixTree a
RadixTree Maybe a
mx (Radix1Tree a -> Radix1Tree a
forall a. Radix1Tree a -> Radix1Tree a
deleteMin1 Radix1Tree a
t)
deleteMin1 :: Radix1Tree a -> Radix1Tree a
deleteMin1 :: forall a. Radix1Tree a -> Radix1Tree a
deleteMin1 Radix1Tree a
Nil = Radix1Tree a
forall a. Radix1Tree a
Nil
deleteMin1 Radix1Tree a
r = Radix1Tree a -> Radix1Tree a
forall a. Radix1Tree a -> Radix1Tree a
unsafeDeleteMin1 Radix1Tree a
r
unsafeDeleteMin1 :: Radix1Tree a -> Radix1Tree a
unsafeDeleteMin1 :: forall a. Radix1Tree a -> Radix1Tree a
unsafeDeleteMin1 = Radix1Tree a -> Radix1Tree a
forall a. Radix1Tree a -> Radix1Tree a
go
where
go :: Radix1Tree a -> Radix1Tree a
go Radix1Tree a
t =
case Radix1Tree a
t of
Bin Prefix
p Radix1Tree a
l Radix1Tree a
r -> Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
forall a. Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
rebinL Prefix
p (Radix1Tree a -> Radix1Tree a
go Radix1Tree a
l) Radix1Tree a
r
Tip ByteArray
arr Maybe a
mx Radix1Tree a
dx -> case Maybe a
mx of
Maybe a
Nothing -> ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
retip ByteArray
arr Maybe a
mx (Radix1Tree a -> Radix1Tree a
go Radix1Tree a
dx)
Just a
_ -> ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
retip ByteArray
arr Maybe a
forall a. Maybe a
Nothing Radix1Tree a
dx
Radix1Tree a
Nil -> Radix1Tree a
forall a. Radix1Tree a
Nil
deleteMax0 :: RadixTree a -> RadixTree a
deleteMax0 :: forall a. RadixTree a -> RadixTree a
deleteMax0 t0 :: RadixTree a
t0@(RadixTree Maybe a
mx Radix1Tree a
t) =
case Radix1Tree a
t of
Radix1Tree a
Nil -> case Maybe a
mx of
Just a
_ -> Maybe a -> Radix1Tree a -> RadixTree a
forall a. Maybe a -> Radix1Tree a -> RadixTree a
RadixTree Maybe a
forall a. Maybe a
Nothing Radix1Tree a
t
Maybe a
Nothing -> RadixTree a
t0
Radix1Tree a
_ -> Maybe a -> Radix1Tree a -> RadixTree a
forall a. Maybe a -> Radix1Tree a -> RadixTree a
RadixTree Maybe a
mx (Radix1Tree a -> Radix1Tree a
forall a. Radix1Tree a -> Radix1Tree a
unsafeDeleteMax1 Radix1Tree a
t)
deleteMax1 :: Radix1Tree a -> Radix1Tree a
deleteMax1 :: forall a. Radix1Tree a -> Radix1Tree a
deleteMax1 Radix1Tree a
Nil = Radix1Tree a
forall a. Radix1Tree a
Nil
deleteMax1 Radix1Tree a
r = Radix1Tree a -> Radix1Tree a
forall a. Radix1Tree a -> Radix1Tree a
unsafeDeleteMax1 Radix1Tree a
r
unsafeDeleteMax1 :: Radix1Tree a -> Radix1Tree a
unsafeDeleteMax1 :: forall a. Radix1Tree a -> Radix1Tree a
unsafeDeleteMax1 = Radix1Tree a -> Radix1Tree a
forall a. Radix1Tree a -> Radix1Tree a
go
where
go :: Radix1Tree a -> Radix1Tree a
go Radix1Tree a
t =
case Radix1Tree a
t of
Bin Prefix
p Radix1Tree a
l Radix1Tree a
r -> Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
forall a. Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
rebinR Prefix
p Radix1Tree a
l (Radix1Tree a -> Radix1Tree a
go Radix1Tree a
r)
Tip ByteArray
arr Maybe a
mx Radix1Tree a
dx -> case Radix1Tree a
dx of
Radix1Tree a
Nil -> Radix1Tree a
forall a. Radix1Tree a
Nil
Radix1Tree a
_ -> ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
retip ByteArray
arr Maybe a
mx (Radix1Tree a -> Radix1Tree a
go Radix1Tree a
dx)
Radix1Tree a
Nil -> Radix1Tree a
forall a. Radix1Tree a
Nil
adjustMin0 :: (a -> a) -> RadixTree a -> RadixTree a
adjustMin0 :: forall a. (a -> a) -> RadixTree a -> RadixTree a
adjustMin0 a -> a
f (RadixTree Maybe a
mx Radix1Tree a
t) =
case Maybe a
mx of
Just a
x -> Maybe a -> Radix1Tree a -> RadixTree a
forall a. Maybe a -> Radix1Tree a -> RadixTree a
RadixTree (a -> Maybe a
forall a. a -> Maybe a
Just (a -> Maybe a) -> a -> Maybe a
forall a b. (a -> b) -> a -> b
$ a -> a
f a
x) Radix1Tree a
t
Maybe a
Nothing -> Maybe a -> Radix1Tree a -> RadixTree a
forall a. Maybe a -> Radix1Tree a -> RadixTree a
RadixTree Maybe a
mx ((a -> a) -> Radix1Tree a -> Radix1Tree a
forall a. (a -> a) -> Radix1Tree a -> Radix1Tree a
adjustMin1 a -> a
f Radix1Tree a
t)
adjustMin1 :: (a -> a) -> Radix1Tree a -> Radix1Tree a
adjustMin1 :: forall a. (a -> a) -> Radix1Tree a -> Radix1Tree a
adjustMin1 a -> a
_ Radix1Tree a
Nil = Radix1Tree a
forall a. Radix1Tree a
Nil
adjustMin1 a -> a
f Radix1Tree a
r = (a -> a) -> Radix1Tree a -> Radix1Tree a
forall a. (a -> a) -> Radix1Tree a -> Radix1Tree a
unsafeAdjustMin1 a -> a
f Radix1Tree a
r
unsafeAdjustMin1 :: (a -> a) -> Radix1Tree a -> Radix1Tree a
unsafeAdjustMin1 :: forall a. (a -> a) -> Radix1Tree a -> Radix1Tree a
unsafeAdjustMin1 a -> a
f = Radix1Tree a -> Radix1Tree a
go
where
go :: Radix1Tree a -> Radix1Tree a
go Radix1Tree a
t =
case Radix1Tree a
t of
Bin Prefix
p Radix1Tree a
l Radix1Tree a
r -> Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
forall a. Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
Bin Prefix
p (Radix1Tree a -> Radix1Tree a
go Radix1Tree a
l) Radix1Tree a
r
Tip ByteArray
arr Maybe a
mx Radix1Tree a
dx -> case Maybe a
mx of
Just a
x -> ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
Tip ByteArray
arr (a -> Maybe a
forall a. a -> Maybe a
Just (a -> Maybe a) -> a -> Maybe a
forall a b. (a -> b) -> a -> b
$ a -> a
f a
x) Radix1Tree a
dx
Maybe a
Nothing -> ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
Tip ByteArray
arr Maybe a
mx (Radix1Tree a -> Radix1Tree a
go Radix1Tree a
dx)
Radix1Tree a
Nil -> Radix1Tree a
forall a. Radix1Tree a
Nil
adjustMinWithKey0 :: (Build -> a -> a) -> RadixTree a -> RadixTree a
adjustMinWithKey0 :: forall a. (Build -> a -> a) -> RadixTree a -> RadixTree a
adjustMinWithKey0 Build -> a -> a
f (RadixTree Maybe a
mx Radix1Tree a
t) =
case Maybe a
mx of
Just a
x -> Maybe a -> Radix1Tree a -> RadixTree a
forall a. Maybe a -> Radix1Tree a -> RadixTree a
RadixTree (a -> Maybe a
forall a. a -> Maybe a
Just (a -> Maybe a) -> a -> Maybe a
forall a b. (a -> b) -> a -> b
$ Build -> a -> a
f (Tsil ByteArray -> Build
Build Tsil ByteArray
forall a. Tsil a
Lin) a
x) Radix1Tree a
t
Maybe a
Nothing -> Maybe a -> Radix1Tree a -> RadixTree a
forall a. Maybe a -> Radix1Tree a -> RadixTree a
RadixTree Maybe a
mx (Radix1Tree a -> RadixTree a) -> Radix1Tree a -> RadixTree a
forall a b. (a -> b) -> a -> b
$
case Radix1Tree a
t of
Radix1Tree a
Nil -> Radix1Tree a
forall a. Radix1Tree a
Nil
Radix1Tree a
_ -> (Tsil ByteArray -> ByteArray -> a -> a)
-> Radix1Tree a -> Radix1Tree a
forall a.
(Tsil ByteArray -> ByteArray -> a -> a)
-> Radix1Tree a -> Radix1Tree a
unsafeAdjustMinWithKey_ (\Tsil ByteArray
b ByteArray
arr -> Build -> a -> a
f (Tsil ByteArray -> Build
Build (Tsil ByteArray -> Build) -> Tsil ByteArray -> Build
forall a b. (a -> b) -> a -> b
$ Tsil ByteArray -> ByteArray -> Tsil ByteArray
forall a. Tsil a -> a -> Tsil a
Snoc Tsil ByteArray
b ByteArray
arr)) Radix1Tree a
t
adjustMinWithKey1 :: (Build1 -> a -> a) -> Radix1Tree a -> Radix1Tree a
adjustMinWithKey1 :: forall a. (Build1 -> a -> a) -> Radix1Tree a -> Radix1Tree a
adjustMinWithKey1 Build1 -> a -> a
_ Radix1Tree a
Nil = Radix1Tree a
forall a. Radix1Tree a
Nil
adjustMinWithKey1 Build1 -> a -> a
f Radix1Tree a
r = (Build1 -> a -> a) -> Radix1Tree a -> Radix1Tree a
forall a. (Build1 -> a -> a) -> Radix1Tree a -> Radix1Tree a
unsafeAdjustMinWithKey1 Build1 -> a -> a
f Radix1Tree a
r
unsafeAdjustMinWithKey1 :: (Build1 -> a -> a) -> Radix1Tree a -> Radix1Tree a
unsafeAdjustMinWithKey1 :: forall a. (Build1 -> a -> a) -> Radix1Tree a -> Radix1Tree a
unsafeAdjustMinWithKey1 Build1 -> a -> a
f = (Tsil ByteArray -> ByteArray -> a -> a)
-> Radix1Tree a -> Radix1Tree a
forall a.
(Tsil ByteArray -> ByteArray -> a -> a)
-> Radix1Tree a -> Radix1Tree a
unsafeAdjustMinWithKey_ (\Tsil ByteArray
b ByteArray
arr -> Build1 -> a -> a
f (YtpmeNon ByteArray -> Build1
Build1 (YtpmeNon ByteArray -> Build1) -> YtpmeNon ByteArray -> Build1
forall a b. (a -> b) -> a -> b
$ Tsil ByteArray
b Tsil ByteArray -> ByteArray -> YtpmeNon ByteArray
forall a. Tsil a -> a -> YtpmeNon a
:/ ByteArray
arr))
{-# INLINE unsafeAdjustMinWithKey_ #-}
unsafeAdjustMinWithKey_
:: (Tsil ByteArray -> ByteArray -> a -> a) -> Radix1Tree a -> Radix1Tree a
unsafeAdjustMinWithKey_ :: forall a.
(Tsil ByteArray -> ByteArray -> a -> a)
-> Radix1Tree a -> Radix1Tree a
unsafeAdjustMinWithKey_ Tsil ByteArray -> ByteArray -> a -> a
f = Tsil ByteArray -> Radix1Tree a -> Radix1Tree a
go Tsil ByteArray
forall a. Tsil a
Lin
where
go :: Tsil ByteArray -> Radix1Tree a -> Radix1Tree a
go Tsil ByteArray
b Radix1Tree a
t =
case Radix1Tree a
t of
Bin Prefix
p Radix1Tree a
l Radix1Tree a
r -> Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
forall a. Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
Bin Prefix
p (Tsil ByteArray -> Radix1Tree a -> Radix1Tree a
go Tsil ByteArray
b Radix1Tree a
l) Radix1Tree a
r
Tip ByteArray
arr Maybe a
mx Radix1Tree a
dx -> case Maybe a
mx of
Just a
x -> ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
Tip ByteArray
arr (a -> Maybe a
forall a. a -> Maybe a
Just (a -> Maybe a) -> a -> Maybe a
forall a b. (a -> b) -> a -> b
$ Tsil ByteArray -> ByteArray -> a -> a
f Tsil ByteArray
b ByteArray
arr a
x) Radix1Tree a
dx
Maybe a
Nothing -> ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
Tip ByteArray
arr Maybe a
mx (Tsil ByteArray -> Radix1Tree a -> Radix1Tree a
go (Tsil ByteArray -> ByteArray -> Tsil ByteArray
forall a. Tsil a -> a -> Tsil a
Snoc Tsil ByteArray
b ByteArray
arr) Radix1Tree a
dx)
Radix1Tree a
Nil -> Radix1Tree a
forall a. Radix1Tree a
Nil
adjustMax0 :: (a -> a) -> RadixTree a -> RadixTree a
adjustMax0 :: forall a. (a -> a) -> RadixTree a -> RadixTree a
adjustMax0 a -> a
f t0 :: RadixTree a
t0@(RadixTree Maybe a
mx Radix1Tree a
t) =
case Radix1Tree a
t of
Radix1Tree a
Nil -> case Maybe a
mx of
Just a
x -> Maybe a -> Radix1Tree a -> RadixTree a
forall a. Maybe a -> Radix1Tree a -> RadixTree a
RadixTree (a -> Maybe a
forall a. a -> Maybe a
Just (a -> Maybe a) -> a -> Maybe a
forall a b. (a -> b) -> a -> b
$ a -> a
f a
x) Radix1Tree a
t
Maybe a
Nothing -> RadixTree a
t0
Radix1Tree a
_ -> Maybe a -> Radix1Tree a -> RadixTree a
forall a. Maybe a -> Radix1Tree a -> RadixTree a
RadixTree Maybe a
mx ((a -> a) -> Radix1Tree a -> Radix1Tree a
forall a. (a -> a) -> Radix1Tree a -> Radix1Tree a
unsafeAdjustMax1 a -> a
f Radix1Tree a
t)
adjustMax1 :: (a -> a) -> Radix1Tree a -> Radix1Tree a
adjustMax1 :: forall a. (a -> a) -> Radix1Tree a -> Radix1Tree a
adjustMax1 a -> a
_ Radix1Tree a
Nil = Radix1Tree a
forall a. Radix1Tree a
Nil
adjustMax1 a -> a
f Radix1Tree a
r = (a -> a) -> Radix1Tree a -> Radix1Tree a
forall a. (a -> a) -> Radix1Tree a -> Radix1Tree a
unsafeAdjustMax1 a -> a
f Radix1Tree a
r
unsafeAdjustMax1 :: (a -> a) -> Radix1Tree a -> Radix1Tree a
unsafeAdjustMax1 :: forall a. (a -> a) -> Radix1Tree a -> Radix1Tree a
unsafeAdjustMax1 a -> a
f = Radix1Tree a -> Radix1Tree a
go
where
go :: Radix1Tree a -> Radix1Tree a
go Radix1Tree a
t =
case Radix1Tree a
t of
Bin Prefix
p Radix1Tree a
l Radix1Tree a
r -> Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
forall a. Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
Bin Prefix
p Radix1Tree a
l (Radix1Tree a -> Radix1Tree a
go Radix1Tree a
r)
Tip ByteArray
arr Maybe a
mx Radix1Tree a
dx -> case Radix1Tree a
dx of
Radix1Tree a
Nil | Just a
x <- Maybe a
mx -> ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
Tip ByteArray
arr (a -> Maybe a
forall a. a -> Maybe a
Just (a -> Maybe a) -> a -> Maybe a
forall a b. (a -> b) -> a -> b
$ a -> a
f a
x) Radix1Tree a
dx
Radix1Tree a
_ -> ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
Tip ByteArray
arr Maybe a
mx (Radix1Tree a -> Radix1Tree a
go Radix1Tree a
dx)
Radix1Tree a
Nil -> Radix1Tree a
forall a. Radix1Tree a
Nil
adjustMaxWithKey0 :: (Build -> a -> a) -> RadixTree a -> RadixTree a
adjustMaxWithKey0 :: forall a. (Build -> a -> a) -> RadixTree a -> RadixTree a
adjustMaxWithKey0 Build -> a -> a
f t0 :: RadixTree a
t0@(RadixTree Maybe a
mx Radix1Tree a
t) =
case Radix1Tree a
t of
Radix1Tree a
Nil -> case Maybe a
mx of
Just a
x -> Maybe a -> Radix1Tree a -> RadixTree a
forall a. Maybe a -> Radix1Tree a -> RadixTree a
RadixTree (a -> Maybe a
forall a. a -> Maybe a
Just (a -> Maybe a) -> a -> Maybe a
forall a b. (a -> b) -> a -> b
$ Build -> a -> a
f (Tsil ByteArray -> Build
Build Tsil ByteArray
forall a. Tsil a
Lin) a
x) Radix1Tree a
t
Maybe a
Nothing -> RadixTree a
t0
Radix1Tree a
_ -> Maybe a -> Radix1Tree a -> RadixTree a
forall a. Maybe a -> Radix1Tree a -> RadixTree a
RadixTree Maybe a
mx (Radix1Tree a -> RadixTree a) -> Radix1Tree a -> RadixTree a
forall a b. (a -> b) -> a -> b
$
(Tsil ByteArray -> ByteArray -> a -> a)
-> Radix1Tree a -> Radix1Tree a
forall a.
(Tsil ByteArray -> ByteArray -> a -> a)
-> Radix1Tree a -> Radix1Tree a
unsafeAdjustMaxWithKey_ (\Tsil ByteArray
b ByteArray
arr -> Build -> a -> a
f (Tsil ByteArray -> Build
Build (Tsil ByteArray -> Build) -> Tsil ByteArray -> Build
forall a b. (a -> b) -> a -> b
$ Tsil ByteArray -> ByteArray -> Tsil ByteArray
forall a. Tsil a -> a -> Tsil a
Snoc Tsil ByteArray
b ByteArray
arr)) Radix1Tree a
t
adjustMaxWithKey1 :: (Build1 -> a -> a) -> Radix1Tree a -> Radix1Tree a
adjustMaxWithKey1 :: forall a. (Build1 -> a -> a) -> Radix1Tree a -> Radix1Tree a
adjustMaxWithKey1 Build1 -> a -> a
_ Radix1Tree a
Nil = Radix1Tree a
forall a. Radix1Tree a
Nil
adjustMaxWithKey1 Build1 -> a -> a
f Radix1Tree a
r = (Build1 -> a -> a) -> Radix1Tree a -> Radix1Tree a
forall a. (Build1 -> a -> a) -> Radix1Tree a -> Radix1Tree a
unsafeAdjustMaxWithKey1 Build1 -> a -> a
f Radix1Tree a
r
unsafeAdjustMaxWithKey1 :: (Build1 -> a -> a) -> Radix1Tree a -> Radix1Tree a
unsafeAdjustMaxWithKey1 :: forall a. (Build1 -> a -> a) -> Radix1Tree a -> Radix1Tree a
unsafeAdjustMaxWithKey1 Build1 -> a -> a
f = (Tsil ByteArray -> ByteArray -> a -> a)
-> Radix1Tree a -> Radix1Tree a
forall a.
(Tsil ByteArray -> ByteArray -> a -> a)
-> Radix1Tree a -> Radix1Tree a
unsafeAdjustMaxWithKey_ (\Tsil ByteArray
b ByteArray
arr -> Build1 -> a -> a
f (YtpmeNon ByteArray -> Build1
Build1 (YtpmeNon ByteArray -> Build1) -> YtpmeNon ByteArray -> Build1
forall a b. (a -> b) -> a -> b
$ Tsil ByteArray
b Tsil ByteArray -> ByteArray -> YtpmeNon ByteArray
forall a. Tsil a -> a -> YtpmeNon a
:/ ByteArray
arr))
{-# INLINE unsafeAdjustMaxWithKey_ #-}
unsafeAdjustMaxWithKey_
:: (Tsil ByteArray -> ByteArray -> a -> a) -> Radix1Tree a -> Radix1Tree a
unsafeAdjustMaxWithKey_ :: forall a.
(Tsil ByteArray -> ByteArray -> a -> a)
-> Radix1Tree a -> Radix1Tree a
unsafeAdjustMaxWithKey_ Tsil ByteArray -> ByteArray -> a -> a
f = Tsil ByteArray -> Radix1Tree a -> Radix1Tree a
go Tsil ByteArray
forall a. Tsil a
Lin
where
go :: Tsil ByteArray -> Radix1Tree a -> Radix1Tree a
go Tsil ByteArray
b Radix1Tree a
t =
case Radix1Tree a
t of
Bin Prefix
p Radix1Tree a
l Radix1Tree a
r -> Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
forall a. Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
Bin Prefix
p Radix1Tree a
l (Tsil ByteArray -> Radix1Tree a -> Radix1Tree a
go Tsil ByteArray
b Radix1Tree a
r)
Tip ByteArray
arr Maybe a
mx Radix1Tree a
dx ->
case Radix1Tree a
dx of
Radix1Tree a
Nil | Just a
x <- Maybe a
mx -> ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
Tip ByteArray
arr (a -> Maybe a
forall a. a -> Maybe a
Just (a -> Maybe a) -> a -> Maybe a
forall a b. (a -> b) -> a -> b
$ Tsil ByteArray -> ByteArray -> a -> a
f Tsil ByteArray
b ByteArray
arr a
x) Radix1Tree a
dx
Radix1Tree a
_ -> ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
Tip ByteArray
arr Maybe a
mx (Tsil ByteArray -> Radix1Tree a -> Radix1Tree a
go (Tsil ByteArray -> ByteArray -> Tsil ByteArray
forall a. Tsil a -> a -> Tsil a
Snoc Tsil ByteArray
b ByteArray
arr) Radix1Tree a
dx)
Radix1Tree a
Nil -> Radix1Tree a
forall a. Radix1Tree a
Nil
updateMin0 :: (a -> Maybe a) -> RadixTree a -> RadixTree a
updateMin0 :: forall a. (a -> Maybe a) -> RadixTree a -> RadixTree a
updateMin0 a -> Maybe a
f (RadixTree Maybe a
mx Radix1Tree a
t) =
case Maybe a
mx of
Just a
x -> Maybe a -> Radix1Tree a -> RadixTree a
forall a. Maybe a -> Radix1Tree a -> RadixTree a
RadixTree (a -> Maybe a
f a
x) Radix1Tree a
t
Maybe a
Nothing -> Maybe a -> Radix1Tree a -> RadixTree a
forall a. Maybe a -> Radix1Tree a -> RadixTree a
RadixTree Maybe a
mx ((a -> Maybe a) -> Radix1Tree a -> Radix1Tree a
forall a. (a -> Maybe a) -> Radix1Tree a -> Radix1Tree a
updateMin1 a -> Maybe a
f Radix1Tree a
t)
updateMin1 :: (a -> Maybe a) -> Radix1Tree a -> Radix1Tree a
updateMin1 :: forall a. (a -> Maybe a) -> Radix1Tree a -> Radix1Tree a
updateMin1 a -> Maybe a
_ Radix1Tree a
Nil = Radix1Tree a
forall a. Radix1Tree a
Nil
updateMin1 a -> Maybe a
f Radix1Tree a
r = (a -> Maybe a) -> Radix1Tree a -> Radix1Tree a
forall a. (a -> Maybe a) -> Radix1Tree a -> Radix1Tree a
unsafeUpdateMin1 a -> Maybe a
f Radix1Tree a
r
unsafeUpdateMin1 :: (a -> Maybe a) -> Radix1Tree a -> Radix1Tree a
unsafeUpdateMin1 :: forall a. (a -> Maybe a) -> Radix1Tree a -> Radix1Tree a
unsafeUpdateMin1 a -> Maybe a
f = Radix1Tree a -> Radix1Tree a
go
where
go :: Radix1Tree a -> Radix1Tree a
go Radix1Tree a
t =
case Radix1Tree a
t of
Bin Prefix
p Radix1Tree a
l Radix1Tree a
r -> Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
forall a. Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
rebinL Prefix
p (Radix1Tree a -> Radix1Tree a
go Radix1Tree a
l) Radix1Tree a
r
Tip ByteArray
arr Maybe a
mx Radix1Tree a
dx -> case Maybe a
mx of
Just a
x -> ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
retip ByteArray
arr (a -> Maybe a
f a
x) Radix1Tree a
dx
Maybe a
Nothing -> ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
retip ByteArray
arr Maybe a
mx (Radix1Tree a -> Radix1Tree a
go Radix1Tree a
dx)
Radix1Tree a
Nil -> Radix1Tree a
forall a. Radix1Tree a
Nil
updateMinWithKey0 :: (Build -> a -> Maybe a) -> RadixTree a -> RadixTree a
updateMinWithKey0 :: forall a. (Build -> a -> Maybe a) -> RadixTree a -> RadixTree a
updateMinWithKey0 Build -> a -> Maybe a
f (RadixTree Maybe a
mx Radix1Tree a
t) =
case Maybe a
mx of
Just a
x -> Maybe a -> Radix1Tree a -> RadixTree a
forall a. Maybe a -> Radix1Tree a -> RadixTree a
RadixTree (Build -> a -> Maybe a
f (Tsil ByteArray -> Build
Build Tsil ByteArray
forall a. Tsil a
Lin) a
x) Radix1Tree a
t
Maybe a
Nothing -> Maybe a -> Radix1Tree a -> RadixTree a
forall a. Maybe a -> Radix1Tree a -> RadixTree a
RadixTree Maybe a
mx (Radix1Tree a -> RadixTree a) -> Radix1Tree a -> RadixTree a
forall a b. (a -> b) -> a -> b
$
case Radix1Tree a
t of
Radix1Tree a
Nil -> Radix1Tree a
forall a. Radix1Tree a
Nil
Radix1Tree a
_ -> (Tsil ByteArray -> ByteArray -> a -> Maybe a)
-> Radix1Tree a -> Radix1Tree a
forall a.
(Tsil ByteArray -> ByteArray -> a -> Maybe a)
-> Radix1Tree a -> Radix1Tree a
unsafeUpdateMinWithKey_ (\Tsil ByteArray
b ByteArray
arr -> Build -> a -> Maybe a
f (Tsil ByteArray -> Build
Build (Tsil ByteArray -> Build) -> Tsil ByteArray -> Build
forall a b. (a -> b) -> a -> b
$ Tsil ByteArray -> ByteArray -> Tsil ByteArray
forall a. Tsil a -> a -> Tsil a
Snoc Tsil ByteArray
b ByteArray
arr)) Radix1Tree a
t
updateMinWithKey1 :: (Build1 -> a -> Maybe a) -> Radix1Tree a -> Radix1Tree a
updateMinWithKey1 :: forall a. (Build1 -> a -> Maybe a) -> Radix1Tree a -> Radix1Tree a
updateMinWithKey1 Build1 -> a -> Maybe a
_ Radix1Tree a
Nil = Radix1Tree a
forall a. Radix1Tree a
Nil
updateMinWithKey1 Build1 -> a -> Maybe a
f Radix1Tree a
r = (Build1 -> a -> Maybe a) -> Radix1Tree a -> Radix1Tree a
forall a. (Build1 -> a -> Maybe a) -> Radix1Tree a -> Radix1Tree a
unsafeUpdateMinWithKey1 Build1 -> a -> Maybe a
f Radix1Tree a
r
unsafeUpdateMinWithKey1 :: (Build1 -> a -> Maybe a) -> Radix1Tree a -> Radix1Tree a
unsafeUpdateMinWithKey1 :: forall a. (Build1 -> a -> Maybe a) -> Radix1Tree a -> Radix1Tree a
unsafeUpdateMinWithKey1 Build1 -> a -> Maybe a
f = (Tsil ByteArray -> ByteArray -> a -> Maybe a)
-> Radix1Tree a -> Radix1Tree a
forall a.
(Tsil ByteArray -> ByteArray -> a -> Maybe a)
-> Radix1Tree a -> Radix1Tree a
unsafeUpdateMinWithKey_ (\Tsil ByteArray
b ByteArray
arr -> Build1 -> a -> Maybe a
f (YtpmeNon ByteArray -> Build1
Build1 (YtpmeNon ByteArray -> Build1) -> YtpmeNon ByteArray -> Build1
forall a b. (a -> b) -> a -> b
$ Tsil ByteArray
b Tsil ByteArray -> ByteArray -> YtpmeNon ByteArray
forall a. Tsil a -> a -> YtpmeNon a
:/ ByteArray
arr))
{-# INLINE unsafeUpdateMinWithKey_ #-}
unsafeUpdateMinWithKey_
:: (Tsil ByteArray -> ByteArray -> a -> Maybe a) -> Radix1Tree a -> Radix1Tree a
unsafeUpdateMinWithKey_ :: forall a.
(Tsil ByteArray -> ByteArray -> a -> Maybe a)
-> Radix1Tree a -> Radix1Tree a
unsafeUpdateMinWithKey_ Tsil ByteArray -> ByteArray -> a -> Maybe a
f = Tsil ByteArray -> Radix1Tree a -> Radix1Tree a
go Tsil ByteArray
forall a. Tsil a
Lin
where
go :: Tsil ByteArray -> Radix1Tree a -> Radix1Tree a
go Tsil ByteArray
b Radix1Tree a
t =
case Radix1Tree a
t of
Bin Prefix
p Radix1Tree a
l Radix1Tree a
r -> Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
forall a. Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
rebinL Prefix
p (Tsil ByteArray -> Radix1Tree a -> Radix1Tree a
go Tsil ByteArray
b Radix1Tree a
l) Radix1Tree a
r
Tip ByteArray
arr Maybe a
mx Radix1Tree a
dx -> case Maybe a
mx of
Just a
x -> ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
retip ByteArray
arr (Tsil ByteArray -> ByteArray -> a -> Maybe a
f Tsil ByteArray
b ByteArray
arr a
x) Radix1Tree a
dx
Maybe a
Nothing -> ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
retip ByteArray
arr Maybe a
mx (Tsil ByteArray -> Radix1Tree a -> Radix1Tree a
go (Tsil ByteArray -> ByteArray -> Tsil ByteArray
forall a. Tsil a -> a -> Tsil a
Snoc Tsil ByteArray
b ByteArray
arr) Radix1Tree a
dx)
Radix1Tree a
Nil -> Radix1Tree a
forall a. Radix1Tree a
Nil
updateMax0 :: (a -> Maybe a) -> RadixTree a -> RadixTree a
updateMax0 :: forall a. (a -> Maybe a) -> RadixTree a -> RadixTree a
updateMax0 a -> Maybe a
f t0 :: RadixTree a
t0@(RadixTree Maybe a
mx Radix1Tree a
t) =
case Radix1Tree a
t of
Radix1Tree a
Nil -> case Maybe a
mx of
Just a
x -> Maybe a -> Radix1Tree a -> RadixTree a
forall a. Maybe a -> Radix1Tree a -> RadixTree a
RadixTree (a -> Maybe a
f a
x) Radix1Tree a
t
Maybe a
Nothing -> RadixTree a
t0
Radix1Tree a
_ -> Maybe a -> Radix1Tree a -> RadixTree a
forall a. Maybe a -> Radix1Tree a -> RadixTree a
RadixTree Maybe a
mx ((a -> Maybe a) -> Radix1Tree a -> Radix1Tree a
forall a. (a -> Maybe a) -> Radix1Tree a -> Radix1Tree a
unsafeUpdateMax1 a -> Maybe a
f Radix1Tree a
t)
updateMax1 :: (a -> Maybe a) -> Radix1Tree a -> Radix1Tree a
updateMax1 :: forall a. (a -> Maybe a) -> Radix1Tree a -> Radix1Tree a
updateMax1 a -> Maybe a
_ Radix1Tree a
Nil = Radix1Tree a
forall a. Radix1Tree a
Nil
updateMax1 a -> Maybe a
f Radix1Tree a
r = (a -> Maybe a) -> Radix1Tree a -> Radix1Tree a
forall a. (a -> Maybe a) -> Radix1Tree a -> Radix1Tree a
unsafeUpdateMax1 a -> Maybe a
f Radix1Tree a
r
unsafeUpdateMax1 :: (a -> Maybe a) -> Radix1Tree a -> Radix1Tree a
unsafeUpdateMax1 :: forall a. (a -> Maybe a) -> Radix1Tree a -> Radix1Tree a
unsafeUpdateMax1 a -> Maybe a
f = Radix1Tree a -> Radix1Tree a
go
where
go :: Radix1Tree a -> Radix1Tree a
go Radix1Tree a
t =
case Radix1Tree a
t of
Bin Prefix
p Radix1Tree a
l Radix1Tree a
r -> Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
forall a. Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
rebinR Prefix
p Radix1Tree a
l (Radix1Tree a -> Radix1Tree a
go Radix1Tree a
r)
Tip ByteArray
arr Maybe a
mx Radix1Tree a
dx -> case Radix1Tree a
dx of
Radix1Tree a
Nil | Just a
x <- Maybe a
mx -> ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
retip ByteArray
arr (a -> Maybe a
f a
x) Radix1Tree a
dx
Radix1Tree a
_ -> ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
retip ByteArray
arr Maybe a
mx (Radix1Tree a -> Radix1Tree a
go Radix1Tree a
dx)
Radix1Tree a
Nil -> Radix1Tree a
forall a. Radix1Tree a
Nil
updateMaxWithKey0 :: (Build -> a -> Maybe a) -> RadixTree a -> RadixTree a
updateMaxWithKey0 :: forall a. (Build -> a -> Maybe a) -> RadixTree a -> RadixTree a
updateMaxWithKey0 Build -> a -> Maybe a
f t0 :: RadixTree a
t0@(RadixTree Maybe a
mx Radix1Tree a
t) =
case Radix1Tree a
t of
Radix1Tree a
Nil -> case Maybe a
mx of
Just a
x -> Maybe a -> Radix1Tree a -> RadixTree a
forall a. Maybe a -> Radix1Tree a -> RadixTree a
RadixTree (Build -> a -> Maybe a
f (Tsil ByteArray -> Build
Build Tsil ByteArray
forall a. Tsil a
Lin) a
x) Radix1Tree a
t
Maybe a
Nothing -> RadixTree a
t0
Radix1Tree a
_ -> Maybe a -> Radix1Tree a -> RadixTree a
forall a. Maybe a -> Radix1Tree a -> RadixTree a
RadixTree Maybe a
mx (Radix1Tree a -> RadixTree a) -> Radix1Tree a -> RadixTree a
forall a b. (a -> b) -> a -> b
$
(Tsil ByteArray -> ByteArray -> a -> Maybe a)
-> Radix1Tree a -> Radix1Tree a
forall a.
(Tsil ByteArray -> ByteArray -> a -> Maybe a)
-> Radix1Tree a -> Radix1Tree a
unsafeUpdateMaxWithKey_ (\Tsil ByteArray
b ByteArray
arr -> Build -> a -> Maybe a
f (Tsil ByteArray -> Build
Build (Tsil ByteArray -> Build) -> Tsil ByteArray -> Build
forall a b. (a -> b) -> a -> b
$ Tsil ByteArray -> ByteArray -> Tsil ByteArray
forall a. Tsil a -> a -> Tsil a
Snoc Tsil ByteArray
b ByteArray
arr)) Radix1Tree a
t
updateMaxWithKey1 :: (Build1 -> a -> Maybe a) -> Radix1Tree a -> Radix1Tree a
updateMaxWithKey1 :: forall a. (Build1 -> a -> Maybe a) -> Radix1Tree a -> Radix1Tree a
updateMaxWithKey1 Build1 -> a -> Maybe a
_ Radix1Tree a
Nil = Radix1Tree a
forall a. Radix1Tree a
Nil
updateMaxWithKey1 Build1 -> a -> Maybe a
f Radix1Tree a
r = (Build1 -> a -> Maybe a) -> Radix1Tree a -> Radix1Tree a
forall a. (Build1 -> a -> Maybe a) -> Radix1Tree a -> Radix1Tree a
unsafeUpdateMaxWithKey1 Build1 -> a -> Maybe a
f Radix1Tree a
r
unsafeUpdateMaxWithKey1 :: (Build1 -> a -> Maybe a) -> Radix1Tree a -> Radix1Tree a
unsafeUpdateMaxWithKey1 :: forall a. (Build1 -> a -> Maybe a) -> Radix1Tree a -> Radix1Tree a
unsafeUpdateMaxWithKey1 Build1 -> a -> Maybe a
f = (Tsil ByteArray -> ByteArray -> a -> Maybe a)
-> Radix1Tree a -> Radix1Tree a
forall a.
(Tsil ByteArray -> ByteArray -> a -> Maybe a)
-> Radix1Tree a -> Radix1Tree a
unsafeUpdateMaxWithKey_ (\Tsil ByteArray
b ByteArray
arr -> Build1 -> a -> Maybe a
f (YtpmeNon ByteArray -> Build1
Build1 (YtpmeNon ByteArray -> Build1) -> YtpmeNon ByteArray -> Build1
forall a b. (a -> b) -> a -> b
$ Tsil ByteArray
b Tsil ByteArray -> ByteArray -> YtpmeNon ByteArray
forall a. Tsil a -> a -> YtpmeNon a
:/ ByteArray
arr))
{-# INLINE unsafeUpdateMaxWithKey_ #-}
unsafeUpdateMaxWithKey_
:: (Tsil ByteArray -> ByteArray -> a -> Maybe a) -> Radix1Tree a -> Radix1Tree a
unsafeUpdateMaxWithKey_ :: forall a.
(Tsil ByteArray -> ByteArray -> a -> Maybe a)
-> Radix1Tree a -> Radix1Tree a
unsafeUpdateMaxWithKey_ Tsil ByteArray -> ByteArray -> a -> Maybe a
f = Tsil ByteArray -> Radix1Tree a -> Radix1Tree a
go Tsil ByteArray
forall a. Tsil a
Lin
where
go :: Tsil ByteArray -> Radix1Tree a -> Radix1Tree a
go Tsil ByteArray
b Radix1Tree a
t =
case Radix1Tree a
t of
Bin Prefix
p Radix1Tree a
l Radix1Tree a
r -> Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
forall a. Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
rebinR Prefix
p Radix1Tree a
l (Tsil ByteArray -> Radix1Tree a -> Radix1Tree a
go Tsil ByteArray
b Radix1Tree a
r)
Tip ByteArray
arr Maybe a
mx Radix1Tree a
dx -> case Radix1Tree a
dx of
Radix1Tree a
Nil | Just a
x <- Maybe a
mx -> ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
retip ByteArray
arr (Tsil ByteArray -> ByteArray -> a -> Maybe a
f Tsil ByteArray
b ByteArray
arr a
x) Radix1Tree a
dx
Radix1Tree a
_ -> ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
retip ByteArray
arr Maybe a
mx (Tsil ByteArray -> Radix1Tree a -> Radix1Tree a
go (Tsil ByteArray -> ByteArray -> Tsil ByteArray
forall a. Tsil a -> a -> Tsil a
Snoc Tsil ByteArray
b ByteArray
arr) Radix1Tree a
dx)
Radix1Tree a
Nil -> Radix1Tree a
forall a. Radix1Tree a
Nil
data ViewL a = ViewL !Build a !(RadixTree a)
deriving Int -> ViewL a -> ShowS
[ViewL a] -> ShowS
ViewL a -> String
(Int -> ViewL a -> ShowS)
-> (ViewL a -> String) -> ([ViewL a] -> ShowS) -> Show (ViewL a)
forall a. Show a => Int -> ViewL a -> ShowS
forall a. Show a => [ViewL a] -> ShowS
forall a. Show a => ViewL a -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: forall a. Show a => Int -> ViewL a -> ShowS
showsPrec :: Int -> ViewL a -> ShowS
$cshow :: forall a. Show a => ViewL a -> String
show :: ViewL a -> String
$cshowList :: forall a. Show a => [ViewL a] -> ShowS
showList :: [ViewL a] -> ShowS
Show
minView0 :: RadixTree a -> Maybe (ViewL a)
minView0 :: forall a. RadixTree a -> Maybe (ViewL a)
minView0 (RadixTree Maybe a
mx Radix1Tree a
t) =
case Maybe a
mx of
Just a
x -> ViewL a -> Maybe (ViewL a)
forall a. a -> Maybe a
Just (ViewL a -> Maybe (ViewL a)) -> ViewL a -> Maybe (ViewL a)
forall a b. (a -> b) -> a -> b
$! Build -> a -> RadixTree a -> ViewL a
forall a. Build -> a -> RadixTree a -> ViewL a
ViewL (Tsil ByteArray -> Build
Build Tsil ByteArray
forall a. Tsil a
Lin) a
x (Maybe a -> Radix1Tree a -> RadixTree a
forall a. Maybe a -> Radix1Tree a -> RadixTree a
RadixTree Maybe a
forall a. Maybe a
Nothing Radix1Tree a
t)
Maybe a
Nothing ->
case Radix1Tree a
t of
Radix1Tree a
Nil -> Maybe (ViewL a)
forall a. Maybe a
Nothing
Radix1Tree a
_ -> ViewL a -> Maybe (ViewL a)
forall a. a -> Maybe a
Just (ViewL a -> Maybe (ViewL a)) -> ViewL a -> Maybe (ViewL a)
forall a b. (a -> b) -> a -> b
$! let !(# !Tsil ByteArray
b, !ByteArray
arr, a
x, !Radix1Tree a
t' #) = Radix1Tree a -> (# Tsil ByteArray, ByteArray, a, Radix1Tree a #)
forall a.
Radix1Tree a -> (# Tsil ByteArray, ByteArray, a, Radix1Tree a #)
unsafeMinView_ Radix1Tree a
t
in Build -> a -> RadixTree a -> ViewL a
forall a. Build -> a -> RadixTree a -> ViewL a
ViewL (Tsil ByteArray -> Build
Build (Tsil ByteArray -> Build) -> Tsil ByteArray -> Build
forall a b. (a -> b) -> a -> b
$ Tsil ByteArray -> ByteArray -> Tsil ByteArray
forall a. Tsil a -> a -> Tsil a
Snoc Tsil ByteArray
b ByteArray
arr) a
x (Maybe a -> Radix1Tree a -> RadixTree a
forall a. Maybe a -> Radix1Tree a -> RadixTree a
RadixTree Maybe a
mx Radix1Tree a
t')
data ViewL1 a = ViewL1 !Build1 a !(Radix1Tree a)
deriving Int -> ViewL1 a -> ShowS
[ViewL1 a] -> ShowS
ViewL1 a -> String
(Int -> ViewL1 a -> ShowS)
-> (ViewL1 a -> String) -> ([ViewL1 a] -> ShowS) -> Show (ViewL1 a)
forall a. Show a => Int -> ViewL1 a -> ShowS
forall a. Show a => [ViewL1 a] -> ShowS
forall a. Show a => ViewL1 a -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: forall a. Show a => Int -> ViewL1 a -> ShowS
showsPrec :: Int -> ViewL1 a -> ShowS
$cshow :: forall a. Show a => ViewL1 a -> String
show :: ViewL1 a -> String
$cshowList :: forall a. Show a => [ViewL1 a] -> ShowS
showList :: [ViewL1 a] -> ShowS
Show
minView1 :: Radix1Tree a -> Maybe (ViewL1 a)
minView1 :: forall a. Radix1Tree a -> Maybe (ViewL1 a)
minView1 Radix1Tree a
Nil = Maybe (ViewL1 a)
forall a. Maybe a
Nothing
minView1 Radix1Tree a
t = ViewL1 a -> Maybe (ViewL1 a)
forall a. a -> Maybe a
Just (ViewL1 a -> Maybe (ViewL1 a)) -> ViewL1 a -> Maybe (ViewL1 a)
forall a b. (a -> b) -> a -> b
$! Radix1Tree a -> ViewL1 a
forall a. Radix1Tree a -> ViewL1 a
unsafeMinView1 Radix1Tree a
t
unsafeMinView1 :: Radix1Tree a -> ViewL1 a
unsafeMinView1 :: forall a. Radix1Tree a -> ViewL1 a
unsafeMinView1 Radix1Tree a
t =
let !(# !Tsil ByteArray
b, !ByteArray
arr, a
x, !Radix1Tree a
t' #) = Radix1Tree a -> (# Tsil ByteArray, ByteArray, a, Radix1Tree a #)
forall a.
Radix1Tree a -> (# Tsil ByteArray, ByteArray, a, Radix1Tree a #)
unsafeMinView_ Radix1Tree a
t
in Build1 -> a -> Radix1Tree a -> ViewL1 a
forall a. Build1 -> a -> Radix1Tree a -> ViewL1 a
ViewL1 (YtpmeNon ByteArray -> Build1
Build1 (YtpmeNon ByteArray -> Build1) -> YtpmeNon ByteArray -> Build1
forall a b. (a -> b) -> a -> b
$ Tsil ByteArray
b Tsil ByteArray -> ByteArray -> YtpmeNon ByteArray
forall a. Tsil a -> a -> YtpmeNon a
:/ ByteArray
arr) a
x Radix1Tree a
t'
unsafeMinView_ :: Radix1Tree a -> (# Tsil ByteArray, ByteArray, a, Radix1Tree a #)
unsafeMinView_ :: forall a.
Radix1Tree a -> (# Tsil ByteArray, ByteArray, a, Radix1Tree a #)
unsafeMinView_ = Tsil ByteArray
-> Radix1Tree a -> (# Tsil ByteArray, ByteArray, a, Radix1Tree a #)
forall {c}.
Tsil ByteArray
-> Radix1Tree c -> (# Tsil ByteArray, ByteArray, c, Radix1Tree c #)
go Tsil ByteArray
forall a. Tsil a
Lin
where
go :: Tsil ByteArray
-> Radix1Tree c -> (# Tsil ByteArray, ByteArray, c, Radix1Tree c #)
go Tsil ByteArray
b Radix1Tree c
t =
case Radix1Tree c
t of
Bin Prefix
p Radix1Tree c
l Radix1Tree c
r ->
let !(# !Tsil ByteArray
b', !ByteArray
brr, c
z, !Radix1Tree c
l' #) = Tsil ByteArray
-> Radix1Tree c -> (# Tsil ByteArray, ByteArray, c, Radix1Tree c #)
go Tsil ByteArray
b Radix1Tree c
l
in (# Tsil ByteArray
b', ByteArray
brr, c
z, Prefix -> Radix1Tree c -> Radix1Tree c -> Radix1Tree c
forall a. Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
rebinL Prefix
p Radix1Tree c
l' Radix1Tree c
r #)
Tip ByteArray
arr Maybe c
mx Radix1Tree c
dx ->
case Maybe c
mx of
Just c
x -> (# Tsil ByteArray
b, ByteArray
arr, c
x, ByteArray -> Maybe c -> Radix1Tree c -> Radix1Tree c
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
retip ByteArray
arr Maybe c
forall a. Maybe a
Nothing Radix1Tree c
dx #)
Maybe c
Nothing ->
let !(# !Tsil ByteArray
b', !ByteArray
brr, c
z, !Radix1Tree c
dy #) = Tsil ByteArray
-> Radix1Tree c -> (# Tsil ByteArray, ByteArray, c, Radix1Tree c #)
go (Tsil ByteArray -> ByteArray -> Tsil ByteArray
forall a. Tsil a -> a -> Tsil a
Snoc Tsil ByteArray
b ByteArray
arr) Radix1Tree c
dx
in (# Tsil ByteArray
b', ByteArray
brr, c
z, ByteArray -> Maybe c -> Radix1Tree c -> Radix1Tree c
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
retip ByteArray
arr Maybe c
mx Radix1Tree c
dy #)
Radix1Tree c
Nil -> MalformedTree -> (# Tsil ByteArray, ByteArray, c, Radix1Tree c #)
forall a e. Exception e => e -> a
throw (MalformedTree -> (# Tsil ByteArray, ByteArray, c, Radix1Tree c #))
-> MalformedTree
-> (# Tsil ByteArray, ByteArray, c, Radix1Tree c #)
forall a b. (a -> b) -> a -> b
$ String -> String -> MalformedTree
MalformedTree String
moduleLoc1 String
"minView"
data ViewR a = ViewR !(RadixTree a) !Build a
deriving Int -> ViewR a -> ShowS
[ViewR a] -> ShowS
ViewR a -> String
(Int -> ViewR a -> ShowS)
-> (ViewR a -> String) -> ([ViewR a] -> ShowS) -> Show (ViewR a)
forall a. Show a => Int -> ViewR a -> ShowS
forall a. Show a => [ViewR a] -> ShowS
forall a. Show a => ViewR a -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: forall a. Show a => Int -> ViewR a -> ShowS
showsPrec :: Int -> ViewR a -> ShowS
$cshow :: forall a. Show a => ViewR a -> String
show :: ViewR a -> String
$cshowList :: forall a. Show a => [ViewR a] -> ShowS
showList :: [ViewR a] -> ShowS
Show
maxView0 :: RadixTree a -> Maybe (ViewR a)
maxView0 :: forall a. RadixTree a -> Maybe (ViewR a)
maxView0 (RadixTree Maybe a
mx Radix1Tree a
t) =
case Radix1Tree a
t of
Radix1Tree a
Nil -> RadixTree a -> Build -> a -> ViewR a
forall a. RadixTree a -> Build -> a -> ViewR a
ViewR (Maybe a -> Radix1Tree a -> RadixTree a
forall a. Maybe a -> Radix1Tree a -> RadixTree a
RadixTree Maybe a
forall a. Maybe a
Nothing Radix1Tree a
t) (Tsil ByteArray -> Build
Build Tsil ByteArray
forall a. Tsil a
Lin) (a -> ViewR a) -> Maybe a -> Maybe (ViewR a)
forall a b. (a -> b) -> Maybe a -> Maybe b
`fmap'` Maybe a
mx
Radix1Tree a
_ -> ViewR a -> Maybe (ViewR a)
forall a. a -> Maybe a
Just (ViewR a -> Maybe (ViewR a)) -> ViewR a -> Maybe (ViewR a)
forall a b. (a -> b) -> a -> b
$! let !(# !Radix1Tree a
t', !Tsil ByteArray
b, !ByteArray
arr, a
x #) = Radix1Tree a -> (# Radix1Tree a, Tsil ByteArray, ByteArray, a #)
forall a.
Radix1Tree a -> (# Radix1Tree a, Tsil ByteArray, ByteArray, a #)
unsafeMaxView_ Radix1Tree a
t
in RadixTree a -> Build -> a -> ViewR a
forall a. RadixTree a -> Build -> a -> ViewR a
ViewR (Maybe a -> Radix1Tree a -> RadixTree a
forall a. Maybe a -> Radix1Tree a -> RadixTree a
RadixTree Maybe a
mx Radix1Tree a
t') (Tsil ByteArray -> Build
Build (Tsil ByteArray -> Build) -> Tsil ByteArray -> Build
forall a b. (a -> b) -> a -> b
$ Tsil ByteArray -> ByteArray -> Tsil ByteArray
forall a. Tsil a -> a -> Tsil a
Snoc Tsil ByteArray
b ByteArray
arr) a
x
data ViewR1 a = ViewR1 !(Radix1Tree a) !Build1 a
deriving Int -> ViewR1 a -> ShowS
[ViewR1 a] -> ShowS
ViewR1 a -> String
(Int -> ViewR1 a -> ShowS)
-> (ViewR1 a -> String) -> ([ViewR1 a] -> ShowS) -> Show (ViewR1 a)
forall a. Show a => Int -> ViewR1 a -> ShowS
forall a. Show a => [ViewR1 a] -> ShowS
forall a. Show a => ViewR1 a -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: forall a. Show a => Int -> ViewR1 a -> ShowS
showsPrec :: Int -> ViewR1 a -> ShowS
$cshow :: forall a. Show a => ViewR1 a -> String
show :: ViewR1 a -> String
$cshowList :: forall a. Show a => [ViewR1 a] -> ShowS
showList :: [ViewR1 a] -> ShowS
Show
maxView1 :: Radix1Tree a -> Maybe (ViewR1 a)
maxView1 :: forall a. Radix1Tree a -> Maybe (ViewR1 a)
maxView1 Radix1Tree a
Nil = Maybe (ViewR1 a)
forall a. Maybe a
Nothing
maxView1 Radix1Tree a
t = ViewR1 a -> Maybe (ViewR1 a)
forall a. a -> Maybe a
Just (ViewR1 a -> Maybe (ViewR1 a)) -> ViewR1 a -> Maybe (ViewR1 a)
forall a b. (a -> b) -> a -> b
$! Radix1Tree a -> ViewR1 a
forall a. Radix1Tree a -> ViewR1 a
unsafeMaxView1 Radix1Tree a
t
unsafeMaxView1 :: Radix1Tree a -> ViewR1 a
unsafeMaxView1 :: forall a. Radix1Tree a -> ViewR1 a
unsafeMaxView1 Radix1Tree a
t =
let !(# !Radix1Tree a
t', !Tsil ByteArray
b, !ByteArray
arr, a
x #) = Radix1Tree a -> (# Radix1Tree a, Tsil ByteArray, ByteArray, a #)
forall a.
Radix1Tree a -> (# Radix1Tree a, Tsil ByteArray, ByteArray, a #)
unsafeMaxView_ Radix1Tree a
t
in Radix1Tree a -> Build1 -> a -> ViewR1 a
forall a. Radix1Tree a -> Build1 -> a -> ViewR1 a
ViewR1 Radix1Tree a
t' (YtpmeNon ByteArray -> Build1
Build1 (YtpmeNon ByteArray -> Build1) -> YtpmeNon ByteArray -> Build1
forall a b. (a -> b) -> a -> b
$ Tsil ByteArray
b Tsil ByteArray -> ByteArray -> YtpmeNon ByteArray
forall a. Tsil a -> a -> YtpmeNon a
:/ ByteArray
arr) a
x
unsafeMaxView_ :: Radix1Tree a -> (# Radix1Tree a, Tsil ByteArray, ByteArray, a #)
unsafeMaxView_ :: forall a.
Radix1Tree a -> (# Radix1Tree a, Tsil ByteArray, ByteArray, a #)
unsafeMaxView_ = Tsil ByteArray
-> Radix1Tree a -> (# Radix1Tree a, Tsil ByteArray, ByteArray, a #)
forall {d}.
Tsil ByteArray
-> Radix1Tree d -> (# Radix1Tree d, Tsil ByteArray, ByteArray, d #)
go Tsil ByteArray
forall a. Tsil a
Lin
where
go :: Tsil ByteArray
-> Radix1Tree d -> (# Radix1Tree d, Tsil ByteArray, ByteArray, d #)
go Tsil ByteArray
b Radix1Tree d
t =
case Radix1Tree d
t of
Bin Prefix
p Radix1Tree d
l Radix1Tree d
r ->
let !(# !Radix1Tree d
r', !Tsil ByteArray
b', !ByteArray
brr, d
z #) = Tsil ByteArray
-> Radix1Tree d -> (# Radix1Tree d, Tsil ByteArray, ByteArray, d #)
go Tsil ByteArray
b Radix1Tree d
r
in (# Prefix -> Radix1Tree d -> Radix1Tree d -> Radix1Tree d
forall a. Prefix -> Radix1Tree a -> Radix1Tree a -> Radix1Tree a
rebinR Prefix
p Radix1Tree d
l Radix1Tree d
r', Tsil ByteArray
b', ByteArray
brr, d
z #)
Tip ByteArray
arr Maybe d
mx Radix1Tree d
dx ->
case Radix1Tree d
dx of
Radix1Tree d
Nil | Just d
x <- Maybe d
mx -> (# ByteArray -> Maybe d -> Radix1Tree d -> Radix1Tree d
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
retip ByteArray
arr Maybe d
forall a. Maybe a
Nothing Radix1Tree d
dx, Tsil ByteArray
b, ByteArray
arr, d
x #)
Radix1Tree d
_ ->
let !(# !Radix1Tree d
dy, !Tsil ByteArray
b', !ByteArray
brr, d
z #) = Tsil ByteArray
-> Radix1Tree d -> (# Radix1Tree d, Tsil ByteArray, ByteArray, d #)
go (Tsil ByteArray -> ByteArray -> Tsil ByteArray
forall a. Tsil a -> a -> Tsil a
Snoc Tsil ByteArray
b ByteArray
arr) Radix1Tree d
dx
in (# ByteArray -> Maybe d -> Radix1Tree d -> Radix1Tree d
forall a. ByteArray -> Maybe a -> Radix1Tree a -> Radix1Tree a
retip ByteArray
arr Maybe d
mx Radix1Tree d
dy, Tsil ByteArray
b', ByteArray
brr, d
z #)
Radix1Tree d
Nil -> MalformedTree -> (# Radix1Tree d, Tsil ByteArray, ByteArray, d #)
forall a e. Exception e => e -> a
throw (MalformedTree -> (# Radix1Tree d, Tsil ByteArray, ByteArray, d #))
-> MalformedTree
-> (# Radix1Tree d, Tsil ByteArray, ByteArray, d #)
forall a b. (a -> b) -> a -> b
$ String -> String -> MalformedTree
MalformedTree String
moduleLoc1 String
"maxView"