Codota Logo
PriorityQueue
Code IndexAdd Codota 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)

  • Add the Codota plugin to your IDE and get smart completions
private void myMethod () {
Connection c =
  • Codota IconDataSource dataSource;dataSource.getConnection()
  • Codota IconString url;DriverManager.getConnection(url)
  • Codota IconIdentityDatabaseUtil.getDBConnection()
  • Smart code suggestions by Codota
}
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

  • Start an intent from android
  • setRequestProperty (URLConnection)
  • getApplicationContext (Context)
  • notifyDataSetChanged (ArrayAdapter)
  • ObjectMapper (com.fasterxml.jackson.databind)
    This mapper (or, data binder, or codec) provides functionality for converting between Java objects (
  • URLConnection (java.net)
    The abstract class URLConnection is the superclass of all classes that represent a communications li
  • BitSet (java.util)
    This class implements a vector of bits that grows as needed. Each component of the bit set has a boo
  • LinkedHashMap (java.util)
    Hash table and linked list implementation of the Map interface, with predictable iteration order. Th
  • Base64 (org.apache.commons.codec.binary)
    Provides Base64 encoding and decoding as defined by RFC 2045.This class implements section 6.8. Base
  • Table (org.hibernate.mapping)
    A relational table
Codota Logo
  • Products

    Search for Java codeSearch for JavaScript codeEnterprise
  • IDE Plugins

    IntelliJ IDEAWebStormAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogCodota Academy Plugin user guide Terms of usePrivacy policyJava Code IndexJavascript Code Index
Get Codota for your IDE now