{-# LANGUAGE DeriveDataTypeable         #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE DerivingStrategies #-}

-- |
-- Module      :  $Header$
-- Description :  Data.IntSet with Enum elements.
-- Copyright   :  (c) 2011-2019 Michal Terepeta
--                (c) 2019-2022 Mikolaj Konarski and others (see git history)
-- License     :  BSD3
-- Maintainer  :  mikolaj.konarski@funktory.com
-- Stability   :  alpha
-- Portability :  uses DeriveDataTypeable and GeneralizedNewtypeDeriving

-- This is a simple wrapper for 'Data.IntSet' that allows storing any elements
-- of Enum type class. Useful if one wants to have the performance of
-- 'Data.IntSet' and at the same time use something else than 'Int's (e.g. an
-- 'Int' wrapped with newtype). For documentation see the one for 'Data.IntSet'.

module Data.EnumSet
  ( EnumSet

  -- * Wrapping/unwrapping
  , intSetToEnumSet
  , enumSetToIntSet

  -- * Operators
  , (\\)

  -- * Query
  , null
  , size
  , member
  , notMember
  , lookupLT
  , lookupGT
  , lookupLE
  , lookupGE
  , isSubsetOf
  , isProperSubsetOf

  -- * Construction
  , empty
  , singleton
  , insert
  , delete

  -- * Combine
  , union
  , unions
  , difference
  , intersection

  -- * Filter
  , filter
  , partition
  , split
  , splitMember

  -- * Map
  , map

  -- * Folds
  , foldr
  , foldl
  -- ** Strict folds
  , foldr'
  , foldl'
  -- ** Legacy folds
  , fold


  -- * Min\/Max
  , findMin
  , findMax
  , deleteMin
  , deleteMax
  , deleteFindMin
  , deleteFindMax
  , maxView
  , minView

  -- * Conversion

  -- ** List
  , elems
  , toList
  , fromList

  -- ** Ordered list
  , toAscList
  , toDescList
  , fromAscList
  , fromDistinctAscList

  ) where

import Prelude hiding ( Foldable(..), filter, lookup, map )
import qualified Prelude as P

import Data.IntSet ( IntSet )
import qualified Data.IntSet as I

import Control.Arrow ( (***) )
import Control.DeepSeq ( NFData )
import Data.Monoid ( Monoid )
import Data.Semigroup ( Semigroup )
import Data.Typeable ( Typeable )
import Data.Aeson
    ( FromJSON(parseJSON), ToJSON(toEncoding, toJSON) )
import Text.Read
import GHC.Generics (Generic)

-- | Wrapper for 'IntSet' with 'Enum' elements.
newtype EnumSet k = EnumSet { forall k. EnumSet k -> IntSet
unWrap :: IntSet }
  deriving stock
    ( EnumSet k -> EnumSet k -> Bool
forall k. EnumSet k -> EnumSet k -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: EnumSet k -> EnumSet k -> Bool
$c/= :: forall k. EnumSet k -> EnumSet k -> Bool
== :: EnumSet k -> EnumSet k -> Bool
$c== :: forall k. EnumSet k -> EnumSet k -> Bool
Eq
    , EnumSet k -> EnumSet k -> Bool
EnumSet k -> EnumSet k -> Ordering
forall k. Eq (EnumSet k)
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall k. EnumSet k -> EnumSet k -> Bool
forall k. EnumSet k -> EnumSet k -> Ordering
forall k. EnumSet k -> EnumSet k -> EnumSet k
min :: EnumSet k -> EnumSet k -> EnumSet k
$cmin :: forall k. EnumSet k -> EnumSet k -> EnumSet k
max :: EnumSet k -> EnumSet k -> EnumSet k
$cmax :: forall k. EnumSet k -> EnumSet k -> EnumSet k
>= :: EnumSet k -> EnumSet k -> Bool
$c>= :: forall k. EnumSet k -> EnumSet k -> Bool
> :: EnumSet k -> EnumSet k -> Bool
$c> :: forall k. EnumSet k -> EnumSet k -> Bool
<= :: EnumSet k -> EnumSet k -> Bool
$c<= :: forall k. EnumSet k -> EnumSet k -> Bool
< :: EnumSet k -> EnumSet k -> Bool
$c< :: forall k. EnumSet k -> EnumSet k -> Bool
compare :: EnumSet k -> EnumSet k -> Ordering
$ccompare :: forall k. EnumSet k -> EnumSet k -> Ordering
Ord
    , Typeable
    )
  deriving newtype
    ( NonEmpty (EnumSet k) -> EnumSet k
EnumSet k -> EnumSet k -> EnumSet k
forall b. Integral b => b -> EnumSet k -> EnumSet k
forall k. NonEmpty (EnumSet k) -> EnumSet k
forall k. EnumSet k -> EnumSet k -> EnumSet k
forall a.
(a -> a -> a)
-> (NonEmpty a -> a)
-> (forall b. Integral b => b -> a -> a)
-> Semigroup a
forall k b. Integral b => b -> EnumSet k -> EnumSet k
stimes :: forall b. Integral b => b -> EnumSet k -> EnumSet k
$cstimes :: forall k b. Integral b => b -> EnumSet k -> EnumSet k
sconcat :: NonEmpty (EnumSet k) -> EnumSet k
$csconcat :: forall k. NonEmpty (EnumSet k) -> EnumSet k
<> :: EnumSet k -> EnumSet k -> EnumSet k
$c<> :: forall k. EnumSet k -> EnumSet k -> EnumSet k
Semigroup
    , EnumSet k
[EnumSet k] -> EnumSet k
EnumSet k -> EnumSet k -> EnumSet k
forall k. Semigroup (EnumSet k)
forall k. EnumSet k
forall a.
Semigroup a -> a -> (a -> a -> a) -> ([a] -> a) -> Monoid a
forall k. [EnumSet k] -> EnumSet k
forall k. EnumSet k -> EnumSet k -> EnumSet k
mconcat :: [EnumSet k] -> EnumSet k
$cmconcat :: forall k. [EnumSet k] -> EnumSet k
mappend :: EnumSet k -> EnumSet k -> EnumSet k
$cmappend :: forall k. EnumSet k -> EnumSet k -> EnumSet k
mempty :: EnumSet k
$cmempty :: forall k. EnumSet k
Monoid
    , EnumSet k -> ()
forall k. EnumSet k -> ()
forall a. (a -> ()) -> NFData a
rnf :: EnumSet k -> ()
$crnf :: forall k. EnumSet k -> ()
NFData
    )

instance (Enum k, Show k) => Show (EnumSet k) where
  showsPrec :: Int -> EnumSet k -> ShowS
showsPrec Int
p EnumSet k
ks = Bool -> ShowS -> ShowS
showParen (Int
p forall a. Ord a => a -> a -> Bool
> Int
10) forall a b. (a -> b) -> a -> b
$
    String -> ShowS
showString String
"fromList " forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Show a => a -> ShowS
shows (forall k. Enum k => EnumSet k -> [k]
toList EnumSet k
ks)

instance (Enum k, Read k) => Read (EnumSet k) where
  readPrec :: ReadPrec (EnumSet k)
readPrec = forall a. ReadPrec a -> ReadPrec a
parens forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Int -> ReadPrec a -> ReadPrec a
prec Int
10 forall a b. (a -> b) -> a -> b
$ do
    Ident String
"fromList" <- ReadPrec Lexeme
lexP
    forall k. Enum k => [k] -> EnumSet k
fromList forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Read a => ReadPrec a
readPrec

instance ToJSON (EnumSet a) where
    toJSON :: EnumSet a -> Value
toJSON = forall a. ToJSON a => a -> Value
toJSON forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall k. EnumSet k -> IntSet
unWrap
    toEncoding :: EnumSet a -> Encoding
toEncoding = forall a. ToJSON a => a -> Encoding
toEncoding forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall k. EnumSet k -> IntSet
unWrap

instance (FromJSON a) => FromJSON (EnumSet a) where
    parseJSON :: Value -> Parser (EnumSet a)
parseJSON = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (forall k. IntSet -> EnumSet k
EnumSet forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Int] -> IntSet
I.fromList) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. FromJSON a => Value -> Parser a
parseJSON

--
-- Conversion to/from 'IntSet'.
--

-- | Wrap 'IntSet'.
intSetToEnumSet :: IntSet -> EnumSet k
intSetToEnumSet :: forall k. IntSet -> EnumSet k
intSetToEnumSet = forall k. IntSet -> EnumSet k
EnumSet
{-# INLINE intSetToEnumSet #-}

-- | Unwrap 'IntSet'.
enumSetToIntSet :: EnumSet k -> IntSet
enumSetToIntSet :: forall k. EnumSet k -> IntSet
enumSetToIntSet = forall k. EnumSet k -> IntSet
unWrap
{-# INLINE enumSetToIntSet #-}

--
-- Here begins the main part.
--

(\\) :: EnumSet k -> EnumSet k -> EnumSet k
(EnumSet IntSet
is1) \\ :: forall k. EnumSet k -> EnumSet k -> EnumSet k
\\ (EnumSet IntSet
is2) = forall k. IntSet -> EnumSet k
EnumSet forall a b. (a -> b) -> a -> b
$ IntSet
is1 IntSet -> IntSet -> IntSet
I.\\ IntSet
is2
{-# INLINE (\\) #-}

null :: EnumSet k -> Bool
null :: forall a. EnumSet a -> Bool
null = IntSet -> Bool
I.null forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall k. EnumSet k -> IntSet
unWrap
{-# INLINE null #-}

size :: EnumSet k -> Int
size :: forall k. EnumSet k -> Int
size = IntSet -> Int
I.size forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall k. EnumSet k -> IntSet
unWrap
{-# INLINE size #-}

member :: (Enum k) => k -> EnumSet k -> Bool
member :: forall k. Enum k => k -> EnumSet k -> Bool
member k
k = Int -> IntSet -> Bool
I.member (forall a. Enum a => a -> Int
fromEnum k
k) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall k. EnumSet k -> IntSet
unWrap
{-# INLINE member #-}

notMember :: (Enum k) => k -> EnumSet k -> Bool
notMember :: forall k. Enum k => k -> EnumSet k -> Bool
notMember k
k = Int -> IntSet -> Bool
I.notMember (forall a. Enum a => a -> Int
fromEnum k
k) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall k. EnumSet k -> IntSet
unWrap
{-# INLINE notMember #-}

lookupLT :: (Enum k) => k -> EnumSet k -> Maybe k
lookupLT :: forall k. Enum k => k -> EnumSet k -> Maybe k
lookupLT k
k = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a. Enum a => Int -> a
toEnum forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> IntSet -> Maybe Int
I.lookupLT (forall a. Enum a => a -> Int
fromEnum k
k) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall k. EnumSet k -> IntSet
unWrap
{-# INLINE lookupLT #-}

lookupGT :: (Enum k) => k -> EnumSet k -> Maybe k
lookupGT :: forall k. Enum k => k -> EnumSet k -> Maybe k
lookupGT k
k = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a. Enum a => Int -> a
toEnum forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> IntSet -> Maybe Int
I.lookupGT (forall a. Enum a => a -> Int
fromEnum k
k) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall k. EnumSet k -> IntSet
unWrap
{-# INLINE lookupGT #-}

lookupLE :: (Enum k) => k -> EnumSet k -> Maybe k
lookupLE :: forall k. Enum k => k -> EnumSet k -> Maybe k
lookupLE k
k = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a. Enum a => Int -> a
toEnum forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> IntSet -> Maybe Int
I.lookupLE (forall a. Enum a => a -> Int
fromEnum k
k) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall k. EnumSet k -> IntSet
unWrap
{-# INLINE lookupLE #-}

lookupGE :: (Enum k) => k -> EnumSet k -> Maybe k
lookupGE :: forall k. Enum k => k -> EnumSet k -> Maybe k
lookupGE k
k = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a. Enum a => Int -> a
toEnum forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> IntSet -> Maybe Int
I.lookupGE (forall a. Enum a => a -> Int
fromEnum k
k) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall k. EnumSet k -> IntSet
unWrap
{-# INLINE lookupGE #-}

empty :: EnumSet k
empty :: forall k. EnumSet k
empty = forall k. IntSet -> EnumSet k
EnumSet IntSet
I.empty
{-# INLINE empty #-}

singleton :: (Enum k) => k -> EnumSet k
singleton :: forall k. Enum k => k -> EnumSet k
singleton = forall k. IntSet -> EnumSet k
EnumSet forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> IntSet
I.singleton forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Enum a => a -> Int
fromEnum
{-# INLINE singleton #-}

insert :: (Enum k) => k -> EnumSet k -> EnumSet k
insert :: forall k. Enum k => k -> EnumSet k -> EnumSet k
insert k
k = forall k. IntSet -> EnumSet k
EnumSet forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> IntSet -> IntSet
I.insert (forall a. Enum a => a -> Int
fromEnum k
k) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall k. EnumSet k -> IntSet
unWrap
{-# INLINE insert #-}

delete :: (Enum k) => k -> EnumSet k -> EnumSet k
delete :: forall k. Enum k => k -> EnumSet k -> EnumSet k
delete k
k = forall k. IntSet -> EnumSet k
EnumSet forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> IntSet -> IntSet
I.delete (forall a. Enum a => a -> Int
fromEnum k
k) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall k. EnumSet k -> IntSet
unWrap
{-# INLINE delete #-}

unions :: [EnumSet k] -> EnumSet k
unions :: forall k. [EnumSet k] -> EnumSet k
unions = forall k. IntSet -> EnumSet k
EnumSet forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *). Foldable f => f IntSet -> IntSet
I.unions forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a -> b) -> [a] -> [b]
P.map forall k. EnumSet k -> IntSet
unWrap
{-# INLINE unions #-}

union :: EnumSet k -> EnumSet k -> EnumSet k
union :: forall k. EnumSet k -> EnumSet k -> EnumSet k
union (EnumSet IntSet
is1) (EnumSet IntSet
is2) = forall k. IntSet -> EnumSet k
EnumSet forall a b. (a -> b) -> a -> b
$ IntSet -> IntSet -> IntSet
I.union IntSet
is1 IntSet
is2
{-# INLINE union #-}

difference :: EnumSet k -> EnumSet k -> EnumSet k
difference :: forall k. EnumSet k -> EnumSet k -> EnumSet k
difference (EnumSet IntSet
is1) (EnumSet IntSet
is2) = forall k. IntSet -> EnumSet k
EnumSet forall a b. (a -> b) -> a -> b
$ IntSet -> IntSet -> IntSet
I.difference IntSet
is1 IntSet
is2
{-# INLINE difference #-}

intersection :: EnumSet k -> EnumSet k -> EnumSet k
intersection :: forall k. EnumSet k -> EnumSet k -> EnumSet k
intersection (EnumSet IntSet
is1) (EnumSet IntSet
is2) = forall k. IntSet -> EnumSet k
EnumSet forall a b. (a -> b) -> a -> b
$ IntSet -> IntSet -> IntSet
I.intersection IntSet
is1 IntSet
is2
{-# INLINE intersection #-}

isProperSubsetOf :: EnumSet k -> EnumSet k -> Bool
isProperSubsetOf :: forall k. EnumSet k -> EnumSet k -> Bool
isProperSubsetOf (EnumSet IntSet
is1) (EnumSet IntSet
is2) = IntSet -> IntSet -> Bool
I.isProperSubsetOf IntSet
is1 IntSet
is2
{-# INLINE isProperSubsetOf #-}

isSubsetOf :: EnumSet k -> EnumSet k -> Bool
isSubsetOf :: forall k. EnumSet k -> EnumSet k -> Bool
isSubsetOf (EnumSet IntSet
is1) (EnumSet IntSet
is2) = IntSet -> IntSet -> Bool
I.isSubsetOf IntSet
is1 IntSet
is2
{-# INLINE isSubsetOf #-}

filter :: (Enum k) => (k -> Bool) -> EnumSet k -> EnumSet k
filter :: forall k. Enum k => (k -> Bool) -> EnumSet k -> EnumSet k
filter k -> Bool
f = forall k. IntSet -> EnumSet k
EnumSet forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Int -> Bool) -> IntSet -> IntSet
I.filter (k -> Bool
f forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Enum a => Int -> a
toEnum) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall k. EnumSet k -> IntSet
unWrap
{-# INLINE filter #-}

partition :: (Enum k) => (k -> Bool) -> EnumSet k -> (EnumSet k, EnumSet k)
partition :: forall k.
Enum k =>
(k -> Bool) -> EnumSet k -> (EnumSet k, EnumSet k)
partition k -> Bool
f = (forall k. IntSet -> EnumSet k
EnumSet forall (a :: * -> * -> *) b c b' c'.
Arrow a =>
a b c -> a b' c' -> a (b, b') (c, c')
*** forall k. IntSet -> EnumSet k
EnumSet) forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Int -> Bool) -> IntSet -> (IntSet, IntSet)
I.partition (k -> Bool
f forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Enum a => Int -> a
toEnum) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall k. EnumSet k -> IntSet
unWrap
{-# INLINE partition #-}

split :: (Enum k) => k -> EnumSet k -> (EnumSet k, EnumSet k)
split :: forall k. Enum k => k -> EnumSet k -> (EnumSet k, EnumSet k)
split k
k = (forall k. IntSet -> EnumSet k
EnumSet forall (a :: * -> * -> *) b c b' c'.
Arrow a =>
a b c -> a b' c' -> a (b, b') (c, c')
*** forall k. IntSet -> EnumSet k
EnumSet) forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> IntSet -> (IntSet, IntSet)
I.split (forall a. Enum a => a -> Int
fromEnum k
k) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall k. EnumSet k -> IntSet
unWrap
{-# INLINE split #-}

splitMember :: (Enum k) => k -> EnumSet k -> (EnumSet k, Bool, EnumSet k)
splitMember :: forall k. Enum k => k -> EnumSet k -> (EnumSet k, Bool, EnumSet k)
splitMember k
k =  forall {b} {k} {k}.
(IntSet, b, IntSet) -> (EnumSet k, b, EnumSet k)
wrap forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> IntSet -> (IntSet, Bool, IntSet)
I.splitMember (forall a. Enum a => a -> Int
fromEnum k
k) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall k. EnumSet k -> IntSet
unWrap
  where
    wrap :: (IntSet, b, IntSet) -> (EnumSet k, b, EnumSet k)
wrap (IntSet
is1, b
b, IntSet
is2) = (forall k. IntSet -> EnumSet k
EnumSet IntSet
is1, b
b, forall k. IntSet -> EnumSet k
EnumSet IntSet
is2)
{-# INLINE splitMember #-}

maxView :: (Enum k) => EnumSet k -> Maybe (k, EnumSet k)
maxView :: forall k. Enum k => EnumSet k -> Maybe (k, EnumSet k)
maxView = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (forall a. Enum a => Int -> a
toEnum forall (a :: * -> * -> *) b c b' c'.
Arrow a =>
a b c -> a b' c' -> a (b, b') (c, c')
*** forall k. IntSet -> EnumSet k
EnumSet) forall b c a. (b -> c) -> (a -> b) -> a -> c
. IntSet -> Maybe (Int, IntSet)
I.maxView forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall k. EnumSet k -> IntSet
unWrap
{-# INLINE maxView #-}

minView :: (Enum k) => EnumSet k -> Maybe (k, EnumSet k)
minView :: forall k. Enum k => EnumSet k -> Maybe (k, EnumSet k)
minView = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (forall a. Enum a => Int -> a
toEnum forall (a :: * -> * -> *) b c b' c'.
Arrow a =>
a b c -> a b' c' -> a (b, b') (c, c')
*** forall k. IntSet -> EnumSet k
EnumSet) forall b c a. (b -> c) -> (a -> b) -> a -> c
. IntSet -> Maybe (Int, IntSet)
I.minView  forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall k. EnumSet k -> IntSet
unWrap
{-# INLINE minView #-}

deleteFindMin :: (Enum k) => EnumSet k -> (k, EnumSet k)
deleteFindMin :: forall k. Enum k => EnumSet k -> (k, EnumSet k)
deleteFindMin = (forall a. Enum a => Int -> a
toEnum forall (a :: * -> * -> *) b c b' c'.
Arrow a =>
a b c -> a b' c' -> a (b, b') (c, c')
*** forall k. IntSet -> EnumSet k
EnumSet) forall b c a. (b -> c) -> (a -> b) -> a -> c
. IntSet -> (Int, IntSet)
I.deleteFindMin forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall k. EnumSet k -> IntSet
unWrap
{-# INLINE deleteFindMin #-}

deleteFindMax :: (Enum k) => EnumSet k -> (k, EnumSet k)
deleteFindMax :: forall k. Enum k => EnumSet k -> (k, EnumSet k)
deleteFindMax = (forall a. Enum a => Int -> a
toEnum forall (a :: * -> * -> *) b c b' c'.
Arrow a =>
a b c -> a b' c' -> a (b, b') (c, c')
*** forall k. IntSet -> EnumSet k
EnumSet) forall b c a. (b -> c) -> (a -> b) -> a -> c
. IntSet -> (Int, IntSet)
I.deleteFindMax forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall k. EnumSet k -> IntSet
unWrap
{-# INLINE deleteFindMax #-}

findMin :: (Enum k) => EnumSet k -> k
findMin :: forall k. Enum k => EnumSet k -> k
findMin = forall a. Enum a => Int -> a
toEnum forall b c a. (b -> c) -> (a -> b) -> a -> c
. IntSet -> Int
I.findMin forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall k. EnumSet k -> IntSet
unWrap
{-# INLINE findMin #-}

findMax :: (Enum k) => EnumSet k -> k
findMax :: forall k. Enum k => EnumSet k -> k
findMax = forall a. Enum a => Int -> a
toEnum forall b c a. (b -> c) -> (a -> b) -> a -> c
. IntSet -> Int
I.findMax forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall k. EnumSet k -> IntSet
unWrap
{-# INLINE findMax #-}

deleteMin :: EnumSet k -> EnumSet k
deleteMin :: forall k. EnumSet k -> EnumSet k
deleteMin = forall k. IntSet -> EnumSet k
EnumSet forall b c a. (b -> c) -> (a -> b) -> a -> c
. IntSet -> IntSet
I.deleteMin forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall k. EnumSet k -> IntSet
unWrap
{-# INLINE deleteMin #-}

deleteMax :: EnumSet k -> EnumSet k
deleteMax :: forall k. EnumSet k -> EnumSet k
deleteMax = forall k. IntSet -> EnumSet k
EnumSet forall b c a. (b -> c) -> (a -> b) -> a -> c
. IntSet -> IntSet
I.deleteMax forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall k. EnumSet k -> IntSet
unWrap
{-# INLINE deleteMax #-}

map :: (Enum k) => (k -> k) -> EnumSet k -> EnumSet k
map :: forall k. Enum k => (k -> k) -> EnumSet k -> EnumSet k
map k -> k
f = forall k. IntSet -> EnumSet k
EnumSet forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Int -> Int) -> IntSet -> IntSet
I.map (forall a. Enum a => a -> Int
fromEnum forall b c a. (b -> c) -> (a -> b) -> a -> c
. k -> k
f forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Enum a => Int -> a
toEnum) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall k. EnumSet k -> IntSet
unWrap
{-# INLINE map #-}

foldr :: (Enum k) => (k -> b -> b) -> b -> EnumSet k -> b
foldr :: forall k b. Enum k => (k -> b -> b) -> b -> EnumSet k -> b
foldr k -> b -> b
f b
acc = forall b. (Int -> b -> b) -> b -> IntSet -> b
I.foldr (k -> b -> b
f forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Enum a => Int -> a
toEnum) b
acc forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall k. EnumSet k -> IntSet
unWrap
{-# INLINE foldr #-}

foldl :: (Enum k) => (a -> k -> a) -> a -> EnumSet k -> a
foldl :: forall k a. Enum k => (a -> k -> a) -> a -> EnumSet k -> a
foldl a -> k -> a
f a
acc = forall a. (a -> Int -> a) -> a -> IntSet -> a
I.foldl (\a
a -> a -> k -> a
f a
a forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Enum a => Int -> a
toEnum) a
acc forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall k. EnumSet k -> IntSet
unWrap
{-# INLINE foldl #-}

foldr' :: (Enum k) => (k -> b -> b) -> b -> EnumSet k -> b
foldr' :: forall k b. Enum k => (k -> b -> b) -> b -> EnumSet k -> b
foldr' k -> b -> b
f b
acc = forall b. (Int -> b -> b) -> b -> IntSet -> b
I.foldr' (k -> b -> b
f forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Enum a => Int -> a
toEnum) b
acc forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall k. EnumSet k -> IntSet
unWrap
{-# INLINE foldr' #-}

foldl' :: (Enum k) => (a -> k -> a) -> a -> EnumSet k -> a
foldl' :: forall k a. Enum k => (a -> k -> a) -> a -> EnumSet k -> a
foldl' a -> k -> a
f a
acc = forall a. (a -> Int -> a) -> a -> IntSet -> a
I.foldl' (\a
a -> a -> k -> a
f a
a forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Enum a => Int -> a
toEnum) a
acc forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall k. EnumSet k -> IntSet
unWrap
{-# INLINE foldl' #-}

fold :: (Enum k) => (k -> b -> b) -> b -> EnumSet k -> b
fold :: forall k b. Enum k => (k -> b -> b) -> b -> EnumSet k -> b
fold k -> b -> b
f b
acc = forall b. (Int -> b -> b) -> b -> IntSet -> b
I.fold (k -> b -> b
f forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Enum a => Int -> a
toEnum) b
acc forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall k. EnumSet k -> IntSet
unWrap
{-# INLINE fold #-}

elems :: (Enum k) => EnumSet k -> [k]
elems :: forall k. Enum k => EnumSet k -> [k]
elems = forall a b. (a -> b) -> [a] -> [b]
P.map forall a. Enum a => Int -> a
toEnum forall b c a. (b -> c) -> (a -> b) -> a -> c
. IntSet -> [Int]
I.elems forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall k. EnumSet k -> IntSet
unWrap
{-# INLINE elems #-}

toList :: (Enum k) => EnumSet k -> [k]
toList :: forall k. Enum k => EnumSet k -> [k]
toList = forall a b. (a -> b) -> [a] -> [b]
P.map forall a. Enum a => Int -> a
toEnum forall b c a. (b -> c) -> (a -> b) -> a -> c
. IntSet -> [Int]
I.toList forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall k. EnumSet k -> IntSet
unWrap
{-# INLINE toList #-}

toAscList :: (Enum k) => EnumSet k -> [k]
toAscList :: forall k. Enum k => EnumSet k -> [k]
toAscList = forall a b. (a -> b) -> [a] -> [b]
P.map forall a. Enum a => Int -> a
toEnum forall b c a. (b -> c) -> (a -> b) -> a -> c
. IntSet -> [Int]
I.toAscList forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall k. EnumSet k -> IntSet
unWrap
{-# INLINE toAscList #-}

toDescList :: (Enum k) => EnumSet k -> [k]
toDescList :: forall k. Enum k => EnumSet k -> [k]
toDescList = forall a b. (a -> b) -> [a] -> [b]
P.map forall a. Enum a => Int -> a
toEnum forall b c a. (b -> c) -> (a -> b) -> a -> c
. IntSet -> [Int]
I.toDescList forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall k. EnumSet k -> IntSet
unWrap
{-# INLINE toDescList #-}

fromList :: (Enum k) => [k] -> EnumSet k
fromList :: forall k. Enum k => [k] -> EnumSet k
fromList = forall k. IntSet -> EnumSet k
EnumSet forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Int] -> IntSet
I.fromList forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a -> b) -> [a] -> [b]
P.map forall a. Enum a => a -> Int
fromEnum
{-# INLINE fromList #-}

fromAscList :: (Enum k) => [k] -> EnumSet k
fromAscList :: forall k. Enum k => [k] -> EnumSet k
fromAscList = forall k. IntSet -> EnumSet k
EnumSet forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Int] -> IntSet
I.fromAscList forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a -> b) -> [a] -> [b]
P.map forall a. Enum a => a -> Int
fromEnum
{-# INLINE fromAscList #-}

fromDistinctAscList :: (Enum k) => [k] -> EnumSet k
fromDistinctAscList :: forall k. Enum k => [k] -> EnumSet k
fromDistinctAscList = forall k. IntSet -> EnumSet k
EnumSet forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Int] -> IntSet
I.fromDistinctAscList forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a -> b) -> [a] -> [b]
P.map forall a. Enum a => a -> Int
fromEnum
{-# INLINE fromDistinctAscList #-}