Tabnine Logo
PriorityQueue
Code IndexAdd Tabnine to your IDE (free)

How to use
PriorityQueue
in
smile.sort

Best Java code snippets using smile.sort.PriorityQueue (Showing top 8 results out of 315)

origin: com.github.haifengl/smile-math

/**
 * fix up.
 */
private void swim(int k) {
  while (k > 1 && less(k, (k + d - 2) / d)) {
    swap(k, (k + d - 2) / d);
    k = (k + d - 2) / d;
  }
}
origin: com.github.haifengl/smile-math

/**
 * Removes and returns the index of item with minimum value (highest priority).
 */
public int poll() {
  swap(1, n);
  sink(1, n - 1);
  return pq[n--];
}
origin: com.github.haifengl/smile-math

  /**
   * The priority of item k has changed.
   */
  public void change(int k) {
    swim(qp[k]);
    sink(qp[k], n);
  }
}
origin: com.github.haifengl/smile-graph

@Override
public double[] dijkstra(int s) {
  double[] wt = new double[n];
  Arrays.fill(wt, Double.POSITIVE_INFINITY);
  PriorityQueue queue = new PriorityQueue(wt);
  for (int v = 0; v < n; v++) {
    queue.insert(v);
  }
  wt[s] = 0.0;
  queue.lower(s);
  while (!queue.empty()) {
    int v = queue.poll();
    if (!Double.isInfinite(wt[v])) {
      for (Edge edge : graph[v]) {
        int w = edge.v2;
        if (!digraph && w == v) {
          w = edge.v1;
        }
        
        double p = wt[v] + edge.weight;
        if (p < wt[w]) {
          wt[w] = p;
          queue.lower(w);
        }
      }
    }
  }
  
  return wt;
}
origin: com.github.haifengl/smile-math

/**
 * Insert a new item into queue.
 * @param v the index of item.
 */
public void insert(int v) {
  pq[++n] = v;
  qp[v] = n;
  swim(n);
}
origin: com.github.haifengl/smile-graph

Arrays.fill(wt, Double.POSITIVE_INFINITY);
PriorityQueue queue = new PriorityQueue(wt);
for (int v = 0; v < n; v++) {
  queue.insert(v);
queue.lower(s);
while (!queue.empty()) {
  int v = queue.poll();
  if (!Double.isInfinite(wt[v])) {
    for (int w = 0; w < n; w++) {
        if (p < wt[w]) {
          wt[w] = p;
          queue.lower(w);
origin: com.github.haifengl/smile-math

/**
 * The value of item k is lower (higher priority) now.
 */
public void lower(int k) {
  swim(qp[k]);
}
origin: com.github.haifengl/smile-math

/**
 * fix down.
 */
private void sink(int k, int N) {
  int j;
  while ((j = d * (k - 1) + 2) <= N) {
    for (int i = j + 1; i < j + d && i <= N; i++) {
      if (less(i, j)) {
        j = i;
      }
    }
    if (!(less(j, k))) {
      break;
    }
    swap(k, j);
    k = j;
  }
}
smile.sortPriorityQueue

Javadoc

Priority Queue for index items.

Most used methods

  • <init>
    Constructor. Default use a 3-heap.
  • empty
    Returns true if the queue is empty.
  • insert
    Insert a new item into queue.
  • less
    Priority comparison of item i and j.
  • lower
    The value of item k is lower (higher priority) now.
  • poll
    Removes and returns the index of item with minimum value (highest priority).
  • sink
    fix down.
  • swap
    Swap i and j items of pq and qp.
  • swim
    fix up.

Popular in Java

  • Finding current android device location
  • compareTo (BigDecimal)
  • setScale (BigDecimal)
  • putExtra (Intent)
  • FileNotFoundException (java.io)
    Thrown when a file specified by a program cannot be found.
  • InputStream (java.io)
    A readable source of bytes.Most clients will use input streams that read data from the file system (
  • UnknownHostException (java.net)
    Thrown when a hostname can not be resolved.
  • LinkedList (java.util)
    Doubly-linked list implementation of the List and Dequeinterfaces. Implements all optional list oper
  • Manifest (java.util.jar)
    The Manifest class is used to obtain attribute information for a JarFile and its entries.
  • JButton (javax.swing)
  • From CI to AI: The AI layer in your organization
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