tags:

views:

49

answers:

0

I have working on clustering algorithm. I decided to use hashmap to store the points because thinking that i can use as clusterID and as the point. I do a dfs fashion search to identify nearest and my calculation related work and all the looping on data take place outside of the method that I identify the clusters.

Also the intention of this clustering is that, if a point belongs to a same cluster its id remain the same. What I want to find out is that once i enter value in the hash map how can increase the index for the next value (Key would be same) with out using loop.

Here is how my method looks like, I took up some content of the algorithm out of since it really not relevant to the question.

public void dfsNearest(double point) {

  double aPointInCluster = point;
  if(!cluster.contains(aPointInCluster)) {
                        ...
   this.setNumOfClusters(this.getNumOfClusters() + 1);
   mapOfCluster.put(this.getNumOfClusters(), aPointInCluster);
                        //after this i want to increase the index so no override happens
  }
                ...

  if(newNeighbor != 0.0) {
   cluster.add(newNeighbor);
   mapOfCluster.put(this.getNumOfClusters(), newNeighbor);
                        //want to increase the index....
                        ... 
   if (!visitedMap.containsKey(newNeighbor)) {
    dfsNearest(newNeighbor);
   }
  }
               ...
 }

Thanks for any suggestions, also please let me know if rest of the code is necessary to make a good decision. Just wanted to keep it simple.