    {-
    (c) The University of Glasgow 2006
    (c) The AQUA Project, Glasgow University, 1994-1998

    \section[UniqSet]{Specialised sets, for things with @Uniques@}

    Based on @UniqFMs@ (as you would expect).

    Basically, the things need to be in class @Uniquable@.
    -}
    {-# LANGUAGE GeneralizedNewtypeDeriving #-}
    {-# LANGUAGE DeriveDataTypeable #-}

    module GHC.Types.Unique.Set (
            -- * Unique set type
            UniqSet,    -- type synonym for UniqFM a
            getUniqSet,
            pprUniqSet,

            -- ** Manipulating these sets
            emptyUniqSet,
            unitUniqSet,
            mkUniqSet,
            addOneToUniqSet, addListToUniqSet,
            delOneFromUniqSet, delOneFromUniqSet_Directly, delListFromUniqSet,
            delListFromUniqSet_Directly,
            unionUniqSets, unionManyUniqSets,
            minusUniqSet, uniqSetMinusUFM, uniqSetMinusUDFM,
            intersectUniqSets,
            disjointUniqSets,
            restrictUniqSetToUFM,
            uniqSetAny, uniqSetAll,
            elementOfUniqSet,
            elemUniqSet_Directly,
            filterUniqSet,
            filterUniqSet_Directly,
            sizeUniqSet,
            isEmptyUniqSet,
            lookupUniqSet,
            lookupUniqSet_Directly,
            partitionUniqSet,
            mapUniqSet,
            unsafeUFMToUniqSet,
            nonDetEltsUniqSet,
            nonDetKeysUniqSet,
            nonDetStrictFoldUniqSet,
            mapMaybeUniqSet_sameUnique,

            -- UniqueSet
            UniqueSet(..),
            nullUniqueSet,
            sizeUniqueSet,
            memberUniqueSet,
            emptyUniqueSet,
            singletonUniqueSet,
            insertUniqueSet,
            deleteUniqueSet,
            differenceUniqueSet,
            unionUniqueSet,
            unionsUniqueSet,
            intersectionUniqueSet,
            isSubsetOfUniqueSet,
            filterUniqueSet,
            foldlUniqueSet,
            foldrUniqueSet,
            elemsUniqueSet,
            fromListUniqueSet,
        ) where

    import GHC.Prelude

    import GHC.Types.Unique.DFM
    import GHC.Types.Unique.FM
    import GHC.Types.Unique
    import Data.Coerce
    import GHC.Utils.Outputable
    import Data.Data
    import qualified Data.Semigroup as Semi
    import Control.DeepSeq
    import qualified GHC.Data.Word64Set as S

    -- Note [UniqSet invariant]
    -- ~~~~~~~~~~~~~~~~~~~~~~~~~
    -- UniqSet has the following invariant:
    --   The keys in the map are the uniques of the values
    -- It means that to implement mapUniqSet you have to update
    -- both the keys and the values.

    -- | Set of Uniquable values
    newtype UniqSet a = UniqSet {forall a. UniqSet a -> UniqFM a a
    getUniqSet' :: UniqFM a a}
                      deriving (Typeable (UniqSet a)
    Typeable (UniqSet a) =>
    (forall (c :: * -> *).
     (forall d b. Data d => c (d -> b) -> d -> c b)
     -> (forall g. g -> c g) -> UniqSet a -> c (UniqSet a))
    -> (forall (c :: * -> *).
        (forall b r. Data b => c (b -> r) -> c r)
        -> (forall r. r -> c r) -> Constr -> c (UniqSet a))
    -> (UniqSet a -> Constr)
    -> (UniqSet a -> DataType)
    -> (forall (t :: * -> *) (c :: * -> *).
        Typeable t =>
        (forall d. Data d => c (t d)) -> Maybe (c (UniqSet a)))
    -> (forall (t :: * -> * -> *) (c :: * -> *).
        Typeable t =>
        (forall d e. (Data d, Data e) => c (t d e))
        -> Maybe (c (UniqSet a)))
    -> ((forall b. Data b => b -> b) -> UniqSet a -> UniqSet a)
    -> (forall r r'.
        (r -> r' -> r)
        -> r -> (forall d. Data d => d -> r') -> UniqSet a -> r)
    -> (forall r r'.
        (r' -> r -> r)
        -> r -> (forall d. Data d => d -> r') -> UniqSet a -> r)
    -> (forall u. (forall d. Data d => d -> u) -> UniqSet a -> [u])
    -> (forall u.
        Int -> (forall d. Data d => d -> u) -> UniqSet a -> u)
    -> (forall (m :: * -> *).
        Monad m =>
        (forall d. Data d => d -> m d) -> UniqSet a -> m (UniqSet a))
    -> (forall (m :: * -> *).
        MonadPlus m =>
        (forall d. Data d => d -> m d) -> UniqSet a -> m (UniqSet a))
    -> (forall (m :: * -> *).
        MonadPlus m =>
        (forall d. Data d => d -> m d) -> UniqSet a -> m (UniqSet a))
    -> Data (UniqSet a)
    UniqSet a -> Constr
    UniqSet a -> DataType
    (forall b. Data b => b -> b) -> UniqSet a -> UniqSet a
    forall a. Data a => Typeable (UniqSet a)
    forall a. Data a => UniqSet a -> Constr
    forall a. Data a => UniqSet a -> DataType
    forall a.
    Data a =>
    (forall b. Data b => b -> b) -> UniqSet a -> UniqSet a
    forall a u.
    Data a =>
    Int -> (forall d. Data d => d -> u) -> UniqSet a -> u
    forall a u.
    Data a =>
    (forall d. Data d => d -> u) -> UniqSet a -> [u]
    forall a r r'.
    Data a =>
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> UniqSet a -> r
    forall a r r'.
    Data a =>
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> UniqSet a -> r
    forall a (m :: * -> *).
    (Data a, Monad m) =>
    (forall d. Data d => d -> m d) -> UniqSet a -> m (UniqSet a)
    forall a (m :: * -> *).
    (Data a, MonadPlus m) =>
    (forall d. Data d => d -> m d) -> UniqSet a -> m (UniqSet a)
    forall a (c :: * -> *).
    Data a =>
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c (UniqSet a)
    forall a (c :: * -> *).
    Data a =>
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> UniqSet a -> c (UniqSet a)
    forall a (t :: * -> *) (c :: * -> *).
    (Data a, Typeable t) =>
    (forall d. Data d => c (t d)) -> Maybe (c (UniqSet a))
    forall a (t :: * -> * -> *) (c :: * -> *).
    (Data a, Typeable t) =>
    (forall d e. (Data d, Data e) => c (t d e))
    -> Maybe (c (UniqSet a))
    forall a.
    Typeable a =>
    (forall (c :: * -> *).
     (forall d b. Data d => c (d -> b) -> d -> c b)
     -> (forall g. g -> c g) -> a -> c a)
    -> (forall (c :: * -> *).
        (forall b r. Data b => c (b -> r) -> c r)
        -> (forall r. r -> c r) -> Constr -> c a)
    -> (a -> Constr)
    -> (a -> DataType)
    -> (forall (t :: * -> *) (c :: * -> *).
        Typeable t =>
        (forall d. Data d => c (t d)) -> Maybe (c a))
    -> (forall (t :: * -> * -> *) (c :: * -> *).
        Typeable t =>
        (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
    -> ((forall b. Data b => b -> b) -> a -> a)
    -> (forall r r'.
        (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
    -> (forall r r'.
        (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
    -> (forall u. (forall d. Data d => d -> u) -> a -> [u])
    -> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
    -> (forall (m :: * -> *).
        Monad m =>
        (forall d. Data d => d -> m d) -> a -> m a)
    -> (forall (m :: * -> *).
        MonadPlus m =>
        (forall d. Data d => d -> m d) -> a -> m a)
    -> (forall (m :: * -> *).
        MonadPlus m =>
        (forall d. Data d => d -> m d) -> a -> m a)
    -> Data a
    forall u. Int -> (forall d. Data d => d -> u) -> UniqSet a -> u
    forall u. (forall d. Data d => d -> u) -> UniqSet a -> [u]
    forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> UniqSet a -> r
    forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> UniqSet a -> r
    forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> UniqSet a -> m (UniqSet a)
    forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> UniqSet a -> m (UniqSet a)
    forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c (UniqSet a)
    forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> UniqSet a -> c (UniqSet a)
    forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c (UniqSet a))
    forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e))
    -> Maybe (c (UniqSet a))
    $cgfoldl :: forall a (c :: * -> *).
    Data a =>
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> UniqSet a -> c (UniqSet a)
    gfoldl :: forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> UniqSet a -> c (UniqSet a)
    $cgunfold :: forall a (c :: * -> *).
    Data a =>
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c (UniqSet a)
    gunfold :: forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c (UniqSet a)
    $ctoConstr :: forall a. Data a => UniqSet a -> Constr
    toConstr :: UniqSet a -> Constr
    $cdataTypeOf :: forall a. Data a => UniqSet a -> DataType
    dataTypeOf :: UniqSet a -> DataType
    $cdataCast1 :: forall a (t :: * -> *) (c :: * -> *).
    (Data a, Typeable t) =>
    (forall d. Data d => c (t d)) -> Maybe (c (UniqSet a))
    dataCast1 :: forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c (UniqSet a))
    $cdataCast2 :: forall a (t :: * -> * -> *) (c :: * -> *).
    (Data a, Typeable t) =>
    (forall d e. (Data d, Data e) => c (t d e))
    -> Maybe (c (UniqSet a))
    dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e))
    -> Maybe (c (UniqSet a))
    $cgmapT :: forall a.
    Data a =>
    (forall b. Data b => b -> b) -> UniqSet a -> UniqSet a
    gmapT :: (forall b. Data b => b -> b) -> UniqSet a -> UniqSet a
    $cgmapQl :: forall a r r'.
    Data a =>
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> UniqSet a -> r
    gmapQl :: forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> UniqSet a -> r
    $cgmapQr :: forall a r r'.
    Data a =>
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> UniqSet a -> r
    gmapQr :: forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> UniqSet a -> r
    $cgmapQ :: forall a u.
    Data a =>
    (forall d. Data d => d -> u) -> UniqSet a -> [u]
    gmapQ :: forall u. (forall d. Data d => d -> u) -> UniqSet a -> [u]
    $cgmapQi :: forall a u.
    Data a =>
    Int -> (forall d. Data d => d -> u) -> UniqSet a -> u
    gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> UniqSet a -> u
    $cgmapM :: forall a (m :: * -> *).
    (Data a, Monad m) =>
    (forall d. Data d => d -> m d) -> UniqSet a -> m (UniqSet a)
    gmapM :: forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> UniqSet a -> m (UniqSet a)
    $cgmapMp :: forall a (m :: * -> *).
    (Data a, MonadPlus m) =>
    (forall d. Data d => d -> m d) -> UniqSet a -> m (UniqSet a)
    gmapMp :: forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> UniqSet a -> m (UniqSet a)
    $cgmapMo :: forall a (m :: * -> *).
    (Data a, MonadPlus m) =>
    (forall d. Data d => d -> m d) -> UniqSet a -> m (UniqSet a)
    gmapMo :: forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> UniqSet a -> m (UniqSet a)
    Data, NonEmpty (UniqSet a) -> UniqSet a
    UniqSet a -> UniqSet a -> UniqSet a
    (UniqSet a -> UniqSet a -> UniqSet a)
    -> (NonEmpty (UniqSet a) -> UniqSet a)
    -> (forall b. Integral b => b -> UniqSet a -> UniqSet a)
    -> Semigroup (UniqSet a)
    forall b. Integral b => b -> UniqSet a -> UniqSet a
    forall a. NonEmpty (UniqSet a) -> UniqSet a
    forall a. UniqSet a -> UniqSet a -> UniqSet a
    forall a.
    (a -> a -> a)
    -> (NonEmpty a -> a)
    -> (forall b. Integral b => b -> a -> a)
    -> Semigroup a
    forall a b. Integral b => b -> UniqSet a -> UniqSet a
    $c<> :: forall a. UniqSet a -> UniqSet a -> UniqSet a
    <> :: UniqSet a -> UniqSet a -> UniqSet a
    $csconcat :: forall a. NonEmpty (UniqSet a) -> UniqSet a
    sconcat :: NonEmpty (UniqSet a) -> UniqSet a
    $cstimes :: forall a b. Integral b => b -> UniqSet a -> UniqSet a
    stimes :: forall b. Integral b => b -> UniqSet a -> UniqSet a
    Semi.Semigroup, Semigroup (UniqSet a)
    UniqSet a
    Semigroup (UniqSet a) =>
    UniqSet a
    -> (UniqSet a -> UniqSet a -> UniqSet a)
    -> ([UniqSet a] -> UniqSet a)
    -> Monoid (UniqSet a)
    [UniqSet a] -> UniqSet a
    UniqSet a -> UniqSet a -> UniqSet a
    forall a. Semigroup (UniqSet a)
    forall a. UniqSet a
    forall a.
    Semigroup a =>
    a -> (a -> a -> a) -> ([a] -> a) -> Monoid a
    forall a. [UniqSet a] -> UniqSet a
    forall a. UniqSet a -> UniqSet a -> UniqSet a
    $cmempty :: forall a. UniqSet a
    mempty :: UniqSet a
    $cmappend :: forall a. UniqSet a -> UniqSet a -> UniqSet a
    mappend :: UniqSet a -> UniqSet a -> UniqSet a
    $cmconcat :: forall a. [UniqSet a] -> UniqSet a
    mconcat :: [UniqSet a] -> UniqSet a
    Monoid)

    instance NFData a => NFData (UniqSet a) where
      rnf :: UniqSet a -> ()
    rnf = (a -> ()) -> UniqSet a -> ()
    forall a. (a -> ()) -> UniqSet a -> ()
    forceUniqSet a -> ()
    forall a. NFData a => a -> ()
    rnf

    emptyUniqSet :: UniqSet a
    emptyUniqSet :: forall a. UniqSet a
    emptyUniqSet = UniqFM a a -> UniqSet a
    forall a. UniqFM a a -> UniqSet a
    UniqSet UniqFM a a
    forall {k} (key :: k) elt. UniqFM key elt
    emptyUFM

    unitUniqSet :: Uniquable a => a -> UniqSet a
    unitUniqSet :: forall a. Uniquable a => a -> UniqSet a
    unitUniqSet a
    x = UniqFM a a -> UniqSet a
    forall a. UniqFM a a -> UniqSet a
    UniqSet (UniqFM a a -> UniqSet a) -> UniqFM a a -> UniqSet a
    forall a b. (a -> b) -> a -> b
    $ a -> a -> UniqFM a a
    forall key elt. Uniquable key => key -> elt -> UniqFM key elt
    unitUFM a
    x a
    x

    mkUniqSet :: Uniquable a => [a] -> UniqSet a
    mkUniqSet :: forall a. Uniquable a => [a] -> UniqSet a
    mkUniqSet = (UniqSet a -> a -> UniqSet a) -> UniqSet a -> [a] -> UniqSet a
    forall b a. (b -> a -> b) -> b -> [a] -> b
    forall (t :: * -> *) b a.
    Foldable t =>
    (b -> a -> b) -> b -> t a -> b
    foldl' UniqSet a -> a -> UniqSet a
    forall a. Uniquable a => UniqSet a -> a -> UniqSet a
    addOneToUniqSet UniqSet a
    forall a. UniqSet a
    emptyUniqSet
    {-# INLINEABLE mkUniqSet #-}

    addOneToUniqSet :: Uniquable a => UniqSet a -> a -> UniqSet a
    addOneToUniqSet :: forall a. Uniquable a => UniqSet a -> a -> UniqSet a
    addOneToUniqSet (UniqSet UniqFM a a
    set) a
    x = UniqFM a a -> UniqSet a
    forall a. UniqFM a a -> UniqSet a
    UniqSet (UniqFM a a -> a -> a -> UniqFM a a
    forall key elt.
    Uniquable key =>
    UniqFM key elt -> key -> elt -> UniqFM key elt
    addToUFM UniqFM a a
    set a
    x a
    x)

    addListToUniqSet :: Uniquable a => UniqSet a -> [a] -> UniqSet a
    addListToUniqSet :: forall a. Uniquable a => UniqSet a -> [a] -> UniqSet a
    addListToUniqSet = (UniqSet a -> a -> UniqSet a) -> UniqSet a -> [a] -> UniqSet a
    forall b a. (b -> a -> b) -> b -> [a] -> b
    forall (t :: * -> *) b a.
    Foldable t =>
    (b -> a -> b) -> b -> t a -> b
    foldl' UniqSet a -> a -> UniqSet a
    forall a. Uniquable a => UniqSet a -> a -> UniqSet a
    addOneToUniqSet
    {-# INLINEABLE addListToUniqSet #-}

    delOneFromUniqSet :: Uniquable a => UniqSet a -> a -> UniqSet a
    delOneFromUniqSet :: forall a. Uniquable a => UniqSet a -> a -> UniqSet a
    delOneFromUniqSet (UniqSet UniqFM a a
    s) a
    a = UniqFM a a -> UniqSet a
    forall a. UniqFM a a -> UniqSet a
    UniqSet (UniqFM a a -> a -> UniqFM a a
    forall key elt.
    Uniquable key =>
    UniqFM key elt -> key -> UniqFM key elt
    delFromUFM UniqFM a a
    s a
    a)

    delOneFromUniqSet_Directly :: UniqSet a -> Unique -> UniqSet a
    delOneFromUniqSet_Directly :: forall a. UniqSet a -> Unique -> UniqSet a
    delOneFromUniqSet_Directly (UniqSet UniqFM a a
    s) Unique
    u = UniqFM a a -> UniqSet a
    forall a. UniqFM a a -> UniqSet a
    UniqSet (UniqFM a a -> Unique -> UniqFM a a
    forall {k} (key :: k) elt.
    UniqFM key elt -> Unique -> UniqFM key elt
    delFromUFM_Directly UniqFM a a
    s Unique
    u)

    delListFromUniqSet :: Uniquable a => UniqSet a -> [a] -> UniqSet a
    delListFromUniqSet :: forall a. Uniquable a => UniqSet a -> [a] -> UniqSet a
    delListFromUniqSet (UniqSet UniqFM a a
    s) [a]
    l = UniqFM a a -> UniqSet a
    forall a. UniqFM a a -> UniqSet a
    UniqSet (UniqFM a a -> [a] -> UniqFM a a
    forall key elt.
    Uniquable key =>
    UniqFM key elt -> [key] -> UniqFM key elt
    delListFromUFM UniqFM a a
    s [a]
    l)
    {-# INLINEABLE delListFromUniqSet #-}

    delListFromUniqSet_Directly :: UniqSet a -> [Unique] -> UniqSet a
    delListFromUniqSet_Directly :: forall a. UniqSet a -> [Unique] -> UniqSet a
    delListFromUniqSet_Directly (UniqSet UniqFM a a
    s) [Unique]
    l =
        UniqFM a a -> UniqSet a
    forall a. UniqFM a a -> UniqSet a
    UniqSet (UniqFM a a -> [Unique] -> UniqFM a a
    forall {k} (key :: k) elt.
    UniqFM key elt -> [Unique] -> UniqFM key elt
    delListFromUFM_Directly UniqFM a a
    s [Unique]
    l)
    {-# INLINEABLE delListFromUniqSet_Directly #-}

    unionUniqSets :: UniqSet a -> UniqSet a -> UniqSet a
    unionUniqSets :: forall a. UniqSet a -> UniqSet a -> UniqSet a
    unionUniqSets (UniqSet UniqFM a a
    s) (UniqSet UniqFM a a
    t) = UniqFM a a -> UniqSet a
    forall a. UniqFM a a -> UniqSet a
    UniqSet (UniqFM a a -> UniqFM a a -> UniqFM a a
    forall {k} (key :: k) elt.
    UniqFM key elt -> UniqFM key elt -> UniqFM key elt
    plusUFM UniqFM a a
    s UniqFM a a
    t)

    unionManyUniqSets :: [UniqSet a] -> UniqSet a
    unionManyUniqSets :: forall a. [UniqSet a] -> UniqSet a
    unionManyUniqSets = (UniqSet a -> UniqSet a -> UniqSet a)
    -> UniqSet a -> [UniqSet a] -> UniqSet a
    forall b a. (b -> a -> b) -> b -> [a] -> b
    forall (t :: * -> *) b a.
    Foldable t =>
    (b -> a -> b) -> b -> t a -> b
    foldl' ((UniqSet a -> UniqSet a -> UniqSet a)
    -> UniqSet a -> UniqSet a -> UniqSet a
    forall a b c. (a -> b -> c) -> b -> a -> c
    flip UniqSet a -> UniqSet a -> UniqSet a
    forall a. UniqSet a -> UniqSet a -> UniqSet a
    unionUniqSets) UniqSet a
    forall a. UniqSet a
    emptyUniqSet

    minusUniqSet  :: UniqSet a -> UniqSet a -> UniqSet a
    minusUniqSet :: forall a. UniqSet a -> UniqSet a -> UniqSet a
    minusUniqSet (UniqSet UniqFM a a
    s) (UniqSet UniqFM a a
    t) = UniqFM a a -> UniqSet a
    forall a. UniqFM a a -> UniqSet a
    UniqSet (UniqFM a a -> UniqFM a a -> UniqFM a a
    forall {k} (key :: k) elt1 elt2.
    UniqFM key elt1 -> UniqFM key elt2 -> UniqFM key elt1
    minusUFM UniqFM a a
    s UniqFM a a
    t)

    intersectUniqSets :: UniqSet a -> UniqSet a -> UniqSet a
    intersectUniqSets :: forall a. UniqSet a -> UniqSet a -> UniqSet a
    intersectUniqSets (UniqSet UniqFM a a
    s) (UniqSet UniqFM a a
    t) = UniqFM a a -> UniqSet a
    forall a. UniqFM a a -> UniqSet a
    UniqSet (UniqFM a a -> UniqFM a a -> UniqFM a a
    forall {k} (key :: k) elt1 elt2.
    UniqFM key elt1 -> UniqFM key elt2 -> UniqFM key elt1
    intersectUFM UniqFM a a
    s UniqFM a a
    t)

    disjointUniqSets :: UniqSet a -> UniqSet a -> Bool
    disjointUniqSets :: forall a. UniqSet a -> UniqSet a -> Bool
    disjointUniqSets (UniqSet UniqFM a a
    s) (UniqSet UniqFM a a
    t) = UniqFM a a -> UniqFM a a -> Bool
    forall {k} (key :: k) elt1 elt2.
    UniqFM key elt1 -> UniqFM key elt2 -> Bool
    disjointUFM UniqFM a a
    s UniqFM a a
    t

    restrictUniqSetToUFM :: UniqSet key -> UniqFM key b -> UniqSet key
    restrictUniqSetToUFM :: forall key b. UniqSet key -> UniqFM key b -> UniqSet key
    restrictUniqSetToUFM (UniqSet UniqFM key key
    s) UniqFM key b
    m = UniqFM key key -> UniqSet key
    forall a. UniqFM a a -> UniqSet a
    UniqSet (UniqFM key key -> UniqFM key b -> UniqFM key key
    forall {k} (key :: k) elt1 elt2.
    UniqFM key elt1 -> UniqFM key elt2 -> UniqFM key elt1
    intersectUFM UniqFM key key
    s UniqFM key b
    m)

    uniqSetMinusUFM :: UniqSet key -> UniqFM key b -> UniqSet key
    uniqSetMinusUFM :: forall key b. UniqSet key -> UniqFM key b -> UniqSet key
    uniqSetMinusUFM (UniqSet UniqFM key key
    s) UniqFM key b
    t = UniqFM key key -> UniqSet key
    forall a. UniqFM a a -> UniqSet a
    UniqSet (UniqFM key key -> UniqFM key b -> UniqFM key key
    forall {k} (key :: k) elt1 elt2.
    UniqFM key elt1 -> UniqFM key elt2 -> UniqFM key elt1
    minusUFM UniqFM key key
    s UniqFM key b
    t)

    uniqSetMinusUDFM :: UniqSet key -> UniqDFM key b -> UniqSet key
    uniqSetMinusUDFM :: forall key b. UniqSet key -> UniqDFM key b -> UniqSet key
    uniqSetMinusUDFM (UniqSet UniqFM key key
    s) UniqDFM key b
    t = UniqFM key key -> UniqSet key
    forall a. UniqFM a a -> UniqSet a
    UniqSet (UniqFM key key -> UniqDFM key b -> UniqFM key key
    forall {k} (key :: k) elt1 elt2.
    UniqFM key elt1 -> UniqDFM key elt2 -> UniqFM key elt1
    ufmMinusUDFM UniqFM key key
    s UniqDFM key b
    t)

    elementOfUniqSet :: Uniquable a => a -> UniqSet a -> Bool
    elementOfUniqSet :: forall a. Uniquable a => a -> UniqSet a -> Bool
    elementOfUniqSet a
    a (UniqSet UniqFM a a
    s) = a -> UniqFM a a -> Bool
    forall key elt. Uniquable key => key -> UniqFM key elt -> Bool
    elemUFM a
    a UniqFM a a
    s

    elemUniqSet_Directly :: Unique -> UniqSet a -> Bool
    elemUniqSet_Directly :: forall a. Unique -> UniqSet a -> Bool
    elemUniqSet_Directly Unique
    a (UniqSet UniqFM a a
    s) = Unique -> UniqFM a a -> Bool
    forall {k} (key :: k) elt. Unique -> UniqFM key elt -> Bool
    elemUFM_Directly Unique
    a UniqFM a a
    s

    filterUniqSet :: (a -> Bool) -> UniqSet a -> UniqSet a
    filterUniqSet :: forall a. (a -> Bool) -> UniqSet a -> UniqSet a
    filterUniqSet a -> Bool
    p (UniqSet UniqFM a a
    s) = UniqFM a a -> UniqSet a
    forall a. UniqFM a a -> UniqSet a
    UniqSet ((a -> Bool) -> UniqFM a a -> UniqFM a a
    forall {k} elt (key :: k).
    (elt -> Bool) -> UniqFM key elt -> UniqFM key elt
    filterUFM a -> Bool
    p UniqFM a a
    s)

    filterUniqSet_Directly :: (Unique -> elt -> Bool) -> UniqSet elt -> UniqSet elt
    filterUniqSet_Directly :: forall elt. (Unique -> elt -> Bool) -> UniqSet elt -> UniqSet elt
    filterUniqSet_Directly Unique -> elt -> Bool
    f (UniqSet UniqFM elt elt
    s) = UniqFM elt elt -> UniqSet elt
    forall a. UniqFM a a -> UniqSet a
    UniqSet ((Unique -> elt -> Bool) -> UniqFM elt elt -> UniqFM elt elt
    forall {k} elt (key :: k).
    (Unique -> elt -> Bool) -> UniqFM key elt -> UniqFM key elt
    filterUFM_Directly Unique -> elt -> Bool
    f UniqFM elt elt
    s)

    partitionUniqSet :: (a -> Bool) -> UniqSet a -> (UniqSet a, UniqSet a)
    partitionUniqSet :: forall a. (a -> Bool) -> UniqSet a -> (UniqSet a, UniqSet a)
    partitionUniqSet a -> Bool
    p (UniqSet UniqFM a a
    s) = (UniqFM a a, UniqFM a a) -> (UniqSet a, UniqSet a)
    forall a b. Coercible a b => a -> b
    coerce ((a -> Bool) -> UniqFM a a -> (UniqFM a a, UniqFM a a)
    forall {k} elt (key :: k).
    (elt -> Bool) -> UniqFM key elt -> (UniqFM key elt, UniqFM key elt)
    partitionUFM a -> Bool
    p UniqFM a a
    s)

    uniqSetAny :: (a -> Bool) -> UniqSet a -> Bool
    uniqSetAny :: forall a. (a -> Bool) -> UniqSet a -> Bool
    uniqSetAny a -> Bool
    p (UniqSet UniqFM a a
    s) = (a -> Bool) -> UniqFM a a -> Bool
    forall {k} elt (key :: k). (elt -> Bool) -> UniqFM key elt -> Bool
    anyUFM a -> Bool
    p UniqFM a a
    s

    uniqSetAll :: (a -> Bool) -> UniqSet a -> Bool
    uniqSetAll :: forall a. (a -> Bool) -> UniqSet a -> Bool
    uniqSetAll a -> Bool
    p (UniqSet UniqFM a a
    s) = (a -> Bool) -> UniqFM a a -> Bool
    forall {k} elt (key :: k). (elt -> Bool) -> UniqFM key elt -> Bool
    allUFM a -> Bool
    p UniqFM a a
    s

    sizeUniqSet :: UniqSet a -> Int
    sizeUniqSet :: forall a. UniqSet a -> Int
    sizeUniqSet (UniqSet UniqFM a a
    s) = UniqFM a a -> Int
    forall {k} (key :: k) elt. UniqFM key elt -> Int
    sizeUFM UniqFM a a
    s

    isEmptyUniqSet :: UniqSet a -> Bool
    isEmptyUniqSet :: forall a. UniqSet a -> Bool
    isEmptyUniqSet (UniqSet UniqFM a a
    s) = UniqFM a a -> Bool
    forall {k} (key :: k) elt. UniqFM key elt -> Bool
    isNullUFM UniqFM a a
    s

    -- | What's the point you might ask? We might have changed an object
    -- without it's key changing. In which case this lookup makes sense.
    lookupUniqSet :: Uniquable key => UniqSet key -> key -> Maybe key
    lookupUniqSet :: forall key. Uniquable key => UniqSet key -> key -> Maybe key
    lookupUniqSet (UniqSet UniqFM key key
    s) key
    k = UniqFM key key -> key -> Maybe key
    forall key elt. Uniquable key => UniqFM key elt -> key -> Maybe elt
    lookupUFM UniqFM key key
    s key
    k

    lookupUniqSet_Directly :: UniqSet a -> Unique -> Maybe a
    lookupUniqSet_Directly :: forall a. UniqSet a -> Unique -> Maybe a
    lookupUniqSet_Directly (UniqSet UniqFM a a
    s) Unique
    k = UniqFM a a -> Unique -> Maybe a
    forall {k} (key :: k) elt. UniqFM key elt -> Unique -> Maybe elt
    lookupUFM_Directly UniqFM a a
    s Unique
    k

    -- See Note [Deterministic UniqFM] to learn about nondeterminism.
    -- If you use this please provide a justification why it doesn't introduce
    -- nondeterminism.
    nonDetEltsUniqSet :: UniqSet elt -> [elt]
    nonDetEltsUniqSet :: forall elt. UniqSet elt -> [elt]
    nonDetEltsUniqSet = UniqFM elt elt -> [elt]
    forall {k} (key :: k) elt. UniqFM key elt -> [elt]
    nonDetEltsUFM (UniqFM elt elt -> [elt])
    -> (UniqSet elt -> UniqFM elt elt) -> UniqSet elt -> [elt]
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . UniqSet elt -> UniqFM elt elt
    forall a. UniqSet a -> UniqFM a a
    getUniqSet'

    -- See Note [Deterministic UniqFM] to learn about nondeterminism.
    -- If you use this please provide a justification why it doesn't introduce
    -- nondeterminism.
    nonDetKeysUniqSet :: UniqSet elt -> [Unique]
    nonDetKeysUniqSet :: forall elt. UniqSet elt -> [Unique]
    nonDetKeysUniqSet = UniqFM elt elt -> [Unique]
    forall {k} (key :: k) elt. UniqFM key elt -> [Unique]
    nonDetKeysUFM (UniqFM elt elt -> [Unique])
    -> (UniqSet elt -> UniqFM elt elt) -> UniqSet elt -> [Unique]
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . UniqSet elt -> UniqFM elt elt
    forall a. UniqSet a -> UniqFM a a
    getUniqSet'

    -- See Note [Deterministic UniqFM] to learn about nondeterminism.
    -- If you use this please provide a justification why it doesn't introduce
    -- nondeterminism.
    nonDetStrictFoldUniqSet :: (elt -> a -> a) -> a -> UniqSet elt -> a
    nonDetStrictFoldUniqSet :: forall elt a. (elt -> a -> a) -> a -> UniqSet elt -> a
    nonDetStrictFoldUniqSet elt -> a -> a
    c a
    n (UniqSet UniqFM elt elt
    s) = (elt -> a -> a) -> a -> UniqFM elt elt -> a
    forall {k} elt a (key :: k).
    (elt -> a -> a) -> a -> UniqFM key elt -> a
    nonDetStrictFoldUFM elt -> a -> a
    c a
    n UniqFM elt elt
    s

    -- See Note [UniqSet invariant]
    mapUniqSet :: Uniquable b => (a -> b) -> UniqSet a -> UniqSet b
    mapUniqSet :: forall b a. Uniquable b => (a -> b) -> UniqSet a -> UniqSet b
    mapUniqSet a -> b
    f = [b] -> UniqSet b
    forall a. Uniquable a => [a] -> UniqSet a
    mkUniqSet ([b] -> UniqSet b) -> (UniqSet a -> [b]) -> UniqSet a -> UniqSet b
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (a -> b) -> [a] -> [b]
    forall a b. (a -> b) -> [a] -> [b]
    map a -> b
    f ([a] -> [b]) -> (UniqSet a -> [a]) -> UniqSet a -> [b]
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . UniqSet a -> [a]
    forall elt. UniqSet elt -> [elt]
    nonDetEltsUniqSet

    -- | Like 'Data.Set.mapMaybe', but you must ensure the passed in function
    -- does not change the 'Unique'.
    mapMaybeUniqSet_sameUnique :: (a -> Maybe b) -> UniqSet a -> UniqSet b
    mapMaybeUniqSet_sameUnique :: forall a b. (a -> Maybe b) -> UniqSet a -> UniqSet b
    mapMaybeUniqSet_sameUnique a -> Maybe b
    f (UniqSet UniqFM a a
    a) = UniqFM b b -> UniqSet b
    forall a. UniqFM a a -> UniqSet a
    UniqSet (UniqFM b b -> UniqSet b) -> UniqFM b b -> UniqSet b
    forall a b. (a -> b) -> a -> b
    $ (a -> Maybe b) -> UniqFM a a -> UniqFM b b
    forall {k1} {k2} elt1 elt2 (key1 :: k1) (key2 :: k2).
    (elt1 -> Maybe elt2) -> UniqFM key1 elt1 -> UniqFM key2 elt2
    mapMaybeUFM_sameUnique a -> Maybe b
    f UniqFM a a
    a

    -- Two 'UniqSet's are considered equal if they contain the same
    -- uniques.
    instance Eq (UniqSet a) where
      UniqSet UniqFM a a
    a == :: UniqSet a -> UniqSet a -> Bool
    == UniqSet UniqFM a a
    b = UniqFM a a -> UniqFM a a -> Bool
    forall {k} (key :: k) elt1 elt2.
    UniqFM key elt1 -> UniqFM key elt2 -> Bool
    equalKeysUFM UniqFM a a
    a UniqFM a a
    b

    getUniqSet :: UniqSet a -> UniqFM a a
    getUniqSet :: forall a. UniqSet a -> UniqFM a a
    getUniqSet = UniqSet a -> UniqFM a a
    forall a. UniqSet a -> UniqFM a a
    getUniqSet'

    -- | 'unsafeUFMToUniqSet' converts a @'UniqFM' a@ into a @'UniqSet' a@
    -- assuming, without checking, that it maps each 'Unique' to a value
    -- that has that 'Unique'. See Note [UniqSet invariant].
    unsafeUFMToUniqSet :: UniqFM a a -> UniqSet a
    unsafeUFMToUniqSet :: forall a. UniqFM a a -> UniqSet a
    unsafeUFMToUniqSet = UniqFM a a -> UniqSet a
    forall a. UniqFM a a -> UniqSet a
    UniqSet

    instance Outputable a => Outputable (UniqSet a) where
        ppr :: UniqSet a -> SDoc
    ppr = (a -> SDoc) -> UniqSet a -> SDoc
    forall a. (a -> SDoc) -> UniqSet a -> SDoc
    pprUniqSet a -> SDoc
    forall a. Outputable a => a -> SDoc
    ppr

    pprUniqSet :: (a -> SDoc) -> UniqSet a -> SDoc
    -- It's OK to use nonDetUFMToList here because we only use it for
    -- pretty-printing.
    pprUniqSet :: forall a. (a -> SDoc) -> UniqSet a -> SDoc
    pprUniqSet a -> SDoc
    f = SDoc -> SDoc
    forall doc. IsLine doc => doc -> doc
    braces (SDoc -> SDoc) -> (UniqSet a -> SDoc) -> UniqSet a -> SDoc
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (a -> SDoc) -> [a] -> SDoc
    forall a. (a -> SDoc) -> [a] -> SDoc
    pprWithCommas a -> SDoc
    f ([a] -> SDoc) -> (UniqSet a -> [a]) -> UniqSet a -> SDoc
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . UniqSet a -> [a]
    forall elt. UniqSet elt -> [elt]
    nonDetEltsUniqSet

    forceUniqSet :: (a -> ()) -> UniqSet a -> ()
    forceUniqSet :: forall a. (a -> ()) -> UniqSet a -> ()
    forceUniqSet a -> ()
    f (UniqSet UniqFM a a
    fm) = (a -> ()) -> UniqFM a a -> ()
    forall {k} elt (key :: k). (elt -> ()) -> UniqFM key elt -> ()
    seqEltsUFM a -> ()
    f UniqFM a a
    fm

    --------------------------------------------------------
    -- UniqueSet
    --------------------------------------------------------

    -- | Set of Unique values
    --
    -- Similar to 'UniqSet Unique' but with a more compact representation.
    newtype UniqueSet = US { UniqueSet -> Word64Set
    unUniqueSet :: S.Word64Set }
      deriving (UniqueSet -> UniqueSet -> Bool
    (UniqueSet -> UniqueSet -> Bool)
    -> (UniqueSet -> UniqueSet -> Bool) -> Eq UniqueSet
    forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
    $c== :: UniqueSet -> UniqueSet -> Bool
    == :: UniqueSet -> UniqueSet -> Bool
    $c/= :: UniqueSet -> UniqueSet -> Bool
    /= :: UniqueSet -> UniqueSet -> Bool
    Eq, Eq UniqueSet
    Eq UniqueSet =>
    (UniqueSet -> UniqueSet -> Ordering)
    -> (UniqueSet -> UniqueSet -> Bool)
    -> (UniqueSet -> UniqueSet -> Bool)
    -> (UniqueSet -> UniqueSet -> Bool)
    -> (UniqueSet -> UniqueSet -> Bool)
    -> (UniqueSet -> UniqueSet -> UniqueSet)
    -> (UniqueSet -> UniqueSet -> UniqueSet)
    -> Ord UniqueSet
    UniqueSet -> UniqueSet -> Bool
    UniqueSet -> UniqueSet -> Ordering
    UniqueSet -> UniqueSet -> UniqueSet
    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
    $ccompare :: UniqueSet -> UniqueSet -> Ordering
    compare :: UniqueSet -> UniqueSet -> Ordering
    $c< :: UniqueSet -> UniqueSet -> Bool
    < :: UniqueSet -> UniqueSet -> Bool
    $c<= :: UniqueSet -> UniqueSet -> Bool
    <= :: UniqueSet -> UniqueSet -> Bool
    $c> :: UniqueSet -> UniqueSet -> Bool
    > :: UniqueSet -> UniqueSet -> Bool
    $c>= :: UniqueSet -> UniqueSet -> Bool
    >= :: UniqueSet -> UniqueSet -> Bool
    $cmax :: UniqueSet -> UniqueSet -> UniqueSet
    max :: UniqueSet -> UniqueSet -> UniqueSet
    $cmin :: UniqueSet -> UniqueSet -> UniqueSet
    min :: UniqueSet -> UniqueSet -> UniqueSet
    Ord, Int -> UniqueSet -> ShowS
    [UniqueSet] -> ShowS
    UniqueSet -> String
    (Int -> UniqueSet -> ShowS)
    -> (UniqueSet -> String)
    -> ([UniqueSet] -> ShowS)
    -> Show UniqueSet
    forall a.
    (Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
    $cshowsPrec :: Int -> UniqueSet -> ShowS
    showsPrec :: Int -> UniqueSet -> ShowS
    $cshow :: UniqueSet -> String
    show :: UniqueSet -> String
    $cshowList :: [UniqueSet] -> ShowS
    showList :: [UniqueSet] -> ShowS
    Show, NonEmpty UniqueSet -> UniqueSet
    UniqueSet -> UniqueSet -> UniqueSet
    (UniqueSet -> UniqueSet -> UniqueSet)
    -> (NonEmpty UniqueSet -> UniqueSet)
    -> (forall b. Integral b => b -> UniqueSet -> UniqueSet)
    -> Semigroup UniqueSet
    forall b. Integral b => b -> UniqueSet -> UniqueSet
    forall a.
    (a -> a -> a)
    -> (NonEmpty a -> a)
    -> (forall b. Integral b => b -> a -> a)
    -> Semigroup a
    $c<> :: UniqueSet -> UniqueSet -> UniqueSet
    <> :: UniqueSet -> UniqueSet -> UniqueSet
    $csconcat :: NonEmpty UniqueSet -> UniqueSet
    sconcat :: NonEmpty UniqueSet -> UniqueSet
    $cstimes :: forall b. Integral b => b -> UniqueSet -> UniqueSet
    stimes :: forall b. Integral b => b -> UniqueSet -> UniqueSet
    Semigroup, Semigroup UniqueSet
    UniqueSet
    Semigroup UniqueSet =>
    UniqueSet
    -> (UniqueSet -> UniqueSet -> UniqueSet)
    -> ([UniqueSet] -> UniqueSet)
    -> Monoid UniqueSet
    [UniqueSet] -> UniqueSet
    UniqueSet -> UniqueSet -> UniqueSet
    forall a.
    Semigroup a =>
    a -> (a -> a -> a) -> ([a] -> a) -> Monoid a
    $cmempty :: UniqueSet
    mempty :: UniqueSet
    $cmappend :: UniqueSet -> UniqueSet -> UniqueSet
    mappend :: UniqueSet -> UniqueSet -> UniqueSet
    $cmconcat :: [UniqueSet] -> UniqueSet
    mconcat :: [UniqueSet] -> UniqueSet
    Monoid)

    {-# INLINE nullUniqueSet #-}
    nullUniqueSet :: UniqueSet -> Bool
    nullUniqueSet :: UniqueSet -> Bool
    nullUniqueSet (US Word64Set
    s) = Word64Set -> Bool
    S.null Word64Set
    s

    {-# INLINE sizeUniqueSet #-}
    sizeUniqueSet :: UniqueSet -> Int
    sizeUniqueSet :: UniqueSet -> Int
    sizeUniqueSet (US Word64Set
    s) = Word64Set -> Int
    S.size Word64Set
    s

    {-# INLINE memberUniqueSet #-}
    memberUniqueSet :: Unique -> UniqueSet -> Bool
    memberUniqueSet :: Unique -> UniqueSet -> Bool
    memberUniqueSet Unique
    k (US Word64Set
    s) = Key -> Word64Set -> Bool
    S.member (Unique -> Key
    getKey Unique
    k) Word64Set
    s

    {-# INLINE emptyUniqueSet #-}
    emptyUniqueSet :: UniqueSet
    emptyUniqueSet :: UniqueSet
    emptyUniqueSet = Word64Set -> UniqueSet
    US Word64Set
    S.empty

    {-# INLINE singletonUniqueSet #-}
    singletonUniqueSet :: Unique -> UniqueSet
    singletonUniqueSet :: Unique -> UniqueSet
    singletonUniqueSet Unique
    k = Word64Set -> UniqueSet
    US (Key -> Word64Set
    S.singleton (Unique -> Key
    getKey Unique
    k))

    {-# INLINE insertUniqueSet #-}
    insertUniqueSet :: Unique -> UniqueSet -> UniqueSet
    insertUniqueSet :: Unique -> UniqueSet -> UniqueSet
    insertUniqueSet Unique
    k (US Word64Set
    s) = Word64Set -> UniqueSet
    US (Key -> Word64Set -> Word64Set
    S.insert (Unique -> Key
    getKey Unique
    k) Word64Set
    s)

    {-# INLINE deleteUniqueSet #-}
    deleteUniqueSet :: Unique -> UniqueSet -> UniqueSet
    deleteUniqueSet :: Unique -> UniqueSet -> UniqueSet
    deleteUniqueSet Unique
    k (US Word64Set
    s) = Word64Set -> UniqueSet
    US (Key -> Word64Set -> Word64Set
    S.delete (Unique -> Key
    getKey Unique
    k) Word64Set
    s)

    {-# INLINE unionUniqueSet #-}
    unionUniqueSet :: UniqueSet -> UniqueSet -> UniqueSet
    unionUniqueSet :: UniqueSet -> UniqueSet -> UniqueSet
    unionUniqueSet (US Word64Set
    x) (US Word64Set
    y) = Word64Set -> UniqueSet
    US (Word64Set -> Word64Set -> Word64Set
    S.union Word64Set
    x Word64Set
    y)

    {-# INLINE unionsUniqueSet #-}
    unionsUniqueSet :: [UniqueSet] -> UniqueSet
    unionsUniqueSet :: [UniqueSet] -> UniqueSet
    unionsUniqueSet [UniqueSet]
    xs = Word64Set -> UniqueSet
    US ([Word64Set] -> Word64Set
    S.unions ((UniqueSet -> Word64Set) -> [UniqueSet] -> [Word64Set]
    forall a b. (a -> b) -> [a] -> [b]
    map UniqueSet -> Word64Set
    unUniqueSet [UniqueSet]
    xs))

    {-# INLINE differenceUniqueSet #-}
    differenceUniqueSet :: UniqueSet -> UniqueSet -> UniqueSet
    differenceUniqueSet :: UniqueSet -> UniqueSet -> UniqueSet
    differenceUniqueSet (US Word64Set
    x) (US Word64Set
    y) = Word64Set -> UniqueSet
    US (Word64Set -> Word64Set -> Word64Set
    S.difference Word64Set
    x Word64Set
    y)

    {-# INLINE intersectionUniqueSet #-}
    intersectionUniqueSet :: UniqueSet -> UniqueSet -> UniqueSet
    intersectionUniqueSet :: UniqueSet -> UniqueSet -> UniqueSet
    intersectionUniqueSet (US Word64Set
    x) (US Word64Set
    y) = Word64Set -> UniqueSet
    US (Word64Set -> Word64Set -> Word64Set
    S.intersection Word64Set
    x Word64Set
    y)

    {-# INLINE isSubsetOfUniqueSet #-}
    isSubsetOfUniqueSet :: UniqueSet -> UniqueSet -> Bool
    isSubsetOfUniqueSet :: UniqueSet -> UniqueSet -> Bool
    isSubsetOfUniqueSet (US Word64Set
    x) (US Word64Set
    y) = Word64Set -> Word64Set -> Bool
    S.isSubsetOf Word64Set
    x Word64Set
    y

    {-# INLINE filterUniqueSet #-}
    filterUniqueSet :: (Unique -> Bool) -> UniqueSet -> UniqueSet
    filterUniqueSet :: (Unique -> Bool) -> UniqueSet -> UniqueSet
    filterUniqueSet Unique -> Bool
    f (US Word64Set
    s) = Word64Set -> UniqueSet
    US ((Key -> Bool) -> Word64Set -> Word64Set
    S.filter (Unique -> Bool
    f (Unique -> Bool) -> (Key -> Unique) -> Key -> Bool
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Key -> Unique
    mkUniqueGrimily) Word64Set
    s)

    {-# INLINE foldlUniqueSet #-}
    foldlUniqueSet :: (a -> Unique -> a) -> a -> UniqueSet -> a
    foldlUniqueSet :: forall a. (a -> Unique -> a) -> a -> UniqueSet -> a
    foldlUniqueSet a -> Unique -> a
    k a
    z (US Word64Set
    s) = (a -> Key -> a) -> a -> Word64Set -> a
    forall a. (a -> Key -> a) -> a -> Word64Set -> a
    S.foldl' (\a
    a Key
    b -> a -> Unique -> a
    k a
    a (Key -> Unique
    mkUniqueGrimily Key
    b)) a
    z Word64Set
    s

    {-# INLINE foldrUniqueSet #-}
    foldrUniqueSet :: (Unique -> b -> b) -> b -> UniqueSet -> b
    foldrUniqueSet :: forall b. (Unique -> b -> b) -> b -> UniqueSet -> b
    foldrUniqueSet Unique -> b -> b
    k b
    z (US Word64Set
    s) = (Key -> b -> b) -> b -> Word64Set -> b
    forall b. (Key -> b -> b) -> b -> Word64Set -> b
    S.foldr (Unique -> b -> b
    k (Unique -> b -> b) -> (Key -> Unique) -> Key -> b -> b
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Key -> Unique
    mkUniqueGrimily) b
    z Word64Set
    s

    {-# INLINE elemsUniqueSet #-}
    elemsUniqueSet :: UniqueSet -> [Unique]
    elemsUniqueSet :: UniqueSet -> [Unique]
    elemsUniqueSet (US Word64Set
    s) = (Key -> Unique) -> [Key] -> [Unique]
    forall a b. (a -> b) -> [a] -> [b]
    map Key -> Unique
    mkUniqueGrimily (Word64Set -> [Key]
    S.elems Word64Set
    s)

    {-# INLINE fromListUniqueSet #-}
    fromListUniqueSet :: [Unique] -> UniqueSet
    fromListUniqueSet :: [Unique] -> UniqueSet
    fromListUniqueSet [Unique]
    ks = Word64Set -> UniqueSet
    US ([Key] -> Word64Set
    S.fromList ((Unique -> Key) -> [Unique] -> [Key]
    forall a b. (a -> b) -> [a] -> [b]
    map Unique -> Key
    getKey [Unique]
    ks))