congrats Icon
New! Announcing Tabnine Chat Beta
Learn More
Tabnine Logo
SortUtils.siftDown
Code IndexAdd Tabnine to your IDE (free)

How to use
siftDown
method
in
smile.sort.SortUtils

Best Java code snippets using smile.sort.SortUtils.siftDown (Showing top 13 results out of 315)

origin: com.github.haifengl/smile-math

/**
 * Place the array in max-heap order. Note that the array is not fully sorted.
 */
private static <T extends Comparable<? super T>> void heapify(T[] arr) {
  int n = arr.length;
  for (int i = n / 2 - 1; i >= 0; i--)
    SortUtils.siftDown(arr, i, n - 1);
}
origin: com.github.haifengl/smile-math

/**
 * Place the array in max-heap order. Note that the array is not fully sorted.
 */
private static void heapify(double[] arr) {
  int n = arr.length;
  for (int i = n / 2 - 1; i >= 0; i--)
    SortUtils.siftDown(arr, i, n - 1);
}
origin: com.github.haifengl/smile-math

/**
 * Place the array in max-heap order. Note that the array is not fully sorted.
 */
private static void heapify(float[] arr) {
  int n = arr.length;
  for (int i = n / 2 - 1; i >= 0; i--)
    SortUtils.siftDown(arr, i, n - 1);
}
origin: com.github.haifengl/smile-math

/**
 * Place the array in max-heap order. Note that the array is not fully sorted.
 */
private static void heapify(int[] arr) {
  int n = arr.length;
  for (int i = n / 2 - 1; i >= 0; i--)
    SortUtils.siftDown(arr, i, n - 1);
}
origin: com.github.haifengl/smile-math

/**
 * In case of avoiding creating new objects frequently, one may check and
 * update the peek object directly and call this method to sort the internal
 * array in heap order.
 */
public void heapify() {
  if (n < k) {
    throw new IllegalStateException();
  }
  SortUtils.siftDown(heap, 0, k-1);
}
origin: com.github.haifengl/smile-math

/**
 * Sorts the specified array into ascending numerical order.
 */
public static void sort(float[] arr) {
  int n = arr.length;
  for (int i = n / 2 - 1; i >= 0; i--)
    SortUtils.siftDown(arr, i, n - 1);
  for (int i = n - 1; i > 0; i--) {
    SortUtils.swap(arr, 0, i);
    SortUtils.siftDown(arr, 0, i - 1);
  }
}
origin: com.github.haifengl/smile-math

/**
 * Sorts the specified array into ascending numerical order.
 */
public static void sort(double[] arr) {
  int n = arr.length;
  for (int i = n / 2 - 1; i >= 0; i--)
    SortUtils.siftDown(arr, i, n - 1);
  for (int i = n - 1; i > 0; i--) {
    SortUtils.swap(arr, 0, i);
    SortUtils.siftDown(arr, 0, i - 1);
  }
}
origin: com.github.haifengl/smile-math

/**
 * Sorts the specified array into ascending numerical order.
 */
public static void sort(int[] arr) {
  int n = arr.length;
  for (int i = n / 2 - 1; i >= 0; i--)
    SortUtils.siftDown(arr, i, n - 1);
  for (int i = n - 1; i > 0; i--) {
    SortUtils.swap(arr, 0, i);
    SortUtils.siftDown(arr, 0, i - 1);
  }
}
origin: com.github.haifengl/smile-math

  /**
   * Sorts the specified array into ascending order.
   */
  public static <T extends Comparable<? super T>> void sort(T[] arr) {
    int n = arr.length;
    for (int i = n / 2 - 1; i >= 0; i--)
      SortUtils.siftDown(arr, i, n - 1);

    for (int i = n - 1; i > 0; i--) {
      SortUtils.swap(arr, 0, i);
      SortUtils.siftDown(arr, 0, i - 1);
    }
  }
}
origin: com.github.haifengl/smile-math

/**
 * Assimilate a new value from the stream.
 */
public void add(double datum) {
  sorted = false;
  if (n < k) {
    heap[n++] = datum;
    if (n == k) {
      sort(heap, k);
    }
  } else {
    n++;
    if (datum < heap[0]) {
      heap[0] = datum;
      SortUtils.siftDown(heap, 0, k-1);
    }
  }
}
origin: com.github.haifengl/smile-math

/**
 * Assimilate a new value from the stream.
 */
public void add(T datum) {
  sorted = false;
  if (n < k) {
    heap[n++] = datum;
    if (n == k) {
      heapify(heap);
    }
  } else {
    n++;
    if (datum.compareTo(heap[0]) < 0) {
      heap[0] = datum;
      SortUtils.siftDown(heap, 0, k-1);
    }
  }
}
origin: com.github.haifengl/smile-math

/**
 * Assimilate a new value from the stream.
 */
public void add(int datum) {
  sorted = false;
  if (n < k) {
    heap[n++] = datum;
    if (n == k) {
      heapify(heap);
    }
  } else {
    n++;
    if (datum < heap[0]) {
      heap[0] = datum;
      SortUtils.siftDown(heap, 0, k-1);
    }
  }
}
origin: com.github.haifengl/smile-math

/**
 * Assimilate a new value from the stream.
 */
public void add(float datum) {
  sorted = false;
  if (n < k) {
    heap[n++] = datum;
    if (n == k) {
      heapify(heap);
    }
  } else {
    n++;
    if (datum < heap[0]) {
      heap[0] = datum;
      SortUtils.siftDown(heap, 0, k-1);
    }
  }
}
smile.sortSortUtilssiftDown

Javadoc

To restore the max-heap condition when a node's priority is decreased. We move down the heap, exchanging the node at position k with the larger of that node's two children if necessary and stopping when the node at k is not smaller than either child or the bottom is reached. Note that if n is even and k is n/2, then the node at k has only one child -- this case must be treated properly.

Popular methods of SortUtils

  • swap
    Swap two positions.

Popular in Java

  • Start an intent from android
  • getApplicationContext (Context)
  • getSupportFragmentManager (FragmentActivity)
  • getSystemService (Context)
  • FileReader (java.io)
    A specialized Reader that reads from a file in the file system. All read requests made by calling me
  • ConnectException (java.net)
    A ConnectException is thrown if a connection cannot be established to a remote host on a specific po
  • Deque (java.util)
    A linear collection that supports element insertion and removal at both ends. The name deque is shor
  • Servlet (javax.servlet)
    Defines methods that all servlets must implement. A servlet is a small Java program that runs within
  • LogFactory (org.apache.commons.logging)
    Factory for creating Log instances, with discovery and configuration features similar to that employ
  • Join (org.hibernate.mapping)
  • Top plugins for Android Studio
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now