refcount-0.0.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

(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).