peersim.util
Class IncrementalFreq

java.lang.Object
  extended by peersim.util.IncrementalFreq
All Implemented Interfaces:
java.lang.Cloneable

public class IncrementalFreq
extends java.lang.Object
implements java.lang.Cloneable

A class that can collect frequency information on integer input. right now it can handle only unsigned input. It simply ignores negative numbers.


Constructor Summary
IncrementalFreq()
          Calls this(-1), that is, no values will be ignored.
IncrementalFreq(int maxvalue)
           
 
Method Summary
 void add(int i)
          Adds item i to the input set.
 void add(int i, int k)
          Adds item i to the input set k times.
 java.lang.Object clone()
           
 boolean equals(java.lang.Object obj)
          Tests equality between two IncrementalFreq instances.
 int getFreq(int i)
          Returns the number of occurrences of the given integer.
 int getN()
          Returns number of processed data items.
 int hashCode()
          Hashcode (consistent with equals(java.lang.Object)).
 void print(java.io.PrintStream out)
          Prints current frequency information.
 void printAll(java.io.PrintStream out)
          Prints current frequency information.
 void remove(IncrementalFreq other, boolean strict)
          Performs an element-by-element vector subtraction of the frequency vectors.
 void reset()
          Reset the state of the object.
 java.lang.String toArithmeticExpression()
          An alternative method to convert the object to String
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

IncrementalFreq

public IncrementalFreq(int maxvalue)
Parameters:
maxvalue - Values in the input set larger than this one will be ignored. However, if it is negative, no values are ignored.

IncrementalFreq

public IncrementalFreq()
Calls this(-1), that is, no values will be ignored.

See Also:
IncrementalFreq(int)
Method Detail

reset

public void reset()
Reset the state of the object. After calling this, all public methods behave the same as they did after constructing the object.


add

public final void add(int i)
Adds item i to the input set. It calls add(i,1).

See Also:
add(int,int)

add

public void add(int i,
                int k)
Adds item i to the input set k times. That is, it increments counter i by k. If, however, i is negative, or larger than the maximum defined at construction time (if a maximum was set at all) the operation is ignored.


getN

public int getN()
Returns number of processed data items. This is the number of items over which the class holds statistics.


getFreq

public int getFreq(int i)
Returns the number of occurrences of the given integer.


remove

public void remove(IncrementalFreq other,
                   boolean strict)
Performs an element-by-element vector subtraction of the frequency vectors. If strict is true, it throws an IllegalArgumentException if this is not strictly larger than other (element by element) (Note that both frequency vectors are positive.) Otherwise just sets those elements in this to zero that are smaller than those of other.

Parameters:
other - The instance of IncrementalFreq to subtract
strict - See above explanation

printAll

public void printAll(java.io.PrintStream out)
Prints current frequency information. Prints a separate line for all values from 0 to the capacity of the internal representation using the format
 value occurrences
 
That is, numbers with zero occurrences will also be printed.


print

public void print(java.io.PrintStream out)
Prints current frequency information. Prints a separate line for all values that have a number of occurrences different from zero using the format
 value occurrences
 


toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

toArithmeticExpression

public java.lang.String toArithmeticExpression()
An alternative method to convert the object to String


clone

public java.lang.Object clone()
                       throws java.lang.CloneNotSupportedException
Overrides:
clone in class java.lang.Object
Throws:
java.lang.CloneNotSupportedException

equals

public boolean equals(java.lang.Object obj)
Tests equality between two IncrementalFreq instances. Two objects are equal if both hold the same set of numbers that have occurred non-zero times and the number of occurrences is also equal for these numbers.

Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Hashcode (consistent with equals(java.lang.Object)). Probably you will never want to use this, but since we have equals(java.lang.Object), we must implement it.

Overrides:
hashCode in class java.lang.Object