|
|
|
|
|
Description |
|
|
Synopsis |
|
|
|
|
Bag type
|
|
|
A bag of integers.
| Instances | |
|
|
Operators
|
|
|
O(n+m). See difference.
|
|
Query
|
|
|
O(1). Is the bag empty?
|
|
|
O(n). The number of elements in the bag.
|
|
|
O(n). Returns the number of distinct elements in the bag, ie. (distinctSize bag == length (nub (toList bag))).
|
|
|
O(min(n,W)). Is the element in the bag?
|
|
|
O(min(n,W)). The number of occurrences of an element in the bag.
|
|
|
O(n+m). Is this a subset of the bag?
|
|
|
O(n+m). Is this a proper subset? (ie. a subset and not equal)
|
|
Construction
|
|
|
O(1). Create an empty bag.
|
|
|
O(1). Create a singleton bag.
|
|
|
O(min(n,W)). Insert an element in the bag.
|
|
|
O(min(n,W)). The expression (insertMany x count bag)
inserts count instances of x in the bag bag.
|
|
|
O(min(n,W)). Delete a single element.
|
|
|
O(min(n,W)). Delete all occurrences of an element.
|
|
Combine
|
|
|
O(n+m). Union of two bags. The union adds the elements together.
IntBag\> union (fromList [1,1,2]) (fromList [1,2,2,3])
{1,1,1,2,2,2,3}
|
|
|
O(n+m). Difference between two bags.
IntBag\> difference (fromList [1,1,2]) (fromList [1,2,2,3])
{1}
|
|
|
O(n+m). Intersection of two bags.
IntBag\> intersection (fromList [1,1,2]) (fromList [1,2,2,3])
{1,2}
|
|
|
The union of a list of bags.
|
|
Filter
|
|
|
O(n). Filter all elements that satisfy some predicate.
|
|
|
O(n). Partition the bag according to some predicate.
|
|
Fold
|
|
|
O(n). Fold over each element in the bag.
|
|
|
O(n). Fold over all occurrences of an element at once.
In a call (foldOccur f z bag), the function f takes
the element first and than the occur count.
|
|
Conversion
|
|
|
O(n). The list of elements.
|
|
List
|
|
|
O(n). Create a list with all elements.
|
|
|
O(n*min(n,W)). Create a bag from a list of elements.
|
|
Ordered list
|
|
|
O(n). Create an ascending list of all elements.
|
|
|
O(n*min(n,W)). Create a bag from an ascending list.
|
|
|
O(n*min(n,W)). Create a bag from an ascending list of distinct elements.
|
|
Occurrence lists
|
|
|
O(n). Create a list of element/occurrence pairs.
|
|
|
O(n). Create an ascending list of element/occurrence pairs.
|
|
|
O(n*min(n,W)). Create a bag from a list of element/occurrence pairs.
|
|
|
O(n*min(n,W)). Create a bag from an ascending list of element/occurrence pairs.
|
|
IntMap
|
|
|
O(1). Convert to an IntMap.IntMap from elements to number of occurrences.
|
|
|
O(n). Convert a IntMap.IntMap from elements to occurrences into a bag.
|
|
|
O(1). Convert a IntMap.IntMap from elements to occurrences into a bag.
Assumes that the IntMap.IntMap contains only elements that occur at least once.
|
|
Debugging
|
|
|
O(n). Show the tree structure that implements the IntBag. The tree
is shown as a compressed and hanging.
|
|
|
O(n). The expression (showTreeWith hang wide map) shows
the tree that implements the bag. The tree is shown hanging when hang is True
and otherwise as a rotated tree. When wide is True an extra wide version
is shown.
|
|
Produced by Haddock version 2.4.2 |