edu.umd.cloud9.io
Class VectorInt<F extends WritableComparable>

java.lang.Object
  extended by java.util.AbstractMap<K,V>
      extended by java.util.HashMap<F,Integer>
          extended by edu.umd.cloud9.io.VectorInt<F>
Type Parameters:
F - type of feature
All Implemented Interfaces:
Serializable, Cloneable, Map<F,Integer>, Writable

public class VectorInt<F extends WritableComparable>
extends HashMap<F,Integer>
implements Writable

Writable representing a vector of integer values. This generic class, based on the Java HashMap, supports the use of any class for the features (i.e., component of the vector), but all values are integers.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K,V>
 
Constructor Summary
VectorInt()
          Creates a VectorInt object.
 
Method Summary
 int dot(VectorInt<F> v)
          Computes the dot product between this vector and another vector.
 int get(F f)
          Returns the value of a feature.
 SortedSet<Map.Entry<F,Integer>> getSortedEntries()
          Returns feature-value entries sorted by descending value.
 SortedSet<Map.Entry<F,Integer>> getSortedEntries(int n)
          Returns top n feature-value entries sorted by descending value.
 void plus(VectorInt<F> v)
          Adds another vector to this vector, based on feature-wise addition.
 void readFields(DataInput in)
          Deserializes the vector.
 void set(F f, int v)
          Sets the value of a feature.
 void write(DataOutput out)
          Serializes the vector.
 
Methods inherited from class java.util.HashMap
clear, clone, containsKey, containsValue, entrySet, get, isEmpty, keySet, put, putAll, remove, size, values
 
Methods inherited from class java.util.AbstractMap
equals, hashCode, toString
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Map
equals, hashCode
 

Constructor Detail

VectorInt

public VectorInt()
Creates a VectorInt object.

Method Detail

readFields

public void readFields(DataInput in)
                throws IOException
Deserializes the vector.

Specified by:
readFields in interface Writable
Parameters:
in - source for raw byte representation
Throws:
IOException

write

public void write(DataOutput out)
           throws IOException
Serializes the vector.

Specified by:
write in interface Writable
Parameters:
out - where to write the raw byte representation
Throws:
IOException

set

public void set(F f,
                int v)
Sets the value of a feature.

Parameters:
f - the feature
v - the value

get

public int get(F f)
Returns the value of a feature.

Parameters:
f - the feature
Returns:
the value of the feature

plus

public void plus(VectorInt<F> v)
Adds another vector to this vector, based on feature-wise addition.

Parameters:
v - vector to add

dot

public int dot(VectorInt<F> v)
Computes the dot product between this vector and another vector.

Parameters:
v - the other vector

getSortedEntries

public SortedSet<Map.Entry<F,Integer>> getSortedEntries()
Returns feature-value entries sorted by descending value. Ties broken by the natural sort order of the feature.

Returns:
feature-value entries sorted by descending value

getSortedEntries

public SortedSet<Map.Entry<F,Integer>> getSortedEntries(int n)
Returns top n feature-value entries sorted by descending value. Ties broken by the natural sort order of the feature.

Parameters:
n - number of entries to return
Returns:
top n feature-value entries sorted by descending value