module Data.Median.Optimal
(median3
,median4
,median5)
where
import GHC.Exts (inline)
median3 :: (a -> a -> Bool) -> a -> a -> a -> Int
median3 lte a b c =
if inline lte a b
then
if inline lte a c
then
if inline lte b c
then 1
else 2
else 0
else
if inline lte b c
then
if inline lte a c
then 0
else 2
else 1
{-# INLINE median3 #-}
median4 :: (a -> a -> Bool) -> a -> a -> a -> a -> Int
median4 lte a b c d =
if inline lte a b
then
if inline lte c d
then
if inline lte b d
then 1
else 3
else
if inline lte b c
then 1
else 2
else
if inline lte c d
then
if inline lte a d
then 0
else 3
else
if inline lte a c
then 0
else 2
{-# INLINE median4 #-}
median5 :: (a -> a -> Bool) -> a -> a -> a -> a -> a -> Int
median5 lte a b c d e =
if inline lte a b
then
if inline lte c d
then
if inline lte a c
then
if inline lte b d
then
if inline lte b c
then
if inline lte a e
then
if inline lte c e
then 2
else
if inline lte b e
then 4
else 1
else 1
else
if inline lte a e
then
if inline lte b e
then 1
else
if inline lte c e
then 4
else 2
else 2
else
if inline lte a e
then
if inline lte d e
then 3
else
if inline lte c e
then 4
else 2
else
if inline lte d a
then 3
else 2
else
if inline lte b d
then
if inline lte c e
then
if inline lte b e
then 1
else
if inline lte a e
then 4
else 0
else
if inline lte b c
then 1
else 0
else
if inline lte d a
then
if inline lte c e
then
if inline lte a e
then 0
else
if inline lte d e
then 4
else 3
else 3
else
if inline lte c e
then
if inline lte d e
then 3
else
if inline lte a e
then 4
else 0
else 0
else
if inline lte a d
then
if inline lte b c
then
if inline lte b d
then
if inline lte a e
then
if inline lte d e
then 3
else
if inline lte b e
then 4
else 1
else 1
else
if inline lte a e
then
if inline lte b e
then 1
else
if inline lte d e
then 4
else 3
else 3
else
if inline lte a e
then
if inline lte c e
then 2
else
if inline lte d e
then 4
else 3
else
if inline lte c a
then 2
else 3
else
if inline lte b c
then
if inline lte d e
then
if inline lte b e
then 1
else
if inline lte a e
then 4
else 0
else
if inline lte b d
then 1
else 0
else
if inline lte c a
then
if inline lte d e
then
if inline lte a e
then 0
else
if inline lte c e
then 4
else 2
else 2
else
if inline lte d e
then
if inline lte c e
then 2
else
if inline lte a e
then 4
else 0
else 0
else
if inline lte c d
then
if inline lte b c
then
if inline lte a d
then
if inline lte a c
then
if inline lte b e
then
if inline lte c e
then 2
else
if inline lte a e
then 4
else 0
else 0
else
if inline lte b e
then
if inline lte a e
then 0
else
if inline lte c e
then 4
else 2
else 2
else
if inline lte b e
then
if inline lte d e
then 3
else
if inline lte c e
then 4
else 2
else
if inline lte d b
then 3
else 2
else
if inline lte a d
then
if inline lte c e
then
if inline lte a e
then 0
else
if inline lte b e
then 4
else 1
else
if inline lte a c
then 0
else 1
else
if inline lte d b
then
if inline lte c e
then
if inline lte b e
then 1
else
if inline lte d e
then 4
else 3
else 3
else
if inline lte c e
then
if inline lte d e
then 3
else
if inline lte b e
then 4
else 1
else 1
else
if inline lte b d
then
if inline lte a c
then
if inline lte a d
then
if inline lte b e
then
if inline lte d e
then 3
else
if inline lte a e
then 4
else 0
else 0
else
if inline lte b e
then
if inline lte a e
then 0
else
if inline lte d e
then 4
else 3
else 3
else
if inline lte b e
then
if inline lte c e
then 2
else
if inline lte d e
then 4
else 3
else
if inline lte c b
then 2
else 3
else
if inline lte a c
then
if inline lte d e
then
if inline lte a e
then 0
else
if inline lte b e
then 4
else 1
else
if inline lte a d
then 0
else 1
else
if inline lte c b
then
if inline lte d e
then
if inline lte b e
then 1
else
if inline lte c e
then 4
else 2
else 2
else
if inline lte d e
then
if inline lte c e
then 2
else
if inline lte b e
then 4
else 1
else 1
{-# INLINE median5 #-}