--module SortNet where import Data.List import Control.Parallel import System.Environment import System.Random main = do args <- getArgs if ((length args) < 2) then putStrLn usage else let inp = rand(2^(read (args !! 1))) res :: [Int] res | (args !! 0 == "1") = sortNet inp | (args !! 0 == "2") = sortNetPar inp | otherwise = sortNetParD (if (length args) < 3 then 3 else read (read (args !! 2))) inp output' = (if (length args) < 3 then (read (args !! 3)) == 1 else False) output | output' = print res | otherwise = length res `pseq` putStrLn "done" in output usage = "2-4 Parameter werden benötigt: \n" ++ " 1. Version (sortNet,sortNetPar,sortNetParD)\n"++ " 2. Liste der Länge 2^N (N anzugeben)\n"++ " 3. Parallele Tiefe für sortNetParD (default 3)\n"++ " 4. Ausgabe der Ergebnisliste, 1 meint Ausgabe (default 0)" comparator :: Ord a => a -> a -> [a] comparator _ _ = error "" nToNMerge :: Ord a => [a] -> [a] -> [a] nToNMerge _ _ = error "input length: no power of 2" sortNet :: Ord a => [a] -> [a] sortNet _ = error "" sortNetPar :: Ord a => [a] -> [a] sortNetPar _ = error "" sortNetParD :: Ord a => Int -> [a] -> [a] sortNetParD _ _ = error "" -- | Round robin distribution - inverse to shuffle -- unshuffle :: Int -- ^number of sublists -> [a] -- ^input list -> [[a]] -- ^distributed output unshuffle n xs = [takeEach n (drop i xs) | i <- [0..n-1]] takeEach :: Int -> [a] -> [a] takeEach n [] = [] takeEach n (x:xs) = x : takeEach n (drop (n-1) xs) -- | Simple shuffling - inverse to round robin distribution shuffle :: [[a]] -- ^ sublists -> [a] -- ^ shuffled sublists shuffle = concat . transpose rand :: Int -> [Int] rand i = take i $ randomRs (1,10000) (mkStdGen 2)