How to use fastpriorityqueue - 9 common examples

To help you get started, we’ve selected a few fastpriorityqueue examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github devalpha-io / devalpha-node / lib / util / streams.ts View on Github external
export function createSortedStream(feeds) {
  const streams = createStreams(feeds)
  // eslint-disable-next-line no-unused-vars
  const heap = new Heap(([k1, v1], [k2, v2]) => {
    if (typeof v2.timestamp === 'undefined') {
      if (typeof v1.timestamp === 'undefined') {
        return false
      }
      return true
    }

    if (typeof v1.timestamp === 'undefined') {
      return false
    }

    return v1.timestamp < v2.timestamp
  })

  Object.keys(streams).forEach((key) => {
    const stream = streams[key]
github higlass / higlass / app / scripts / factories / AreaCluster.js View on Github external
this.id = rndHex();
  this.isAverageCenter = isAverageCenter;
  this.cX = null;
  this.cY = null;
  this.members = new KeySet('id');
  this.isChanged = false;

  this.minX = Infinity;
  this.maxX = 0;
  this.minY = Infinity;
  this.maxY = 0;
  // Manhatten diameter
  this.diameter = 0;

  // Farthest nearest neighbors
  this.fnns = new FastPriorityQueue((a, b) => a.d > b.d);

  // Usually this is the grid size of the clusterer
  this.padding = padding;

  this.isRemoved = false;
  this.isDisconnected = false;
}
github ChainSafe / lodestar / packages / lodestar / src / chain / chain.ts View on Github external
super();
    this.opts = opts;
    this.chain = opts.name;
    this.config = config;
    this.db = db;
    this.eth1 = eth1;
    this.opPool = opPool;
    this.logger = logger;
    this.metrics = metrics;
    this.forkChoice = new StatefulDagLMDGHOST();
    this.chainId = 0; // TODO make this real
    this.networkId = new BN(0); // TODO make this real
    this.attestationProcessingQueue = queue(async (task: Function) => {
      await task();
    }, 1);
    this.blockProcessingQueue = new FastPriorityQueue((a: BeaconBlock, b: BeaconBlock) => {
      return a.slot < b.slot;
    });
  }
github josephroquedev / campus-guide / src / util / graph / Navigation.ts View on Github external
export function getBestPathAcross(
    startToExits: Map,
    exitsToTarget: Map,
    distancesBetweenExits: Map>,
    graphs: Map,
    accessible: boolean,
    shortest: boolean): Path | undefined {
  const doorPairings = new FastPriorityQueue(doorPairingComparator);

  for (const exit of startToExits.keys()) {
    for (const entrance of exitsToTarget.keys()) {
      // TODO: adjust path distances inside buildings to give less weight than those outside
      const exitPath = startToExits.get(exit);
      const entrancePath = exitsToTarget.get(entrance);
      if (exitPath == undefined || entrancePath == undefined) {
        // Path could not be found between the start and door, possibly because it's closed,
        // possibly because the user wants it to be accessible
        continue;
      }

      let distance = 0;
      if (shortest) {
        distance = exitPath.distance * INNER_UNIT_TO_M;
        distance += entrancePath.distance * INNER_UNIT_TO_M;
github ChainSafe / lodestar / packages / lodestar / src / chain / chain.ts View on Github external
super();
    this.opts = opts;
    this.chain = opts.name;
    this.config = config;
    this.db = db;
    this.eth1 = eth1;
    this.opPool = opPool;
    this.logger = logger;
    this.metrics = metrics;
    this.forkChoice = new StatefulDagLMDGHOST();
    this.chainId = 0; // TODO make this real
    this.networkId = 0n; // TODO make this real
    this.attestationProcessingQueue = queue(async (task: Function) => {
      await task();
    }, 1);
    this.blockProcessingQueue = new FastPriorityQueue((a: IBlockProcessJob, b: IBlockProcessJob) => {
      return a.block.slot < b.block.slot;
    });
  }
github erikbrinkman / d3-dag / src / sugiyama / layering / coffmanGraham.js View on Github external
function layeringCoffmanGraham(dag) {
    maxWidth =
      maxWidth || Math.floor(Math.sqrt(dag.reduce((a) => a + 1, 0)) + 0.5);

    // Initialize node data
    dag
      .each((node) => {
        node._before = [];
        node._parents = [];
      })
      .each((n) => n.children.forEach((c) => c._parents.push(n)));

    // Create queue
    const queue = FastPriorityQueue((a, b) => {
      for (let j = 0; j < a._before.length; ++j) {
        if (j >= b._before.length) {
          return false;
        } else if (a._before[j] < b._before[j]) {
          return true;
        } else if (b._before[j] < a._before[j]) {
          return false;
        }
      }
      return true;
    });

    // Start with root nodes
    dag.roots().forEach((n) => queue.add(n));
    let i = 0;
    let layer = 0;
github devalpha-io / devalpha-node / dist / util / streams.js View on Github external
function createSortedStream(feeds) {
    const streams = createStreams(feeds);
    // eslint-disable-next-line no-unused-vars
    const heap = new fastpriorityqueue_ts_1.FastPriorityQueue((t1, t2) => {
        if (typeof t1 === 'undefined') {
            if (typeof t2 === 'undefined') {
                return false;
            }
            return true;
        }
        if (typeof t1 === 'undefined') {
            return false;
        }
        return t1 < t2;
    });
    Object.keys(streams).forEach((type) => {
        const stream = streams[type];
        stream.pull((err, item) => {
            if (!err && item) {
                heap.add({
github josephroquedev / campus-guide / src / util / graph / Navigation.ts View on Github external
export function findShortestPathsBetween(
    startNode: Node,
    targetNodes: Set,
    graph: Graph,
    accessible: boolean,
    reverse: boolean): Map {
  const paths: Map = new Map();
  const targetsFound: Set = new Set();

  const nodes = new FastPriorityQueue(partialPathComparator);
  const distances: Map = new Map();
  const previous: Map = new Map();

  for (const node of graph.adjacencies.keys()) {
    if (node === startNode) {
      distances.set(node, 0);
      nodes.add({ dist: 0, node });
    } else {
      distances.set(node, Infinity);
      nodes.add({ dist: Infinity, node });
    }
  }

  const firstTargetNode = targetNodes.values().next().value;

  if (startNode.getType() === NodeType.Door && firstTargetNode.getBuilding() === startNode.getBuilding()) {
github tilk / digitaljs / src / circuit.js View on Github external
constructor(data) {
        this._queue = new Map();
        this._pq = new FastPriorityQueue();
        this._tick = 0;
        this._graph = this.makeGraph(data, data.subcircuits);
    }
    shutdown() {

fastpriorityqueue

Fast heap-based priority queue in JavaScript

Apache-2.0
Latest version published 9 months ago

Package Health Score

66 / 100
Full package analysis