module Data.PrimitiveArray.Index.Complement where
import Control.Applicative
import Control.DeepSeq (NFData(..))
import Data.Aeson
import Data.Binary
import Data.Serialize
import Data.Vector.Unboxed.Deriving
import Data.Vector.Unboxed (Unbox(..))
import GHC.Generics
import Test.QuickCheck
import Data.PrimitiveArray.Index.Class
newtype Complement z = C { unC :: z }
deriving (Eq,Ord,Read,Show,Generic)
derivingUnbox "Complement"
[t| forall z . Unbox z => Complement z -> z |]
[| unC |]
[| C |]
instance Binary z => Binary (Complement z)
instance Serialize z => Serialize (Complement z)
instance ToJSON z => ToJSON (Complement z)
instance FromJSON z => FromJSON (Complement z)
instance NFData z => NFData (Complement z) where
rnf (C z) = rnf z
instance Index i => Index (Complement i) where
linearIndex (C l) (C h) (C i) = linearIndex l h i
smallestLinearIndex (C i) = smallestLinearIndex i
largestLinearIndex (C i) = largestLinearIndex i
size (C l) (C h) = size l h
inBounds (C l) (C h) (C z) = inBounds l h z
instance IndexStream i => IndexStream (Complement i) where
streamUp (C l) (C h) = fmap C $ streamUp l h
streamDown (C l) (C h) = fmap C $ streamDown l h
instance Arbitrary z => Arbitrary (Complement z) where
arbitrary = C <$> arbitrary
shrink (C z) = C <$> shrink z