histogram-simple-1.2: Simple Data.Map-based histogram
Safe HaskellSafe-Inferred
LanguageHaskell2010

Data.Histogram

Description

Simple Map-based histogram. A histogram counts occurrences of things, i.e. 'Histogram k' represents a mapping k -> Int. Since it is backed by a Map from Map, it requires k to have an Ord instance.

Synopsis

Documentation

data Histogram k Source #

A simple Map-based histogram that counts occurrences of k.

Instances

Instances details
Eq k => Eq (Histogram k) Source # 
Instance details

Defined in Data.Histogram

Methods

(==) :: Histogram k -> Histogram k -> Bool #

(/=) :: Histogram k -> Histogram k -> Bool #

Show k => Show (Histogram k) Source # 
Instance details

Defined in Data.Histogram

Ord k => Semigroup (Histogram k) Source # 
Instance details

Defined in Data.Histogram

Methods

(<>) :: Histogram k -> Histogram k -> Histogram k #

sconcat :: NonEmpty (Histogram k) -> Histogram k #

stimes :: Integral b => b -> Histogram k -> Histogram k #

Ord k => Monoid (Histogram k) Source # 
Instance details

Defined in Data.Histogram

toMap :: Histogram k -> Map k Int Source #

Convert to a histogram to a map of counts of all nonzero values

increment :: Ord k => k -> Histogram k -> Histogram k Source #

Increase a key's count by one

decrement :: Ord k => k -> Histogram k -> Histogram k Source #

Decrease a key's count by one

lookup :: Ord k => k -> Histogram k -> Int Source #

(!) :: Ord k => Histogram k -> k -> Int Source #

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.

reset :: Ord k => k -> Histogram k -> Histogram k Source #

Set a key's count to 0.

zero :: Ord k => k -> Histogram k -> Bool Source #

Check whether a key has a count of 0

nonzero :: Ord k => k -> Histogram k -> Bool Source #

Check whether a key has a count of at least 1.

size :: Histogram k -> Int Source #

Get the total number of elements in the map, i.e. the sum of all bins.

empty :: Histogram k -> Bool Source #

Check whether a histogram is empty

keys :: Histogram k -> [k] Source #

Get a list of all non-zero keys.

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.

singleton :: k -> Histogram k Source #

A histogram containing one key with a count of 1.

split :: Ord k => k -> Histogram k -> (Histogram k, Histogram k) Source #

O(n). The expression (split k hist) is a pair (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.

isSubsetOfBy :: Ord k => (Int -> Int -> Bool) -> Histogram k -> Histogram k -> Bool Source #

isSubsetOfBy f h1 h2 returns True if every key in h1 compares to True to its corresponding key in h2 by f.

disjoint :: Ord k => Histogram k -> Histogram k -> Bool Source #

disjoint k1 k2 returns True 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.

fromCountList :: Ord k => [(k, Int)] -> Histogram k Source #

flatMap :: Ord k' => (k -> Int -> Histogram k') -> Histogram k -> Histogram k' Source #

toList :: Histogram k -> [(k, Int)] Source #

fromMap :: Map k Int -> Histogram k Source #

Construct a histogram from a map, removing all elements smaller than 1

unsafeFromMap :: Map k Int -> Histogram k Source #

Construct a histogram directly from a map, without checking if every element is above 1