{-# LANGUAGE CPP, BangPatterns #-}
module Languages.UniquenessPeriods.Vector.StrictV (
uniquenessVariants2GN
, uniquenessVariants2GNP
, sublistsG
, preAppend
) where
#ifdef __GLASGOW_HASKELL__
#if __GLASGOW_HASKELL__>=804
/* code that applies only to GHC 8.4.* and higher versions */
import Data.Semigroup ((<>))
import Prelude hiding ((<>))
#endif
#endif
#ifdef __GLASGOW_HASKELL__
#if __GLASGOW_HASKELL__>=710
/* code that applies only to GHC 7.10.* and higher versions */
import GHC.Base (mconcat)
#endif
#endif
import qualified Data.Vector as V
import qualified Data.List as L (permutations)
import Languages.UniquenessPeriods.Vector.Data
#ifdef __GLASGOW_HASKELL__
#if __GLASGOW_HASKELL__==708
/* code that applies only to GHC 7.8.* */
mconcat = concat
#endif
#endif
uniquenessVariants2GN ::
(Eq a, Ord b) => [a]
-> V.Vector ([b] -> b)
-> FuncRep [a] (V.Vector c) [b]
-> [a]
-> V.Vector ([b],V.Vector b, [a])
uniquenessVariants2GN whspss vN frep !xs = uniquenessVariants2GNP [] [] whspss vN frep xs
{-# INLINE uniquenessVariants2GN #-}
uniquenessVariants2GNP ::
(Eq a, Ord b) => [a]
-> [a]
-> [a]
-> V.Vector ([b] -> b)
-> FuncRep [a] (V.Vector c) [b]
-> [a]
-> V.Vector ([b],V.Vector b, [a])
uniquenessVariants2GNP !ts !us whspss vN frep !xs
| null . sublistsG whspss $ xs = V.empty
| not . null $ whspss =
let !hd = head whspss
!ns = take 8 . sublistsG whspss $ xs
!uss = [hd:us] in
V.fromList . map ((\vs -> let !rs = getAC frep $ vs in (rs, (V.map (\f -> f rs) vN), vs)) . mconcat . preAppend ts uss) .
L.permutations . map (hd:) $ ns
| otherwise = error "Languages.UniquenessPeriods.Vector.StrictV.uniquenessVariants2GNP: undefined for the empty third argument. "
sublistsG :: Eq a => [a] -> [a] -> [[a]]
sublistsG whspss xs =
case dropWhile (`elem` whspss) xs of
[] -> []
s' -> w : sublistsG whspss s''
where (w, s'') = break (`elem` whspss) s'
preAppend :: [a] -> [[a]] -> [[a]] -> [[a]]
#ifdef __GLASGOW_HASKELL__
#if __GLASGOW_HASKELL__>=804
preAppend ts !uss tss = ts:tss <> uss
#endif
#endif
#ifdef __GLASGOW_HASKELL__
#if __GLASGOW_HASKELL__<804
preAppend ts !uss tss = ts:tss ++ uss
#endif
#endif
{-# INLINE preAppend #-}