Safe Haskell | Safe |
---|---|

Language | Haskell2010 |

A simple overlay over Data.Map to manage unordered sets with duplicates.

## Synopsis

- newtype Bag a = Bag {}
- null :: Bag a -> Bool
- size :: Bag a -> Int
- (!) :: Ord a => Bag a -> a -> [a]
- member :: Ord a => a -> Bag a -> Bool
- notMember :: Ord a => a -> Bag a -> Bool
- count :: Ord a => a -> Bag a -> Int
- empty :: Bag a
- singleton :: a -> Bag a
- union :: Ord a => Bag a -> Bag a -> Bag a
- unions :: Ord a => [Bag a] -> Bag a
- insert :: Ord a => a -> Bag a -> Bag a
- fromList :: Ord a => [a] -> Bag a
- groups :: Bag a -> [[a]]
- toList :: Bag a -> [a]
- keys :: Bag a -> [a]
- elems :: Bag a -> [a]
- toAscList :: Bag a -> [a]
- map :: Ord b => (a -> b) -> Bag a -> Bag b
- traverse' :: forall a b m. (Applicative m, Ord b) => (a -> m b) -> Bag a -> m (Bag b)

# Documentation

A set with duplicates. Faithfully stores elements which are equal with regard to (==).

## Instances

Foldable Bag Source # | |

Defined in Agda.Utils.Bag fold :: Monoid m => Bag m -> m # foldMap :: Monoid m => (a -> m) -> Bag a -> m # foldr :: (a -> b -> b) -> b -> Bag a -> b # foldr' :: (a -> b -> b) -> b -> Bag a -> b # foldl :: (b -> a -> b) -> b -> Bag a -> b # foldl' :: (b -> a -> b) -> b -> Bag a -> b # foldr1 :: (a -> a -> a) -> Bag a -> a # foldl1 :: (a -> a -> a) -> Bag a -> a # elem :: Eq a => a -> Bag a -> Bool # maximum :: Ord a => Bag a -> a # | |

Eq a => Eq (Bag a) Source # | |

Ord a => Ord (Bag a) Source # | |

Show a => Show (Bag a) Source # | |

Ord a => Semigroup (Bag a) Source # | |

Ord a => Monoid (Bag a) Source # | |

Null (Bag a) Source # | |

# Query

(!) :: Ord a => Bag a -> a -> [a] Source #

`(bag ! a)`

finds all elements equal to `a`

. O(log n).
Total function, returns `[]`

if none are.

count :: Ord a => a -> Bag a -> Int Source #

Return the multiplicity of the given element. O(log n + count _ _).