refcount-0.1.1: Container with element counts

Safe HaskellSafe-Inferred

Data.Refcount

Synopsis

Documentation

newtype Refcount a Source

Maintain a collection of objects with duplication counts.

Constructors

Refcount 

Fields

unRefcount :: HashMap a Int
 

Instances

Eq a => Eq (Refcount a) 
Show a => Show (Refcount a) 
Generic (Refcount a) 
(Arbitrary a, Hashable a, Eq a) => Arbitrary (Refcount a) 
(Hashable a, Eq a) => Monoid (Refcount a) 

refcount :: (Hashable a, Eq a) => a -> Refcount a -> IntSource

Lookup the count of an object.

refcounted :: Refcount a -> [a]Source

Retrieve the refcounted objects.

insertRef :: (Hashable a, Eq a) => a -> Refcount a -> Refcount aSource

Insert an object and increment its count.

deleteRef :: (Hashable a, Eq a) => a -> Refcount a -> Maybe (Refcount a)Source

Remove a reference to an element and decrease its count, possibly removing it from the set. Returns Nothing if the element wasn't found, or Just set.

removeRef :: (Hashable a, Eq a) => a -> Refcount a -> Maybe (Bool, Refcount a)Source

Remove a reference to an element and decrease its count, possibly removing it from the set. Returns Nothing if the element wasn't found, or Just (wasRemoved, set).

fromList :: (Hashable a, Eq a) => [a] -> Refcount aSource

Create a counted structure from a list of elements.