{-# LANGUAGE ForeignFunctionInterface #-}
module Sym.Perm.Group
(
compose
, act
) where
import Sym.Perm
import Foreign
import Foreign.C.Types
import System.IO.Unsafe
marshal :: (Ptr CLong -> Ptr CLong -> CLong -> Ptr CLong -> CLong -> IO ())
-> Perm -> Perm -> Perm
marshal :: (Ptr CLong -> Ptr CLong -> CLong -> Ptr CLong -> CLong -> IO ())
-> Perm -> Perm -> Perm
marshal Ptr CLong -> Ptr CLong -> CLong -> Ptr CLong -> CLong -> IO ()
op Perm
u Perm
v =
IO Perm -> Perm
forall a. IO a -> a
unsafePerformIO (IO Perm -> Perm) -> IO Perm -> Perm
forall a b. (a -> b) -> a -> b
$
Perm -> (Ptr CLong -> IO Perm) -> IO Perm
forall a. Perm -> (Ptr CLong -> IO a) -> IO a
unsafeWith Perm
u ((Ptr CLong -> IO Perm) -> IO Perm)
-> (Ptr CLong -> IO Perm) -> IO Perm
forall a b. (a -> b) -> a -> b
$ \Ptr CLong
u' ->
Perm -> (Ptr CLong -> IO Perm) -> IO Perm
forall a. Perm -> (Ptr CLong -> IO a) -> IO a
unsafeWith Perm
v ((Ptr CLong -> IO Perm) -> IO Perm)
-> (Ptr CLong -> IO Perm) -> IO Perm
forall a b. (a -> b) -> a -> b
$ \Ptr CLong
v' -> do
let k :: Int
k = Perm -> Int
forall a. Size a => a -> Int
size Perm
u
let n :: Int
n = Perm -> Int
forall a. Size a => a -> Int
size Perm
v
let m :: Int
m = Int -> Int -> Int
forall a. Ord a => a -> a -> a
max Int
k Int
n
Int -> (Ptr CLong -> IO ()) -> IO Perm
unsafeNew Int
m ((Ptr CLong -> IO ()) -> IO Perm)
-> (Ptr CLong -> IO ()) -> IO Perm
forall a b. (a -> b) -> a -> b
$ \Ptr CLong
p -> Ptr CLong -> Ptr CLong -> CLong -> Ptr CLong -> CLong -> IO ()
op Ptr CLong
p Ptr CLong
u' (Int -> CLong
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
k) Ptr CLong
v' (Int -> CLong
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
n)
{-# INLINE marshal #-}
foreign import ccall unsafe "group.h compose" c_compose
:: Ptr CLong -> Ptr CLong -> CLong -> Ptr CLong -> CLong -> IO ()
compose :: Perm -> Perm -> Perm
compose :: Perm -> Perm -> Perm
compose = (Ptr CLong -> Ptr CLong -> CLong -> Ptr CLong -> CLong -> IO ())
-> Perm -> Perm -> Perm
marshal Ptr CLong -> Ptr CLong -> CLong -> Ptr CLong -> CLong -> IO ()
c_compose
{-# INLINE compose #-}
foreign import ccall unsafe "group.h act" c_act
:: Ptr CLong -> Ptr CLong -> CLong -> Ptr CLong -> CLong -> IO ()
act :: Perm -> Perm -> Perm
act :: Perm -> Perm -> Perm
act = (Ptr CLong -> Ptr CLong -> CLong -> Ptr CLong -> CLong -> IO ())
-> Perm -> Perm -> Perm
marshal Ptr CLong -> Ptr CLong -> CLong -> Ptr CLong -> CLong -> IO ()
c_act
{-# INLINE act #-}