Environment for
DeveLoping
KDD-Applications
Supported by Index-Structures

de.lmu.ifi.dbs.elki.data
Class KNNList<D extends Distance<D>>

java.lang.Object
  extended by de.lmu.ifi.dbs.elki.data.KNNList<D>
Type Parameters:
D - Distance class

public class KNNList<D extends Distance<D>>
extends Object

A wrapper class for storing the k most similar comparable objects.

Author:
Elke Achtert

Field Summary
private  D infiniteDistance
          The infinite distance.
private  int k
          The maximum size of this list.
private  SortedSet<DistanceResultPair<D>> list
          The underlying set.
 
Constructor Summary
KNNList(int k, D infiniteDistance)
          Creates a new KNNList with the specified parameters.
 
Method Summary
 boolean add(DistanceResultPair<D> o)
          Adds a new object to this list.
 List<D> distancesToList()
          Return a list containing just the distances
 boolean equals(Object o)
          Indicates whether some other object is "equal to" this one.
 int getK()
          Returns the maximum size of this list.
 D getKNNDistance()
          Returns the k-th distance of this list (e.g. the key of the k-th element).
 D getMaximumDistance()
          Returns the maximum distance of this list (e.g. the key of the last element).
 int hashCode()
          Combine list hash code with the value of k.
 List<Integer> idsToList()
          Return a list containing only the object IDs
 int size()
          Returns the current size of this list.
 List<DistanceResultPair<D>> toList()
          Returns a list representation of this KList.
 String toString()
          Returns a string representation of the object.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

list

private SortedSet<DistanceResultPair<D extends Distance<D>>> list
The underlying set.


k

private int k
The maximum size of this list.


infiniteDistance

private D extends Distance<D> infiniteDistance
The infinite distance.

Constructor Detail

KNNList

public KNNList(int k,
               D infiniteDistance)
Creates a new KNNList with the specified parameters.

Parameters:
k - the number k of objects to be stored
infiniteDistance - the infinite distance
Method Detail

add

public boolean add(DistanceResultPair<D> o)
Adds a new object to this list. If this list contains already k entries and the key of the specified object o is less than the key of the last entry, the last entry will be deleted.

Parameters:
o - the object to be added
Returns:
true, if o has been added, false otherwise.

getKNNDistance

public D getKNNDistance()
Returns the k-th distance of this list (e.g. the key of the k-th element). If this list is empty or contains less than k elements, an infinite key will be returned.

Returns:
the maximum distance of this list

getMaximumDistance

public D getMaximumDistance()
Returns the maximum distance of this list (e.g. the key of the last element). If this list is empty an infinite key will be returned.

Returns:
the maximum distance of this list

toList

public List<DistanceResultPair<D>> toList()
Returns a list representation of this KList.

Returns:
a list representation of this KList

distancesToList

public List<D> distancesToList()
Return a list containing just the distances

Returns:
list of distances

idsToList

public List<Integer> idsToList()
Return a list containing only the object IDs

Returns:
list of object ids

size

public int size()
Returns the current size of this list.

Returns:
the current size of this list

getK

public int getK()
Returns the maximum size of this list.

Returns:
the maximum size of this list

toString

public String toString()
Returns a string representation of the object.

Overrides:
toString in class Object
Returns:
a string representation of the object.

equals

public boolean equals(Object o)
Indicates whether some other object is "equal to" this one.

Overrides:
equals in class Object
Parameters:
o - the reference object with which to compare.
Returns:
true if this object is the same as the obj argument; false otherwise.

hashCode

public int hashCode()
Combine list hash code with the value of k.

Overrides:
hashCode in class Object
See Also:
Object.hashCode()

Release 0.3 (2010-03-31_1612)