/** * Puts an element by substituting it in place of the top most element. * * @param i the index * @param d the distance * @throws Exception if distance is smaller than that of the head element */ public void putBySubstitute(int i, double d) throws Exception { MyHeapElement head = get(); put(i, d); // System.out.println("previous: "+head.distance+" current: "+m_heap[1].distance); if (head.distance == m_heap[1].distance) { // Utils.eq(head.distance, // m_heap[1].distance)) { putKthNearest(head.index, head.distance); } else if (head.distance > m_heap[1].distance) { // Utils.gr(head.distance, // m_heap[1].distance)) { m_KthNearest = null; m_KthNearestSize = 0; initSize = 10; } else if (head.distance < m_heap[1].distance) { throw new Exception("The substituted element is smaller than the " + "head element. put() should have been called " + "in place of putBySubstitute()"); } }
/** * Puts an element by substituting it in place of the top most element. * * @param i the index * @param d the distance * @throws Exception if distance is smaller than that of the head element */ public void putBySubstitute(int i, double d) throws Exception { MyHeapElement head = get(); put(i, d); // System.out.println("previous: "+head.distance+" current: "+m_heap[1].distance); if (head.distance == m_heap[1].distance) { // Utils.eq(head.distance, // m_heap[1].distance)) { putKthNearest(head.index, head.distance); } else if (head.distance > m_heap[1].distance) { // Utils.gr(head.distance, // m_heap[1].distance)) { m_KthNearest = null; m_KthNearestSize = 0; initSize = 10; } else if (head.distance < m_heap[1].distance) { throw new Exception("The substituted element is smaller than the " + "head element. put() should have been called " + "in place of putBySubstitute()"); } }
heap.putBySubstitute(m_InstList[i], distance); } else if (distance == head.distance) { heap.putKthNearest(m_InstList[i], distance);
heap.putBySubstitute(m_InstList[idx], distance); } else if (distance == temp.distance) { heap.putKthNearest(m_InstList[idx], distance);
heap.putBySubstitute(m_InstList[i], distance); } else if (distance == head.distance) { heap.putKthNearest(m_InstList[i], distance);
heap.putBySubstitute(m_InstList[idx], distance); } else if (distance == temp.distance) { heap.putKthNearest(m_InstList[idx], distance);
heap.putKthNearest(i, distance);
heap.putKthNearest(i, distance);