module Data.BitArray.Immutable where

--------------------------------------------------------------------------------

import Data.Word
import Data.Bits

import Data.Array.Unboxed

--------------------------------------------------------------------------------

-- | A packed bit array. 
-- Internally, it is represented as an unboxed array of 'Word64'-s.
data BitArray = A 
  { BitArray -> Int
_first :: {-# UNPACK #-} !Int 
  , BitArray -> Int
_last  :: {-# UNPACK #-} !Int 
  , BitArray -> UArray Int Word64
_words :: {-# UNPACK #-} !(UArray Int Word64)
  }
  
--------------------------------------------------------------------------------

ind :: Int -> (Int,Int)
ind :: Int -> (Int, Int)
ind i :: Int
i = (Int
k,Int
l) where
  k :: Int
k = Int
i Int -> Int -> Int
forall a. Bits a => a -> Int -> a
`shiftR` 6
  l :: Int
l = Int
i Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
k Int -> Int -> Int
forall a. Bits a => a -> Int -> a
`shiftL` 6

--------------------------------------------------------------------------------

{-# SPECIALIZE intToBool :: Int -> Bool #-}
intToBool :: Integral a => a -> Bool
intToBool :: a -> Bool
intToBool n :: a
n = case a
n of
  0 -> Bool
False
  _ -> Bool
True
  
{-# SPECIALIZE boolToInt :: Bool -> Int #-}
boolToInt :: Integral a => Bool -> a
boolToInt :: Bool -> a
boolToInt b :: Bool
b = case Bool
b of
  False -> 0
  True  -> 1

--------------------------------------------------------------------------------