public TreeMap<Double,Integer> sort(TreeMap<Double,Integer> identifiers, DatasetObject objectQuery, int k)
    {
//        System.out.println("Filtering result set");
        java.util.Iterator<Double> s=identifiers.keySet().iterator();
//        if(s.hasNext())
//            s.next(); //skip first to eliminate query object
        TreeMap res=null;
        if(dataset!=null)
        {
            res=new TreeMap();
            while(s.hasNext()&& k>0)
            {
                k--;
                Double key=s.next();
                Integer o=identifiers.get(key);
                Double dist = dataset.distance(objectQuery,dataset.getObject(o));
                while(res.get(dist)!=null)
                {
                    dist+=0.00000001;
                }
                res.put(dist,o);
            }
        }
        else System.out.println("Sort not performed. No dataset associated!");
        return res;       
    }