Environment for
DeveLoping
KDD-Applications
Supported by Index-Structures

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

java.lang.Object
  extended by de.lmu.ifi.dbs.elki.logging.AbstractLoggable
      extended by de.lmu.ifi.dbs.elki.utilities.KNNList<D>
All Implemented Interfaces:
Loggable

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

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<QueryResult<D>> list
          The underlying set.
 
Fields inherited from class de.lmu.ifi.dbs.elki.logging.AbstractLoggable
debug
 
Constructor Summary
KNNList(int k, D infiniteDistance)
          Creates a new KNNList with the specified parameters.
 
Method Summary
 boolean add(QueryResult<D> o)
          Adds a new object to this list.
 List<D> distancesToList()
           
 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()
           
 List<Integer> idsToList()
           
 int size()
          Returns the current size of this list.
 List<QueryResult<D>> toList()
          Returns a list representation of this KList.
 String toString()
          Returns a string representation of the object.
 
Methods inherited from class de.lmu.ifi.dbs.elki.logging.AbstractLoggable
debugFine, debugFiner, debugFinest, exception, message, progress, progress, progress, verbose, verbose, warning
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

list

private SortedSet<QueryResult<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(QueryResult<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<QueryResult<D>> toList()
Returns a list representation of this KList.

Returns:
a list representation of this KList

distancesToList

public List<D> distancesToList()

idsToList

public List<Integer> idsToList()

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()
Overrides:
hashCode in class Object

Release 0.1 (2008-07-10_1838)