Class Histogram
In: lib/histogram.rb
Parent: Hash

A Histogram is a hash whose values are counts of the occurences of the keys.

Methods

<   <=   ==   >   >=   add   count   key_count   new  

Public Class methods

Creates and returns an instance. If arguments are given, they are passed to the add method to initialize the new instance.

Public Instance methods

Returns a new Histogram containing the elements with occurences less than the given count.

Returns a new Histogram containing the elements with occurences less than or equal to the given count.

If count is a number, a new Histogram containing the elements with occurences equal to the given countis returned. If the count is a histogram, true is returned if the instance contains the same keys and values; false otherwise.

Returns a new Histogram containing the elements with occurences greater than the given count.

Returns a new Histogram containing the elements with occurences greater than or equal to the given count.

Adds the key to the instance if it doesn‘t already exist, and adds the specified count to it value. If the key is

  • an Array, each member of the array is added. if the member itself is an Array, then if that array has one member, the member is added as a key; if two members, the member is added as a key and a count; otherwise, a HistogramException is thrown.
  • another histogram, the keys and counts in the key are added to the instance.

Returns the number of occurences of the given key. If an array of keys is given, the sum of the number of occurences of those keys is returned.

Returns the number of keys in the instance.

[Validate]