Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Synopsis
- data Histogram k
- toMap :: Histogram k -> Map k Int
- increment :: Ord k => k -> Histogram k -> Histogram k
- decrement :: Ord k => k -> Histogram k -> Histogram k
- lookup :: Ord k => k -> Histogram k -> Int
- (!) :: Ord k => Histogram k -> k -> Int
- add :: Ord k => Int -> k -> Histogram k -> Histogram k
- set :: Ord k => Int -> k -> Histogram k -> Histogram k
- reset :: Ord k => k -> Histogram k -> Histogram k
- zero :: Ord k => k -> Histogram k -> Bool
- nonzero :: Ord k => k -> Histogram k -> Bool
- size :: Histogram k -> Int
- empty :: Histogram k -> Bool
- keys :: Histogram k -> [k]
- mapKeys :: Ord k2 => (k1 -> k2) -> Histogram k1 -> Histogram k2
- singleton :: k -> Histogram k
- singletonCount :: Ord k => k -> Int -> Histogram k
- split :: Ord k => k -> Histogram k -> (Histogram k, Histogram k)
- splitLookup :: Ord k => k -> Histogram k -> (Histogram k, Int, Histogram k)
- isSubsetOf :: Ord k => Histogram k -> Histogram k -> Bool
- isSubsetOfBy :: Ord k => (Int -> Int -> Bool) -> Histogram k -> Histogram k -> Bool
- disjoint :: Ord k => Histogram k -> Histogram k -> Bool
- fromList :: Ord k => [k] -> Histogram k
- fromCountList :: Ord k => [(k, Int)] -> Histogram k
- flatMap :: Ord k' => (k -> Int -> Histogram k') -> Histogram k -> Histogram k'
- toList :: Histogram k -> [(k, Int)]
- fromMap :: Map k Int -> Histogram k
- unsafeFromMap :: Map k Int -> Histogram k
Documentation
A simple Map
-based histogram that counts occurrences of k
.
toMap :: Histogram k -> Map k Int Source #
Convert to a histogram to a map of counts of all nonzero values
add :: Ord k => Int -> k -> Histogram k -> Histogram k Source #
Increase a key's count by an arbitrary number. Can also be used to decrease by passing a negative value. If the count falls below zero, it's set to 0.
set :: Ord k => Int -> k -> Histogram k -> Histogram k Source #
Set a key's count to an exact value. Nonpositive numbers clip to 0.
size :: Histogram k -> Int Source #
Get the total number of elements in the map, i.e. the sum of all bins.
mapKeys :: Ord k2 => (k1 -> k2) -> Histogram k1 -> Histogram k2 Source #
Applies a function to every key. If two keys in the original map to the same value, their counts are combined.
split :: Ord k => k -> Histogram k -> (Histogram k, Histogram k) Source #
O(n). The expression (
) is a pair split
k hist(h1,h2)
where all keys in h1
are lower than k
and all keys in
h2
larger than k
. Any key equal to k
is found in neither h1
nor h2
.
isSubsetOf :: Ord k => Histogram k -> Histogram k -> Bool Source #
isSubsetOf h1 h2
returns True
if no key has a greater count in h1
than in h2
.
disjoint :: Ord k => Histogram k -> Histogram k -> Bool Source #
returns disjoint
k1 k2True
when there is no key that is nonzero in both k1
and k2
.
fromList :: Ord k => [k] -> Histogram k Source #
Construct a histogram by counting occurrences in a list of keys.