/** * Stores kth nearest elements (if there are more than one). * * @param i the index * @param d the distance */ public void putKthNearest(int i, double d) { if (m_KthNearest == null) { m_KthNearest = new MyHeapElement[initSize]; } if (m_KthNearestSize >= m_KthNearest.length) { initSize += initSize; MyHeapElement temp[] = new MyHeapElement[initSize]; System.arraycopy(m_KthNearest, 0, temp, 0, m_KthNearest.length); m_KthNearest = temp; } m_KthNearest[m_KthNearestSize++] = new MyHeapElement(i, d); }
/** * Stores kth nearest elements (if there are more than one). * * @param i the index * @param d the distance */ public void putKthNearest(int i, double d) { if (m_KthNearest == null) { m_KthNearest = new MyHeapElement[initSize]; } if (m_KthNearestSize >= m_KthNearest.length) { initSize += initSize; MyHeapElement temp[] = new MyHeapElement[initSize]; System.arraycopy(m_KthNearest, 0, temp, 0, m_KthNearest.length); m_KthNearest = temp; } m_KthNearest[m_KthNearestSize++] = new MyHeapElement(i, d); }
/** * adds the value to the heap. * * @param i the index * @param d the distance * @throws Exception if the heap gets too large */ public void put(int i, double d) throws Exception { if ((m_heap[0].index + 1) > (m_heap.length - 1)) { throw new Exception("the number of elements cannot exceed the " + "initially set maximum limit"); } m_heap[0].index++; m_heap[m_heap[0].index] = new MyHeapElement(i, d); upheap(); }
/** * adds the value to the heap. * * @param i the index * @param d the distance * @throws Exception if the heap gets too large */ public void put(int i, double d) throws Exception { if ((m_heap[0].index + 1) > (m_heap.length - 1)) { throw new Exception("the number of elements cannot exceed the " + "initially set maximum limit"); } m_heap[0].index++; m_heap[m_heap[0].index] = new MyHeapElement(i, d); upheap(); }
/** * constructor. * * @param maxSize the maximum size of the heap */ public MyHeap(int maxSize) { if ((maxSize % 2) == 0) { maxSize++; } m_heap = new MyHeapElement[maxSize + 1]; m_heap[0] = new MyHeapElement(0, 0); }
/** * constructor. * * @param maxSize the maximum size of the heap */ public MyHeap(int maxSize) { if ((maxSize % 2) == 0) { maxSize++; } m_heap = new MyHeapElement[maxSize + 1]; m_heap[0] = new MyHeapElement(0, 0); }