edu.harvard.deas.hyperenc.util
Class NNLookup<V>

java.lang.Object
  extended by edu.harvard.deas.hyperenc.util.NNLookup<V>

public class NNLookup<V>
extends Object

A collection of objects and associated integer keys, with support for nearest-neighbor lookups. In other words, this is a Map with integer keys, and the get(int key) method retrieves the object whose key is numerically closest to key.


Constructor Summary
NNLookup()
           
 
Method Summary
 void add(int key, V object)
          Add the object object using key as its index.
 V delete(int key)
          Deletes the object with the key nearest to the specified key.
 Object deleteExact(int key)
          Deletes the object with the specified key.
 V get(int key)
          Get an object using the key key.
 Integer getClosestKey(int key)
          Get the key closest to the one passed in.
 V getExact(int key)
          Gets the object using this exact key.
 int size()
          Returns the number of key-value pairs stored in this map.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NNLookup

public NNLookup()
Method Detail

add

public void add(int key,
                V object)
Add the object object using key as its index.

Parameters:
key - The key to associated with object.
object - The object to be stored.

getExact

public V getExact(int key)
Gets the object using this exact key. If no object has key equal to key, returns null. This is the normal Map behavior.

Parameters:
key - The integer key value to search for.
Returns:
The data of the object with the exact key. Should be null iff the lookup table is empty.

get

public V get(int key)
Get an object using the key key. Gets the object whose key is numerically closest to the one passed in.

Parameters:
key - The integer key value to search for.
Returns:
the object with the closest key, or null iff the lookup table is empty.

delete

public V delete(int key)
Deletes the object with the key nearest to the specified key.

Parameters:
key - The key value you want to delete.
Returns:
The value mapped to the key deleted.

deleteExact

public Object deleteExact(int key)
Deletes the object with the specified key.

Parameters:
key - The key value you want to delete.
Returns:
The value mapped to the key deleted.

getClosestKey

public Integer getClosestKey(int key)
Get the key closest to the one passed in.

Parameters:
key - The key value to search for.
Returns:
The object with the closest key. Should be null iff the lookup table is empty. Currently this is an Integer.

size

public int size()
Returns the number of key-value pairs stored in this map.

Returns:
the size of this map