-- GENERATED by C->Haskell Compiler, version 0.28.3 Switcheroo, 25 November 2017 (Haskell)
-- Edit the ORIGNAL .chs file instead!


{-# LINE 1 "src/IGraph/Algorithms/Clique.chs" #-}
{-# LANGUAGE ForeignFunctionInterface #-}
module IGraph.Algorithms.Clique
    ( cliques
    , largestCliques
    , maximalCliques
    , cliqueNumber
    ) where
import qualified Foreign.C.Types as C2HSImp
import qualified Foreign.Ptr as C2HSImp



import Control.Applicative ((<$>))
import System.IO.Unsafe (unsafePerformIO)

import qualified Foreign.Ptr as C2HSImp
import Foreign

import IGraph
import IGraph.Internal.C2HS
import IGraph.Internal
{-# LINE 17 "src/IGraph/Algorithms/Clique.chs" #-}




cliques :: Graph d v e
        -> (Int, Int)  -- ^ Minimum and maximum size of the cliques to be returned.
                       -- No bound will be used if negative or zero
        -> [[Int]]     -- ^ cliques represented by node ids
cliques gr (lo, hi) = unsafePerformIO $ allocaVectorPtr $ \vptr -> do
    igraphCliques (_graph gr) vptr lo hi
    (map.map) truncate <$> toLists vptr
igraphCliques :: (IGraph) -> (Ptr VectorPtr) -> (Int) -> (Int) -> IO ()
igraphCliques a1 a2 a3 a4 =
  (withIGraph) a1 $ \a1' ->
  let {a2' = castPtr a2} in
  let {a3' = fromIntegral a3} in
  let {a4' = fromIntegral a4} in
  igraphCliques'_ a1' a2' a3' a4' >>= \res ->
  return ()

{-# LINE 28 "src/IGraph/Algorithms/Clique.chs" #-}


largestCliques :: Graph d v e -> [[Int]]
largestCliques gr = unsafePerformIO $ allocaVectorPtr $ \vptr -> do
    igraphLargestCliques (_graph gr) vptr
    (map.map) truncate <$> toLists vptr
igraphLargestCliques :: (IGraph) -> (Ptr VectorPtr) -> IO ()
igraphLargestCliques a1 a2 =
  (withIGraph) a1 $ \a1' ->
  let {a2' = castPtr a2} in
  igraphLargestCliques'_ a1' a2' >>= \res ->
  return ()

{-# LINE 34 "src/IGraph/Algorithms/Clique.chs" #-}


maximalCliques :: Graph d v e
               -> (Int, Int)  -- ^ Minimum and maximum size of the cliques to be returned.
                              -- No bound will be used if negative or zero
               -> [[Int]]     -- ^ cliques represented by node ids
maximalCliques gr (lo, hi) = unsafePerformIO $ allocaVectorPtr $ \vpptr -> do
    igraphMaximalCliques (_graph gr) vpptr lo hi
    (map.map) truncate <$> toLists vpptr
igraphMaximalCliques :: (IGraph) -> (Ptr VectorPtr) -> (Int) -> (Int) -> IO ()
igraphMaximalCliques a1 a2 a3 a4 =
  (withIGraph) a1 $ \a1' ->
  let {a2' = castPtr a2} in
  let {a3' = fromIntegral a3} in
  let {a4' = fromIntegral a4} in
  igraphMaximalCliques'_ a1' a2' a3' a4' >>= \res ->
  return ()

{-# LINE 43 "src/IGraph/Algorithms/Clique.chs" #-}


cliqueNumber :: Graph d v e -> Int
cliqueNumber gr = unsafePerformIO $ igraphCliqueNumber $ _graph gr
igraphCliqueNumber :: (IGraph) -> IO ((Int))
igraphCliqueNumber a1 =
  (withIGraph) a1 $ \a1' ->
  alloca $ \a2' ->
  igraphCliqueNumber'_ a1' a2' >>= \res ->
  peekIntConv  a2'>>= \a2'' ->
  return (a2'')

{-# LINE 50 "src/IGraph/Algorithms/Clique.chs" #-}


foreign import ccall safe "IGraph/Algorithms/Clique.chs.h igraph_cliques"
  igraphCliques'_ :: ((C2HSImp.Ptr (IGraph)) -> ((C2HSImp.Ptr ()) -> (C2HSImp.CInt -> (C2HSImp.CInt -> (IO C2HSImp.CInt)))))

foreign import ccall safe "IGraph/Algorithms/Clique.chs.h igraph_largest_cliques"
  igraphLargestCliques'_ :: ((C2HSImp.Ptr (IGraph)) -> ((C2HSImp.Ptr ()) -> (IO C2HSImp.CInt)))

foreign import ccall safe "IGraph/Algorithms/Clique.chs.h igraph_maximal_cliques"
  igraphMaximalCliques'_ :: ((C2HSImp.Ptr (IGraph)) -> ((C2HSImp.Ptr ()) -> (C2HSImp.CInt -> (C2HSImp.CInt -> (IO C2HSImp.CInt)))))

foreign import ccall safe "IGraph/Algorithms/Clique.chs.h igraph_clique_number"
  igraphCliqueNumber'_ :: ((C2HSImp.Ptr (IGraph)) -> ((C2HSImp.Ptr C2HSImp.CInt) -> (IO C2HSImp.CInt)))