module StmContainers.Set
(
Set,
new,
newIO,
null,
size,
focus,
lookup,
insert,
delete,
reset,
unfoldlM,
listT,
)
where
import StmContainers.Prelude hiding (insert, delete, lookup, alter, foldM, toList, empty, null)
import qualified StmHamt.SizedHamt as A
import qualified Focus as B
newtype Set item =
Set (A.SizedHamt item)
deriving (Typeable)
{-# INLINABLE new #-}
new :: STM (Set item)
new =
Set <$> A.new
{-# INLINABLE newIO #-}
newIO :: IO (Set item)
newIO =
Set <$> A.newIO
{-# INLINABLE null #-}
null :: Set item -> STM Bool
null (Set hamt) =
A.null hamt
{-# INLINABLE size #-}
size :: Set item -> STM Int
size (Set hamt) =
A.size hamt
{-# INLINABLE focus #-}
focus :: (Eq item, Hashable item) => B.Focus () STM result -> item -> Set item -> STM result
focus unitFocus item (Set hamt) =
A.focus rowFocus id item hamt
where
rowFocus =
B.mappingInput (const item) (const ()) unitFocus
{-# INLINABLE lookup #-}
lookup :: (Eq item, Hashable item) => item -> Set item -> STM Bool
lookup =
focus (fmap isJust B.lookup)
{-# INLINABLE insert #-}
insert :: (Eq item, Hashable item) => item -> Set item -> STM ()
insert item (Set hamt) =
A.insert id item hamt
{-# INLINABLE delete #-}
delete :: (Eq item, Hashable item) => item -> Set item -> STM ()
delete item (Set hamt) =
A.focus B.delete id item hamt
{-# INLINABLE reset #-}
reset :: Set item -> STM ()
reset (Set hamt) =
A.reset hamt
{-# INLINABLE unfoldlM #-}
unfoldlM :: Set item -> UnfoldlM STM item
unfoldlM (Set hamt) =
A.unfoldlM hamt
{-# INLINE listT #-}
listT :: Set item -> ListT STM item
listT (Set hamt) =
A.listT hamt