{-# LANGUAGE ForeignFunctionInterface #-}
module Sym.Perm.Bijection
(
simionSchmidt
, simionSchmidt'
) where
import Sym.Perm
import Foreign
import Foreign.C.Types
import System.IO.Unsafe
foreign import ccall unsafe "bij.h simion_schmidt" c_simion_schmidt
:: Ptr CLong -> Ptr CLong -> CLong -> IO ()
foreign import ccall unsafe "bij.h simion_schmidt_inverse" c_simion_schmidt'
:: Ptr CLong -> Ptr CLong -> CLong -> IO ()
marshal :: (Ptr CLong -> Ptr CLong -> CLong -> IO ()) -> Perm -> Perm
marshal :: (Ptr CLong -> Ptr CLong -> CLong -> IO ()) -> Perm -> Perm
marshal Ptr CLong -> Ptr CLong -> CLong -> IO ()
bij Perm
w =
IO Perm -> Perm
forall a. IO a -> a
unsafePerformIO (IO Perm -> Perm)
-> ((Ptr CLong -> IO Perm) -> IO Perm)
-> (Ptr CLong -> IO Perm)
-> Perm
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Perm -> (Ptr CLong -> IO Perm) -> IO Perm
forall a. Perm -> (Ptr CLong -> IO a) -> IO a
unsafeWith Perm
w ((Ptr CLong -> IO Perm) -> Perm) -> (Ptr CLong -> IO Perm) -> Perm
forall a b. (a -> b) -> a -> b
$ \Ptr CLong
p -> do
let n :: Int
n = Perm -> Int
forall a. Size a => a -> Int
size Perm
w
Int -> (Ptr CLong -> IO ()) -> IO Perm
unsafeNew Int
n ((Ptr CLong -> IO ()) -> IO Perm)
-> (Ptr CLong -> IO ()) -> IO Perm
forall a b. (a -> b) -> a -> b
$ \Ptr CLong
q -> Ptr CLong -> Ptr CLong -> CLong -> IO ()
bij Ptr CLong
q Ptr CLong
p (Int -> CLong
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
n)
{-# INLINE marshal #-}
simionSchmidt :: Perm -> Perm
simionSchmidt :: Perm -> Perm
simionSchmidt = (Ptr CLong -> Ptr CLong -> CLong -> IO ()) -> Perm -> Perm
marshal Ptr CLong -> Ptr CLong -> CLong -> IO ()
c_simion_schmidt
simionSchmidt' :: Perm -> Perm
simionSchmidt' :: Perm -> Perm
simionSchmidt' = (Ptr CLong -> Ptr CLong -> CLong -> IO ()) -> Perm -> Perm
marshal Ptr CLong -> Ptr CLong -> CLong -> IO ()
c_simion_schmidt'