{-# OPTIONS_HADDOCK hide #-}
module Data.Tree.AVL.Size
(
size,addSize,clipSize,
addSize#,size#,
) where
import Data.Tree.AVL.Internals.Types(AVL(..))
import Data.Tree.AVL.Height(addHeight)
import GHC.Base
#include "ghcdefs.h"
size :: AVL e -> Int
size :: forall e. AVL e -> Int
size AVL e
t = ASINT(addSize# L(0) t)
{-# INLINE size #-}
size# :: AVL e -> UINT
size# :: forall e. AVL e -> Int#
size# AVL e
t = Int# -> AVL e -> Int#
forall e. Int# -> AVL e -> Int#
addSize# L(0AVL e
) t
{-# INLINE size# #-}
addSize :: Int -> AVL e -> Int
addSize :: forall e. Int -> AVL e -> Int
addSize ASINT(n) AVL e
t = ASINT(addSize# n t)
{-# INLINE addSize #-}
#define AddSize addSize#
AddSize :: UINT -> AVL e -> UINT
AddSize n E = n
AddSize n (N l _ rAVL e
) = case addHeight L(2) l of
L(2) -> INCINT2(n)
L(3) -> fas2 INCINT2(n) r
h -> fasNP n h l r
AddSize n (Z l _ rAVL e
) = case addHeight L(1) l of
L(1) -> INCINT1(n)
L(2) -> INCINT3(n)
L(3) -> fas2 (fas2 INCINT1(n) l) r
h -> fasZ n h l r
AddSize n (P l _ rAVL e
) = case addHeight L(2) r of
L(2) -> INCINT2(n)
L(3) -> fas2 INCINT2(n) l
h -> fasNP n h r l
fasNP,fasZ :: UINT -> UINT -> AVL e -> AVL e -> UINT
fasNP :: forall e. Int# -> Int# -> AVL e -> AVL e -> Int#
fasNP Int#
n Int#
h AVL e
l AVL e
r = Int# -> Int# -> AVL e -> Int#
forall e. Int# -> Int# -> AVL e -> Int#
fasG3 (Int# -> Int# -> AVL e -> Int#
forall e. Int# -> Int# -> AVL e -> Int#
fasG2 INCINT1(n) DECINT2(hAVL e
) l) DECINT1(AVL e
h) r
fasZ :: forall e. Int# -> Int# -> AVL e -> AVL e -> Int#
fasZ Int#
n Int#
h AVL e
l AVL e
r = Int# -> Int# -> AVL e -> Int#
forall e. Int# -> Int# -> AVL e -> Int#
fasG3 (Int# -> Int# -> AVL e -> Int#
forall e. Int# -> Int# -> AVL e -> Int#
fasG3 INCINT1(n) DECINT1(hAVL e
) l) DECINT1(AVL e
h) r
fasG2 :: UINT -> UINT -> AVL e -> UINT
fasG2 :: forall e. Int# -> Int# -> AVL e -> Int#
fasG2 Int#
n L(2) t = fas2 n t
fasG2 Int#
n Int#
h AVL e
t = Int# -> Int# -> AVL e -> Int#
forall e. Int# -> Int# -> AVL e -> Int#
fasG3 Int#
n Int#
h AVL e
t
{-# INLINE fasG2 #-}
fasG3 :: UINT -> UINT -> AVL e -> UINT
fasG3 :: forall e. Int# -> Int# -> AVL e -> Int#
fasG3 Int#
n L(3) (AVL e
N e
_ AVL e
_ r) = fas2 INCINT2(AVL e
n) r
fasG3 Int#
n L(3) (AVL e
Z e
l AVL e
_ r) = fas2 (fas2 INCINT1(n) AVL e
l) r
fasG3 Int#
n L(3) (AVL e
P e
l AVL e
_ _) = fas2 INCINT2(AVL e
n) l
fasG3 Int#
n Int#
h (N AVL e
l e
_ AVL e
r) = Int# -> Int# -> AVL e -> AVL e -> Int#
forall e. Int# -> Int# -> AVL e -> AVL e -> Int#
fasNP Int#
n Int#
h AVL e
l AVL e
r
fasG3 Int#
n Int#
h (Z AVL e
l e
_ AVL e
r) = Int# -> Int# -> AVL e -> AVL e -> Int#
forall e. Int# -> Int# -> AVL e -> AVL e -> Int#
fasZ Int#
n Int#
h AVL e
l AVL e
r
fasG3 Int#
n Int#
h (P AVL e
l e
_ AVL e
r) = Int# -> Int# -> AVL e -> AVL e -> Int#
forall e. Int# -> Int# -> AVL e -> AVL e -> Int#
fasNP Int#
n Int#
h AVL e
r AVL e
l
fasG3 Int#
_ Int#
_ AVL e
E = [Char] -> Int#
forall a. HasCallStack => [Char] -> a
error [Char]
"AddSize: Bad Tree."
fas2 :: UINT -> AVL e -> UINT
fas2 :: forall e. Int# -> AVL e -> Int#
fas2 Int#
n (N AVL e
_ e
_ AVL e
_) = INCINT2(n)
fas2 Int#
n (Z AVL e
_ e
_ AVL e
_) = INCINT3(n)
fas2 Int#
n (P AVL e
_ e
_ AVL e
_) = INCINT2(n)
fas2 Int#
_ AVL e
E = [Char] -> Int#
forall a. HasCallStack => [Char] -> a
error [Char]
"AddSize: Bad Tree."
{-# INLINE fas2 #-}
clipSize :: Int -> AVL e -> Maybe Int
clipSize :: forall e. Int -> AVL e -> Maybe Int
clipSize ASINT(c) AVL e
t = let c_ :: Int#
c_ = Int# -> AVL e -> Int#
forall e. Int# -> AVL e -> Int#
cSzh Int#
c AVL e
t in if Int# -> Bool
isTrue# (Int#
c_ LTN L(0))
then Maybe Int
forall a. Maybe a
Nothing
else Int -> Maybe Int
forall a. a -> Maybe a
Just ASINT(SUBINT(c,c_))
cSzh :: UINT -> AVL e -> UINT
cSzh :: forall e. Int# -> AVL e -> Int#
cSzh Int#
c AVL e
E = Int#
c
cSzh Int#
c (N AVL e
l e
_ AVL e
r) = case Int# -> AVL e -> Int#
forall e. Int# -> AVL e -> Int#
addHeight L(2AVL e
) l of
L(2) -> DECINT2(c)
L(3) -> cSzNP3 c r
Int#
h -> Int# -> Int# -> AVL e -> AVL e -> Int#
forall e. Int# -> Int# -> AVL e -> AVL e -> Int#
cSzNP Int#
c Int#
h AVL e
l AVL e
r
cSzh Int#
c (Z AVL e
l e
_ AVL e
r) = case Int# -> AVL e -> Int#
forall e. Int# -> AVL e -> Int#
addHeight L(1AVL e
) l of
L(1) -> DECINT1(c)
L(2) -> DECINT3(c)
L(3) -> cSzZ3 c l r
Int#
h -> Int# -> Int# -> AVL e -> AVL e -> Int#
forall e. Int# -> Int# -> AVL e -> AVL e -> Int#
cSzZ Int#
c Int#
h AVL e
l AVL e
r
cSzh Int#
c (P AVL e
l e
_ AVL e
r) = case Int# -> AVL e -> Int#
forall e. Int# -> AVL e -> Int#
addHeight L(2AVL e
) r of
L(2) -> DECINT2(c)
L(3) -> cSzNP3 c l
Int#
h -> Int# -> Int# -> AVL e -> AVL e -> Int#
forall e. Int# -> Int# -> AVL e -> AVL e -> Int#
cSzNP Int#
c Int#
h AVL e
r AVL e
l
cSzNP3 :: UINT -> AVL e -> UINT
cSzNP3 :: forall e. Int# -> AVL e -> Int#
cSzNP3 Int#
c AVL e
t = if Int# -> Bool
isTrue# (Int#
c LTN L(4)) then L(-1) Int# -> AVL e -> Int#
forall e. Int# -> AVL e -> Int#
else cSz2 DECINT2(c) t
cSzZ3 :: UINT -> AVL e -> AVL e -> UINT
cSzZ3 :: forall e. Int# -> AVL e -> AVL e -> Int#
cSzZ3 Int#
c AVL e
l AVL e
r = if Int# -> Bool
isTrue# (Int#
c LTN L(5)) then L(-1)
else let c_ :: Int#
c_ = Int# -> AVL e -> Int#
forall e. Int# -> AVL e -> Int#
cSz2 DECINT1(c) l
in if Int# -> Bool
isTrue# (Int#
c_ LTN L(2)) then L(-1)
else Int# -> AVL e -> Int#
forall e. Int# -> AVL e -> Int#
cSz2 Int#
c_ AVL e
r
cSzNP,cSzZ :: UINT -> UINT -> AVL e -> AVL e -> UINT
cSzNP :: forall e. Int# -> Int# -> AVL e -> AVL e -> Int#
cSzNP Int#
c Int#
h AVL e
l AVL e
r = if Int# -> Bool
isTrue# (Int#
c LTN L(7)) then L(-1)
else let c_ :: Int#
c_ = Int# -> Int# -> AVL e -> Int#
forall e. Int# -> Int# -> AVL e -> Int#
cSzG2 DECINT1(c) DECINT2(hAVL e
) l
in if Int# -> Bool
isTrue# (Int#
c_ LTN L(4)) then L(-1)
else Int# -> Int# -> AVL e -> Int#
forall e. Int# -> Int# -> AVL e -> Int#
cSzG3 Int#
c_ DECINT1(h) r
cSzZ :: forall e. Int# -> Int# -> AVL e -> AVL e -> Int#
cSzZ Int#
c Int#
h AVL e
l AVL e
r = if Int# -> Bool
isTrue# (Int#
c LTN L(9)) then L(-1)
else let c_ :: Int#
c_ = Int# -> Int# -> AVL e -> Int#
forall e. Int# -> Int# -> AVL e -> Int#
cSzG3 DECINT1(c) DECINT1(hAVL e
) l
in if Int# -> Bool
isTrue# (Int#
c_ LTN L(4)) then L(-1)
else Int# -> Int# -> AVL e -> Int#
forall e. Int# -> Int# -> AVL e -> Int#
cSzG3 Int#
c_ DECINT1(h) r
cSzG2 :: UINT -> UINT -> AVL e -> UINT
cSzG2 :: forall e. Int# -> Int# -> AVL e -> Int#
cSzG2 Int#
c L(2) t = cSz2 c t
cSzG2 Int#
c Int#
h AVL e
t = Int# -> Int# -> AVL e -> Int#
forall e. Int# -> Int# -> AVL e -> Int#
cSzG3 Int#
c Int#
h AVL e
t
{-# INLINE cSzG2 #-}
cSzG3 :: UINT -> UINT -> AVL e -> UINT
cSzG3 :: forall e. Int# -> Int# -> AVL e -> Int#
cSzG3 Int#
c L(3) (AVL e
N e
_ AVL e
_ r) = cSzNP3 c r
cSzG3 Int#
c L(3) (AVL e
Z e
l AVL e
_ r) = cSzZ3 AVL e
c AVL e
l r
cSzG3 Int#
c L(3) (AVL e
P e
l AVL e
_ _) = cSzNP3 AVL e
c l
cSzG3 Int#
c Int#
h (N AVL e
l e
_ AVL e
r) = Int# -> Int# -> AVL e -> AVL e -> Int#
forall e. Int# -> Int# -> AVL e -> AVL e -> Int#
cSzNP Int#
c Int#
h AVL e
l AVL e
r
cSzG3 Int#
c Int#
h (Z AVL e
l e
_ AVL e
r) = Int# -> Int# -> AVL e -> AVL e -> Int#
forall e. Int# -> Int# -> AVL e -> AVL e -> Int#
cSzZ Int#
c Int#
h AVL e
l AVL e
r
cSzG3 Int#
c Int#
h (P AVL e
l e
_ AVL e
r) = Int# -> Int# -> AVL e -> AVL e -> Int#
forall e. Int# -> Int# -> AVL e -> AVL e -> Int#
cSzNP Int#
c Int#
h AVL e
r AVL e
l
cSzG3 Int#
_ Int#
_ AVL e
E = [Char] -> Int#
forall a. HasCallStack => [Char] -> a
error [Char]
"clipSize: Bad Tree."
cSz2 :: UINT -> AVL e -> UINT
cSz2 :: forall e. Int# -> AVL e -> Int#
cSz2 Int#
c (N AVL e
_ e
_ AVL e
_) = DECINT2(c)
cSz2 Int#
c (Z AVL e
_ e
_ AVL e
_) = DECINT3(c)
cSz2 Int#
c (P AVL e
_ e
_ AVL e
_) = DECINT2(c)
cSz2 Int#
_ AVL e
E = [Char] -> Int#
forall a. HasCallStack => [Char] -> a
error [Char]
"clipSize: Bad Tree."
{-# INLINE cSz2 #-}