gnutant
Class GnutantPheromone

java.lang.Object
  |
  +--gnutant.GnutantPheromone

public class GnutantPheromone
extends java.lang.Object

Gnutant Pheromone is "the routing table" of the Gnutant species. Ants may only add knowledge about new keywords, and the nest where documents relating to that keyword may be found. The underlying data structure will take care of limiting the resource (memory) usage, by implementing an LRU policy. Ants may also obtain a list of nests that contain more information about a given keyword or closely matching keywords.

Version:
$Revision$
Author:
Hein Meling

Constructor Summary
GnutantPheromone(AntView view)
          Creates a new GnutantPheromone instance.
GnutantPheromone(AntView view, int capacity)
          Creates a new GnutantPheromone instance.
GnutantPheromone(AntView view, int capacity, int closeness)
          Creates a new GnutantPheromone instance.
 
Method Summary
 boolean addKeyhash(KeyHash keyhash, NestId nestid)
          Add a new nest containing a document that match the specified keyword, represented by a hash of the keyword.
 java.util.ArrayList getNextNest(KeyHash keyhash, java.util.ArrayList path)
          Obtains a set of possible next nests based on the provided keyhash.
 java.lang.String toString()
          Returns a string representation of the GnutantPheromone.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

GnutantPheromone

public GnutantPheromone(AntView view)
Creates a new GnutantPheromone instance.
Parameters:
view - an AntView value

GnutantPheromone

public GnutantPheromone(AntView view,
                        int capacity)
Creates a new GnutantPheromone instance.
Parameters:
view - an AntView value
capacity - an int value

GnutantPheromone

public GnutantPheromone(AntView view,
                        int capacity,
                        int closeness)
Creates a new GnutantPheromone instance.
Parameters:
view - an AntView value
capacity - an int value
closeness - an int value
Method Detail

addKeyhash

public boolean addKeyhash(KeyHash keyhash,
                          NestId nestid)
Add a new nest containing a document that match the specified keyword, represented by a hash of the keyword.

Note that this method is synchronized because there may be a race condition if trying to simultaneously add the same keyhash with different nest identifiers.

Parameters:
keyhash - Hash of the keyword represented by a KeyHash object.
nestid - Identifier for the nest holding a document represented by the specified keyword.
Returns:
true if the given keyword is already known. That is, other nests store information about this keyword. false is returned if the keyword is unknown.

getNextNest

public java.util.ArrayList getNextNest(KeyHash keyhash,
                                       java.util.ArrayList path)
Obtains a set of possible next nests based on the provided keyhash. If there is no exact match for the specified keyhash in the underlying datastructure the closes match will be made available in the first position in the returned ArrayList.
Parameters:
keyhash - the keyword to match against to find the set of possible next nests.
path - a list of nests to avoid, since we have already visited them.
Returns:
a list of possible next nests, sorted according to their closeness to the specified keyhash.

toString

public java.lang.String toString()
Returns a string representation of the GnutantPheromone. Since this a sort routing table, it will typically be large, so using this for outputing to the screen is ill-advised. It is mainly useful for logging the content of the pheromone tables at various times during a run.
Overrides:
toString in class java.lang.Object
Returns:
a String representation of the GnutantPheromone object. A multiline string will be returned.