{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE LinearTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE TupleSections #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -Wno-name-shadowing #-}
{-# OPTIONS_HADDOCK hide #-}
module Data.Set.Mutable.Linear.Internal where
import qualified Data.HashMap.Mutable.Linear as Linear
import Data.Monoid.Linear
import Data.Unrestricted.Linear
import qualified Prelude.Linear as Linear hiding (insert)
import Prelude (Bool, Int)
import qualified Prelude
newtype Set a = Set (Linear.HashMap a ())
type Keyed a = Linear.Keyed a
empty :: (Keyed a) => Int -> (Set a %1 -> Ur b) %1 -> Ur b
empty :: forall a b. Keyed a => Int -> (Set a %1 -> Ur b) %1 -> Ur b
empty Int
s (Set a %1 -> Ur b
f :: Set a %1 -> Ur b) =
forall k v b. Keyed k => Int -> (HashMap k v %1 -> Ur b) %1 -> Ur b
Linear.empty Int
s (\HashMap a ()
hm -> Set a %1 -> Ur b
f (forall a. HashMap a () -> Set a
Set HashMap a ()
hm))
toList :: (Keyed a) => Set a %1 -> Ur [a]
toList :: forall a. Keyed a => Set a %1 -> Ur [a]
toList (Set HashMap a ()
hm) =
forall k v. HashMap k v %1 -> Ur [(k, v)]
Linear.toList HashMap a ()
hm
forall a b (p :: Multiplicity) (q :: Multiplicity).
a %p -> (a %p -> b) %q -> b
Linear.& \(Ur [(a, ())]
xs) -> forall a. a -> Ur a
Ur (forall a b. (a -> b) -> [a] -> [b]
Prelude.map forall a b. (a, b) -> a
Prelude.fst [(a, ())]
xs)
insert :: (Keyed a) => a -> Set a %1 -> Set a
insert :: forall a. Keyed a => a -> Set a %1 -> Set a
insert a
a (Set HashMap a ()
hmap) = forall a. HashMap a () -> Set a
Set (forall k v. Keyed k => k -> v -> HashMap k v %1 -> HashMap k v
Linear.insert a
a () HashMap a ()
hmap)
delete :: (Keyed a) => a -> Set a %1 -> Set a
delete :: forall a. Keyed a => a -> Set a %1 -> Set a
delete a
a (Set HashMap a ()
hmap) = forall a. HashMap a () -> Set a
Set (forall k v. Keyed k => k -> HashMap k v %1 -> HashMap k v
Linear.delete a
a HashMap a ()
hmap)
union :: (Keyed a) => Set a %1 -> Set a %1 -> Set a
union :: forall a. Keyed a => Set a %1 -> Set a %1 -> Set a
union (Set HashMap a ()
hm1) (Set HashMap a ()
hm2) =
forall a. HashMap a () -> Set a
Set (forall k v.
Keyed k =>
(v -> v -> v) -> HashMap k v %1 -> HashMap k v %1 -> HashMap k v
Linear.unionWith (\()
_ ()
_ -> ()) HashMap a ()
hm1 HashMap a ()
hm2)
intersection :: (Keyed a) => Set a %1 -> Set a %1 -> Set a
intersection :: forall a. Keyed a => Set a %1 -> Set a %1 -> Set a
intersection (Set HashMap a ()
hm1) (Set HashMap a ()
hm2) =
forall a. HashMap a () -> Set a
Set (forall k a b c.
Keyed k =>
(a -> b -> c) -> HashMap k a %1 -> HashMap k b %1 -> HashMap k c
Linear.intersectionWith (\()
_ ()
_ -> ()) HashMap a ()
hm1 HashMap a ()
hm2)
size :: (Keyed a) => Set a %1 -> (Ur Int, Set a)
size :: forall a. Keyed a => Set a %1 -> (Ur Int, Set a)
size (Set HashMap a ()
hm) =
forall k v. HashMap k v %1 -> (Ur Int, HashMap k v)
Linear.size HashMap a ()
hm forall a b (p :: Multiplicity) (q :: Multiplicity).
a %p -> (a %p -> b) %q -> b
Linear.& \(Ur Int
s, HashMap a ()
hm') -> (Ur Int
s, forall a. HashMap a () -> Set a
Set HashMap a ()
hm')
member :: (Keyed a) => a -> Set a %1 -> (Ur Bool, Set a)
member :: forall a. Keyed a => a -> Set a %1 -> (Ur Bool, Set a)
member a
a (Set HashMap a ()
hm) =
forall k v.
Keyed k =>
k -> HashMap k v %1 -> (Ur Bool, HashMap k v)
Linear.member a
a HashMap a ()
hm forall a b (p :: Multiplicity) (q :: Multiplicity).
a %p -> (a %p -> b) %q -> b
Linear.& \(Ur Bool
b, HashMap a ()
hm') -> (Ur Bool
b, forall a. HashMap a () -> Set a
Set HashMap a ()
hm')
fromList :: (Keyed a) => [a] -> (Set a %1 -> Ur b) %1 -> Ur b
fromList :: forall a b. Keyed a => [a] -> (Set a %1 -> Ur b) %1 -> Ur b
fromList [a]
xs Set a %1 -> Ur b
f =
forall k v b.
Keyed k =>
[(k, v)] -> (HashMap k v %1 -> Ur b) %1 -> Ur b
Linear.fromList (forall a b. (a -> b) -> [a] -> [b]
Prelude.map (,()) [a]
xs) (\HashMap a ()
hm -> Set a %1 -> Ur b
f (forall a. HashMap a () -> Set a
Set HashMap a ()
hm))
instance Prelude.Semigroup (Set a) where
<> :: Set a -> Set a -> Set a
(<>) = forall a. HasCallStack => [Char] -> a
Prelude.error [Char]
"Prelude.(<>): invariant violation, unrestricted Set"
instance (Keyed a) => Semigroup (Set a) where
<> :: Set a %1 -> Set a %1 -> Set a
(<>) = forall a. Keyed a => Set a %1 -> Set a %1 -> Set a
union
instance Consumable (Set a) where
consume :: Set a %1 -> ()
consume (Set HashMap a ()
hmap) = forall a. Consumable a => a %1 -> ()
consume HashMap a ()
hmap
instance Dupable (Set a) where
dup2 :: Set a %1 -> (Set a, Set a)
dup2 (Set HashMap a ()
hm) =
forall a. Dupable a => a %1 -> (a, a)
dup2 HashMap a ()
hm forall a b (p :: Multiplicity) (q :: Multiplicity).
a %p -> (a %p -> b) %q -> b
Linear.& \(HashMap a ()
hm1, HashMap a ()
hm2) ->
(forall a. HashMap a () -> Set a
Set HashMap a ()
hm1, forall a. HashMap a () -> Set a
Set HashMap a ()
hm2)