module Sym.Perm.Sort
(
stackSort
, bubbleSort
) where
import Sym.Perm
import Foreign
import Foreign.C.Types
import System.IO.Unsafe
foreign import ccall unsafe "sortop.h stacksort" c_stacksort
:: Ptr CLong -> Ptr CLong -> CLong -> IO ()
foreign import ccall unsafe "sortop.h bubblesort" c_bubblesort
:: Ptr CLong -> Ptr CLong -> CLong -> IO ()
marshal :: (Ptr CLong -> Ptr CLong -> CLong -> IO ()) -> Perm -> Perm
marshal op w =
unsafePerformIO . unsafeWith w $ \p -> do
let n = size w
unsafeNew n $ \q -> op q p (fromIntegral n)
stackSort :: Perm -> Perm
stackSort = marshal c_stacksort
bubbleSort :: Perm -> Perm
bubbleSort = marshal c_bubblesort