-- |
-- Module      :  Languages.UniquenessPeriods.Vector.StrictVG
-- Copyright   :  (c) OleksandrZhabenko 2020
-- License     :  MIT
-- Stability   :  Experimental
-- Maintainer  :  olexandr543@yahoo.com
--
-- Generalization of the DobutokO.Poetry.StrictV module functionality from
-- the @dobutokO-poetry-general@ package.
-- Can be used to get possible permutations of no more than 7 substructures
-- in the 'F.Foldable' structure separated with the elements of the \"whitespace symbols\"
-- structure.

{-# LANGUAGE CPP, BangPatterns, FlexibleContexts, FlexibleInstances, MultiParamTypeClasses #-}

module Languages.UniquenessPeriods.Vector.StrictVG (
  universalSetG
  , result
  , resultB
  , uniquenessVariants2GN
  , uniquenessVariants2GNB
  , uniquenessVariants2GNP
  , uniquenessVariants2GNPB
  , genPermutations
  , genPermutationsV
) where

import qualified Data.Vector.Unboxed as V
import qualified Data.Vector as VB
import qualified Data.List as L (permutations)
import Languages.UniquenessPeriods.Vector.DataG
import qualified Data.Foldable as F
import Data.SubG
import Data.Monoid

-- | A generalized variant of the 'uniquenessVariants2GN' function from the @uniqueness-periods-vector-common@ package which, moreover, allows to specify the used permutations.
uniquenessVariants2GNB ::
  (Eq a, Foldable t, InsertLeft t a, Monoid (t a), Monoid (t (t a)), Ord b, Foldable t2) => a -- ^ The first most common element in the \"whitespace symbols\" structure
  -> (t a -> VB.Vector a) -- ^ The function that is used internally to convert to the boxed 'VB.Vector' of @a@ so that the function can process further the permutations
  -> ((t (t a)) -> VB.Vector (VB.Vector a)) -- ^ The function that is used internally to convert to the boxed 'VB.Vector' of 'VB.Vector' of @a@ so that the function can process further
  -> (VB.Vector a -> t a) -- ^ The function that is used internally to convert from the boxed 'VB.Vector' of @a@ so that the function can process further
  -> VB.Vector (VB.Vector Int) -- ^ The list of permutations of 'Int' indices starting from 0 and up to n (n is probably less than 8).
  -> VB.Vector (t2 b -> b)
  -> FuncRep (t a) (VB.Vector c) (t2 b) -- ^ It includes the defined earlier variant with data constructor 'D2', but additionally allows to use just single argument with data constructor 'U1'
  -> t (t a) -- ^ Must be obtained as 'subG' @whspss xs@
  -> VB.Vector (t2 b,VB.Vector b, t a)
uniquenessVariants2GNB :: a
-> (t a -> Vector a)
-> (t (t a) -> Vector (Vector a))
-> (Vector a -> t a)
-> Vector (Vector Int)
-> Vector (t2 b -> b)
-> FuncRep (t a) (Vector c) (t2 b)
-> t (t a)
-> Vector (t2 b, Vector b, t a)
uniquenessVariants2GNB !a
hd t a -> Vector a
f1 t (t a) -> Vector (Vector a)
f2 Vector a -> t a
f3 Vector (Vector Int)
perms Vector (t2 b -> b)
vN FuncRep (t a) (Vector c) (t2 b)
frep !t (t a)
subs = t a
-> t a
-> a
-> (t a -> Vector a)
-> (t (t a) -> Vector (Vector a))
-> (Vector a -> t a)
-> Vector (Vector Int)
-> Vector (t2 b -> b)
-> FuncRep (t a) (Vector c) (t2 b)
-> t (t a)
-> Vector (t2 b, Vector b, t a)
forall a (t :: * -> *) b (t2 :: * -> *) c.
(Eq a, Foldable t, InsertLeft t a, Monoid (t a), Monoid (t (t a)),
 Ord b, Foldable t2) =>
t a
-> t a
-> a
-> (t a -> Vector a)
-> (t (t a) -> Vector (Vector a))
-> (Vector a -> t a)
-> Vector (Vector Int)
-> Vector (t2 b -> b)
-> FuncRep (t a) (Vector c) (t2 b)
-> t (t a)
-> Vector (t2 b, Vector b, t a)
uniquenessVariants2GNPB t a
forall a. Monoid a => a
mempty t a
forall a. Monoid a => a
mempty a
hd t a -> Vector a
f1 t (t a) -> Vector (Vector a)
f2 Vector a -> t a
f3 Vector (Vector Int)
perms Vector (t2 b -> b)
vN FuncRep (t a) (Vector c) (t2 b)
frep t (t a)
subs
{-# INLINE uniquenessVariants2GNB #-}

-- | A variant of the 'uniquenessVariants2GNB' with the usage of the 'V.Vector' @c@ (an unboxed one) instead of the boxed variant 'VB.Vector' @c@. If @c@ is an instance of the
-- 'V.Unboxed' class then possibly it can be better from the performance point of view to use this variant.
uniquenessVariants2GN ::
  (Eq a, Foldable t, InsertLeft t a, Monoid (t a), Monoid (t (t a)), Ord b, Foldable t2) =>  a -- ^ The first most common element in the whitespace symbols structure
  -> (t a -> VB.Vector a) -- ^ The function that is used internally to convert to the boxed 'VB.Vector' of @a@ so that the function can process further the permutations
  -> ((t (t a)) -> VB.Vector (VB.Vector a)) -- ^ The function that is used internally to convert to the boxed 'VB.Vector' of 'VB.Vector' of @a@ so that the function can process further
  -> (VB.Vector a -> t a) -- ^ The function that is used internally to convert from the boxed 'VB.Vector' of @a@ so that the function can process further
  -> VB.Vector (VB.Vector Int) -- ^ The list of permutations of 'Int' indices starting from 0 and up to n (n is probably less than 8).
  -> VB.Vector (t2 b -> b)
  -> FuncRep (t a) (V.Vector c) (t2 b) -- ^ It includes the defined earlier variant with data constructor 'D2', but additionally allows to use just single argument with data constructor 'U1'
  -> t (t a) -- ^ Must be obtained as 'subG' @whspss xs@
  -> VB.Vector (t2 b,VB.Vector b, t a)
uniquenessVariants2GN :: a
-> (t a -> Vector a)
-> (t (t a) -> Vector (Vector a))
-> (Vector a -> t a)
-> Vector (Vector Int)
-> Vector (t2 b -> b)
-> FuncRep (t a) (Vector c) (t2 b)
-> t (t a)
-> Vector (t2 b, Vector b, t a)
uniquenessVariants2GN !a
hd t a -> Vector a
f1 t (t a) -> Vector (Vector a)
f2 Vector a -> t a
f3 Vector (Vector Int)
perms Vector (t2 b -> b)
vN FuncRep (t a) (Vector c) (t2 b)
frep !t (t a)
subs = t a
-> t a
-> a
-> (t a -> Vector a)
-> (t (t a) -> Vector (Vector a))
-> (Vector a -> t a)
-> Vector (Vector Int)
-> Vector (t2 b -> b)
-> FuncRep (t a) (Vector c) (t2 b)
-> t (t a)
-> Vector (t2 b, Vector b, t a)
forall a (t :: * -> *) b (t2 :: * -> *) c.
(Eq a, Foldable t, InsertLeft t a, Monoid (t a), Monoid (t (t a)),
 Ord b, Foldable t2) =>
t a
-> t a
-> a
-> (t a -> Vector a)
-> (t (t a) -> Vector (Vector a))
-> (Vector a -> t a)
-> Vector (Vector Int)
-> Vector (t2 b -> b)
-> FuncRep (t a) (Vector c) (t2 b)
-> t (t a)
-> Vector (t2 b, Vector b, t a)
uniquenessVariants2GNP t a
forall a. Monoid a => a
mempty t a
forall a. Monoid a => a
mempty a
hd t a -> Vector a
f1 t (t a) -> Vector (Vector a)
f2 Vector a -> t a
f3 Vector (Vector Int)
perms Vector (t2 b -> b)
vN FuncRep (t a) (Vector c) (t2 b)
frep t (t a)
subs
{-# INLINE uniquenessVariants2GN #-}

-- | Generalized variant of 'uniquenessVariants2GN' with prepending and appending @[a]@ (given as the first and the second argument).
uniquenessVariants2GNPB ::
  (Eq a, Foldable t, InsertLeft t a, Monoid (t a), Monoid (t (t a)), Ord b, Foldable t2) => t a
  -> t a
  ->  a -- ^ The first most common element in the whitespace symbols structure
  -> (t a -> VB.Vector a) -- ^ The function that is used internally to convert to the boxed 'VB.Vector' of @a@ so that the function can process further the permutations
  -> ((t (t a)) -> VB.Vector (VB.Vector a)) -- ^ The function that is used internally to convert to the boxed 'VB.Vector' of 'VB.Vector' of @a@ so that the function can process further
  -> (VB.Vector a -> t a) -- ^ The function that is used internally to convert from the boxed 'VB.Vector' of @a@ so that the function can process further
  -> VB.Vector (VB.Vector Int) -- ^ The list of permutations of 'Int' indices starting from 0 and up to n (n is probably less than 7).
  -> VB.Vector (t2 b -> b)
  -> FuncRep (t a) (VB.Vector c) (t2 b) -- ^ Since version 0.5.0.0 it includes the previous variant with data constructor 'D2', but additionally allows to use just single argument with data constructor 'U1'
  -> t (t a) -- ^ Must be obtained as @subG whspss xs@
  -> VB.Vector (t2 b,VB.Vector b, t a)
uniquenessVariants2GNPB :: t a
-> t a
-> a
-> (t a -> Vector a)
-> (t (t a) -> Vector (Vector a))
-> (Vector a -> t a)
-> Vector (Vector Int)
-> Vector (t2 b -> b)
-> FuncRep (t a) (Vector c) (t2 b)
-> t (t a)
-> Vector (t2 b, Vector b, t a)
uniquenessVariants2GNPB !t a
ts !t a
us !a
hd t a -> Vector a
f1 t (t a) -> Vector (Vector a)
f2 Vector a -> t a
f3 Vector (Vector Int)
perms Vector (t2 b -> b)
vN FuncRep (t a) (Vector c) (t2 b)
frep !t (t a)
subs
  | t (t a) -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
F.null t (t a)
subs = Vector (t2 b, Vector b, t a)
forall a. Vector a
VB.empty
  | Bool
otherwise =
     let !uss :: t (t a)
uss = (a
hd a -> t a -> t a
forall (t :: * -> *) a. InsertLeft t a => a -> t a -> t a
%@ t a
us) t a -> t (t a) -> t (t a)
forall (t :: * -> *) a. InsertLeft t a => t a -> t (t a) -> t (t a)
%^ t (t a)
forall a. Monoid a => a
mempty
         !baseV :: Vector (Vector a)
baseV = (Vector a -> Vector a) -> Vector (Vector a) -> Vector (Vector a)
forall a b. (a -> b) -> Vector a -> Vector b
VB.map (a
hd a -> Vector a -> Vector a
forall a. a -> Vector a -> Vector a
`VB.cons`) (Vector (Vector a) -> Vector (Vector a))
-> (t (t a) -> Vector (Vector a)) -> t (t a) -> Vector (Vector a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. t (t a) -> Vector (Vector a)
f2 (t (t a) -> Vector (Vector a)) -> t (t a) -> Vector (Vector a)
forall a b. (a -> b) -> a -> b
$ t (t a)
subs
         !ns :: Vector (Vector a)
ns = t a
-> t (t a)
-> (t a -> Vector a)
-> (t (t a) -> Vector (Vector a))
-> Vector (Vector Int)
-> Vector (Vector a)
-> Vector (Vector a)
forall a (t :: * -> *).
(Eq a, Foldable t, InsertLeft t a, Monoid (t a),
 Monoid (t (t a))) =>
t a
-> t (t a)
-> (t a -> Vector a)
-> (t (t a) -> Vector (Vector a))
-> Vector (Vector Int)
-> Vector (Vector a)
-> Vector (Vector a)
universalSetG t a
ts t (t a)
uss t a -> Vector a
f1 t (t a) -> Vector (Vector a)
f2 Vector (Vector Int)
perms Vector (Vector a)
baseV in (Vector a -> (t2 b, Vector b, t a))
-> Vector (Vector a) -> Vector (t2 b, Vector b, t a)
forall a b. (a -> b) -> Vector a -> Vector b
VB.map ((Vector a -> t a)
-> Vector (t2 b -> b)
-> FuncRep (t a) (Vector c) (t2 b)
-> Vector a
-> (t2 b, Vector b, t a)
forall a (t :: * -> *) (t2 :: * -> *) b c.
(Eq a, Foldable t, Foldable t2) =>
(Vector a -> t a)
-> Vector (t2 b -> b)
-> FuncRep (t a) (Vector c) (t2 b)
-> Vector a
-> (t2 b, Vector b, t a)
resultB Vector a -> t a
f3 Vector (t2 b -> b)
vN FuncRep (t a) (Vector c) (t2 b)
frep) Vector (Vector a)
ns

-- | Is used internally in the 'uniquenessVariants2GNPB', 'uniquenessVariants2GNP' and related functions. A key point of the evaluation -- the universal set of the task represented as a
-- 'VB.Vector' of 'VB.Vector' of @a@.
universalSetG ::
  (Eq a, Foldable t, InsertLeft t a, Monoid (t a), Monoid (t (t a))) => t a
  -> t (t a)
  -> (t a -> VB.Vector a) -- ^ The function that is used internally to convert to the boxed 'VB.Vector' of @a@ so that the function can process further the permutations
  -> ((t (t a)) -> VB.Vector (VB.Vector a)) -- ^ The function that is used internally to convert to the boxed 'VB.Vector' of 'VB.Vector' of @a@ so that the function can process further
  -> VB.Vector (VB.Vector Int) -- ^ The list of permutations of 'Int' indices starting from 0 and up to n (n is probably less than 7).
  -> VB.Vector (VB.Vector a)
  -> VB.Vector (VB.Vector a)
universalSetG :: t a
-> t (t a)
-> (t a -> Vector a)
-> (t (t a) -> Vector (Vector a))
-> Vector (Vector Int)
-> Vector (Vector a)
-> Vector (Vector a)
universalSetG t a
ts t (t a)
uss t a -> Vector a
f1 t (t a) -> Vector (Vector a)
f2 Vector (Vector Int)
perms Vector (Vector a)
baseV = (Vector Int -> Vector a)
-> Vector (Vector Int) -> Vector (Vector a)
forall a b. (a -> b) -> Vector a -> Vector b
VB.map ((Vector a -> Vector a -> Vector a)
-> Vector a -> Vector (Vector a) -> Vector a
forall a b. (a -> b -> b) -> b -> Vector a -> b
VB.foldr' Vector a -> Vector a -> Vector a
forall a. Monoid a => a -> a -> a
mappend Vector a
forall a. Monoid a => a
mempty (Vector (Vector a) -> Vector a)
-> (Vector Int -> Vector (Vector a)) -> Vector Int -> Vector a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Vector a -> Vector (Vector a) -> Vector (Vector a)
forall a. a -> Vector a -> Vector a
VB.cons (t a -> Vector a
f1 t a
ts) (Vector (Vector a) -> Vector (Vector a))
-> (Vector Int -> Vector (Vector a))
-> Vector Int
-> Vector (Vector a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Vector (Vector a) -> Vector (Vector a) -> Vector (Vector a)
forall a. Monoid a => a -> a -> a
`mappend` (t (t a) -> Vector (Vector a)
f2 t (t a)
uss)) (Vector (Vector a) -> Vector (Vector a))
-> (Vector Int -> Vector (Vector a))
-> Vector Int
-> Vector (Vector a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Vector (Vector a) -> Vector Int -> Vector (Vector a)
forall a. Vector a -> Vector Int -> Vector a
VB.unsafeBackpermute Vector (Vector a)
baseV) Vector (Vector Int)
perms
{-# INLINE universalSetG #-}

-- | A variant of the 'uniquenessVariants2GNPB' with the usage of the 'V.Vector' @c@ (an unboxed one) instead of the boxed variant 'VB.Vector' @c@. If @c@ is an instance of the
-- 'V.Unboxed' class then possibly it can be better from the performance point of view to use this variant.
uniquenessVariants2GNP ::
  (Eq a, Foldable t, InsertLeft t a, Monoid (t a), Monoid (t (t a)), Ord b, Foldable t2) => t a -- ^ The prepending structure.
  -> t a -- ^ The postpending structure.
  -> a -- ^ The first most common element in the whitespace symbols structure.
  -> (t a -> VB.Vector a) -- ^ The function that is used internally to convert to the boxed 'VB.Vector' of @a@ so that the function can process further the permutations
  -> ((t (t a)) -> VB.Vector (VB.Vector a)) -- ^ The function that is used internally to convert to the boxed 'VB.Vector' of 'VB.Vector' of @a@ so that the function can process further
  -> (VB.Vector a -> t a) -- ^ The function that is used internally to convert from the boxed 'VB.Vector' of @a@ so that the function can process further
  -> VB.Vector (VB.Vector Int) -- ^ The list of permutations of 'Int' indices starting from 0 and up to n (n is probably less than 7).
  -> VB.Vector (t2 b -> b)
  -> FuncRep (t a) (V.Vector c) (t2 b) -- ^ It includes the defined earlier variant with data constructor 'D2', but additionally allows to use just single argument with data constructor 'U1'
  -> t (t a) -- ^ Must be obtained as 'subG' @whspss xs@
  -> VB.Vector (t2 b,VB.Vector b, t a)
uniquenessVariants2GNP :: t a
-> t a
-> a
-> (t a -> Vector a)
-> (t (t a) -> Vector (Vector a))
-> (Vector a -> t a)
-> Vector (Vector Int)
-> Vector (t2 b -> b)
-> FuncRep (t a) (Vector c) (t2 b)
-> t (t a)
-> Vector (t2 b, Vector b, t a)
uniquenessVariants2GNP !t a
ts !t a
us !a
hd t a -> Vector a
f1 t (t a) -> Vector (Vector a)
f2 Vector a -> t a
f3 Vector (Vector Int)
perms Vector (t2 b -> b)
vN FuncRep (t a) (Vector c) (t2 b)
frep !t (t a)
subs
  | t (t a) -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
F.null t (t a)
subs = Vector (t2 b, Vector b, t a)
forall a. Vector a
VB.empty
  | Bool
otherwise =
     let !uss :: t (t a)
uss = (a
hd a -> t a -> t a
forall (t :: * -> *) a. InsertLeft t a => a -> t a -> t a
%@ t a
us) t a -> t (t a) -> t (t a)
forall (t :: * -> *) a. InsertLeft t a => t a -> t (t a) -> t (t a)
%^ t (t a)
forall a. Monoid a => a
mempty
         !baseV :: Vector (Vector a)
baseV = (Vector a -> Vector a) -> Vector (Vector a) -> Vector (Vector a)
forall a b. (a -> b) -> Vector a -> Vector b
VB.map (a
hd a -> Vector a -> Vector a
forall a. a -> Vector a -> Vector a
`VB.cons`) (Vector (Vector a) -> Vector (Vector a))
-> (t (t a) -> Vector (Vector a)) -> t (t a) -> Vector (Vector a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. t (t a) -> Vector (Vector a)
f2 (t (t a) -> Vector (Vector a)) -> t (t a) -> Vector (Vector a)
forall a b. (a -> b) -> a -> b
$ t (t a)
subs
         !ns :: Vector (Vector a)
ns = t a
-> t (t a)
-> (t a -> Vector a)
-> (t (t a) -> Vector (Vector a))
-> Vector (Vector Int)
-> Vector (Vector a)
-> Vector (Vector a)
forall a (t :: * -> *).
(Eq a, Foldable t, InsertLeft t a, Monoid (t a),
 Monoid (t (t a))) =>
t a
-> t (t a)
-> (t a -> Vector a)
-> (t (t a) -> Vector (Vector a))
-> Vector (Vector Int)
-> Vector (Vector a)
-> Vector (Vector a)
universalSetG t a
ts t (t a)
uss t a -> Vector a
f1 t (t a) -> Vector (Vector a)
f2 Vector (Vector Int)
perms Vector (Vector a)
baseV in (Vector a -> (t2 b, Vector b, t a))
-> Vector (Vector a) -> Vector (t2 b, Vector b, t a)
forall a b. (a -> b) -> Vector a -> Vector b
VB.map ((Vector a -> t a)
-> Vector (t2 b -> b)
-> FuncRep (t a) (Vector c) (t2 b)
-> Vector a
-> (t2 b, Vector b, t a)
forall a (t :: * -> *) (t2 :: * -> *) b c.
(Eq a, Foldable t, Foldable t2) =>
(Vector a -> t a)
-> Vector (t2 b -> b)
-> FuncRep (t a) (Vector c) (t2 b)
-> Vector a
-> (t2 b, Vector b, t a)
result Vector a -> t a
f3 Vector (t2 b -> b)
vN FuncRep (t a) (Vector c) (t2 b)
frep) Vector (Vector a)
ns

result ::
  (Eq a, Foldable t, Foldable t2) =>
  (VB.Vector a -> t a) -- ^ The function that is used internally to convert from the boxed 'VB.Vector' of @a@ so that the function can process further
  -> VB.Vector (t2 b -> b)
  -> FuncRep (t a) (V.Vector c) (t2 b) -- ^ It includes the defined earlier variant with data constructor 'D2', but additionally allows to use just single argument with data constructor 'U1'
  -> VB.Vector a
  -> (t2 b,VB.Vector b, t a)
result :: (Vector a -> t a)
-> Vector (t2 b -> b)
-> FuncRep (t a) (Vector c) (t2 b)
-> Vector a
-> (t2 b, Vector b, t a)
result Vector a -> t a
f3 Vector (t2 b -> b)
vN FuncRep (t a) (Vector c) (t2 b)
frep Vector a
vs =
  (t2 b
rs, (((t2 b -> b) -> b) -> Vector (t2 b -> b) -> Vector b
forall a b. (a -> b) -> Vector a -> Vector b
VB.map (\t2 b -> b
f -> t2 b -> b
f t2 b
rs) Vector (t2 b -> b)
vN), t a
ws)
    where !ws :: t a
ws = Vector a -> t a
f3 Vector a
vs
          !rs :: t2 b
rs = FuncRep (t a) (Vector c) (t2 b) -> t a -> t2 b
forall a b c. FuncRep a b c -> a -> c
getAC FuncRep (t a) (Vector c) (t2 b)
frep t a
ws
{-# INLINE result #-}

resultB ::
  (Eq a, Foldable t, Foldable t2) =>
  (VB.Vector a -> t a) -- ^ The function that is used internally to convert from the boxed 'VB.Vector' of @a@ so that the function can process further
  -> VB.Vector (t2 b -> b)
  -> FuncRep (t a) (VB.Vector c) (t2 b) -- ^ It includes the defined earlier variant with data constructor 'D2', but additionally allows to use just single argument with data constructor 'U1'
  -> VB.Vector a
  -> (t2 b,VB.Vector b, t a)
resultB :: (Vector a -> t a)
-> Vector (t2 b -> b)
-> FuncRep (t a) (Vector c) (t2 b)
-> Vector a
-> (t2 b, Vector b, t a)
resultB Vector a -> t a
f3 Vector (t2 b -> b)
vN FuncRep (t a) (Vector c) (t2 b)
frep Vector a
vs =
  (t2 b
rs, (((t2 b -> b) -> b) -> Vector (t2 b -> b) -> Vector b
forall a b. (a -> b) -> Vector a -> Vector b
VB.map (\t2 b -> b
f -> t2 b -> b
f t2 b
rs) Vector (t2 b -> b)
vN), t a
ws)
    where !ws :: t a
ws = Vector a -> t a
f3 Vector a
vs
          !rs :: t2 b
rs = FuncRep (t a) (Vector c) (t2 b) -> t a -> t2 b
forall a b c. FuncRep a b c -> a -> c
getAC FuncRep (t a) (Vector c) (t2 b)
frep t a
ws
{-# INLINE resultB #-}

genPermutations :: Int -> VB.Vector (VB.Vector Int)
genPermutations :: Int -> Vector (Vector Int)
genPermutations Int
n = ([Int] -> Vector Int) -> Vector [Int] -> Vector (Vector Int)
forall a b. (a -> b) -> Vector a -> Vector b
VB.map [Int] -> Vector Int
forall a. [a] -> Vector a
VB.fromList (Vector [Int] -> Vector (Vector Int))
-> ([Int] -> Vector [Int]) -> [Int] -> Vector (Vector Int)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [[Int]] -> Vector [Int]
forall a. [a] -> Vector a
VB.fromList ([[Int]] -> Vector [Int])
-> ([Int] -> [[Int]]) -> [Int] -> Vector [Int]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Int] -> [[Int]]
forall a. [a] -> [[a]]
L.permutations ([Int] -> [[Int]]) -> ([Int] -> [Int]) -> [Int] -> [[Int]]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> [Int] -> [Int]
forall a. Int -> [a] -> [a]
take Int
n ([Int] -> Vector (Vector Int)) -> [Int] -> Vector (Vector Int)
forall a b. (a -> b) -> a -> b
$ [Int
0..]
{-# INLINE genPermutations #-}

genPermutationsV :: VB.Vector (VB.Vector (VB.Vector Int))
genPermutationsV :: Vector (Vector (Vector Int))
genPermutationsV = (Int -> Vector (Vector Int))
-> Vector Int -> Vector (Vector (Vector Int))
forall a b. (a -> b) -> Vector a -> Vector b
VB.map (\Int
n -> ([Int] -> Vector Int) -> Vector [Int] -> Vector (Vector Int)
forall a b. (a -> b) -> Vector a -> Vector b
VB.map [Int] -> Vector Int
forall a. [a] -> Vector a
VB.fromList (Vector [Int] -> Vector (Vector Int))
-> ([Int] -> Vector [Int]) -> [Int] -> Vector (Vector Int)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [[Int]] -> Vector [Int]
forall a. [a] -> Vector a
VB.fromList ([[Int]] -> Vector [Int])
-> ([Int] -> [[Int]]) -> [Int] -> Vector [Int]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Int] -> [[Int]]
forall a. [a] -> [[a]]
L.permutations ([Int] -> [[Int]]) -> ([Int] -> [Int]) -> [Int] -> [[Int]]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> [Int] -> [Int]
forall a. Int -> [a] -> [a]
take Int
n ([Int] -> Vector (Vector Int)) -> [Int] -> Vector (Vector Int)
forall a b. (a -> b) -> a -> b
$ [Int
0..]) (Vector Int -> Vector (Vector (Vector Int)))
-> (Int -> Vector Int) -> Int -> Vector (Vector (Vector Int))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Int -> Vector Int
forall a. Enum a => a -> a -> Vector a
VB.enumFromTo Int
2 (Int -> Vector (Vector (Vector Int)))
-> Int -> Vector (Vector (Vector Int))
forall a b. (a -> b) -> a -> b
$ Int
7
{-# INLINE genPermutationsV #-}