Dive into secure and efficient coding practices with our curated list of the top 10 examples showcasing 'tinyqueue' in functional components in JavaScript. Our advanced machine learning engine meticulously scans each line of code, cross-referencing millions of open source libraries to ensure your implementation is not just functional, but also robust and secure. Elevate your React applications to new heights by mastering the art of handling side effects, API calls, and asynchronous operations with confidence and precision.
public async continue(maxCost: number): Promise {
const queue = new TinyQueue(this.nextQueue, (a, b) => a.duration - b.duration);
this.nextQueue = [];
while (queue.length) {
const { position, distance, duration, cost } = queue.pop();
if (duration > this.getCost(position)) {
// we have already found a better way
continue;
}
if (this.graph.getBreakPoint(position)) {
await this.graph.getBreakPoint(position)(this.graph.getLabel(position));
}
if (cost > maxCost) {
// remember this state for subsequent calls
export function intervalScheduling(blocks: ScheduleBlock[], assignment: Int16Array) {
if (blocks.length === 0) return 0;
blocks.sort((b1, b2) => b1.startMin - b2.startMin); // sort by start time
// min heap, the top element is the room whose end time is minimal
// a room is represented as a pair: [end time, room index]
const queue = new PriorityQueue(
[[blocks[0].endMin, 0]],
(r1, r2) => r1[0] - r2[0]
);
let numRooms = 0;
assignment[0] = 0;
for (let i = 1; i < blocks.length; i++) {
const { startMin, endMin } = blocks[i];
const [earliestEnd, roomIdx] = queue.peek()!;
if (earliestEnd > startMin) {
// conflict, need to add a new room
numRooms += 1;
queue.push([endMin, numRooms]);
assignment[i] = numRooms;
} else {
queue.pop(); // update the room end time
queue.push([endMin, roomIdx]);
export default function bentleyOttmann (geojson) {
const intersectionPoints = []
const eventQueue = new TinyQueue([], checkWhichEventIsLeft);
fillEventQueue(geojson, eventQueue)
const outQueue = new TinyQueue([], checkWhichSegmentHasRightEndpointFirst);
while (eventQueue.length) {
const event = eventQueue.pop();
if (event.isLeftEndpoint) {
// debugEventAndSegments(event.p, outQueue.data)
const segment = new Segment(event)
for (let i = 0; i < outQueue.data.length; i++) {
const intersection = testSegmentIntersect(segment, outQueue.data[i])
if (intersection !== false) intersectionPoints.push(intersection)
}
outQueue.push(segment)
} else if (event.isLeftEndpoint === false) {
const seg = outQueue.pop()
// debugRemovingSegment(event.p, seg)
}
}
constructor({ threads }) {
// TODO: Consider not running items with zero priority
// Priority is a function so that items can change their priority between
// when their priority is evaluated.
// For example, we might add a track to the playlist and then scroll to/away
// from it before it gets processed.
this._queue = new TinyQueue([], (a, b) => a.priority() - b.priority());
this._availableThreads = threads;
}
export const getModel = ({
data,
renderer,
inheritMainColor = true,
mergeThreshold
}) => {
let result = {
observables: [],
connectors: []
};
if (!isObservable(data)) {
return result;
}
let queue = new TinyQueue(
[
{
observable: data,
startTime: 0,
mainColor: defaultMainColor
}
],
(obs1, obs2) => obs1.startTime - obs2.startTime
);
while (queue.length > 0) {
const { observable, startTime, mainColor, fromIndex } = queue.pop();
const observableIndex = result.observables.length;
if (!isUndefined(fromIndex)) {
result.connectors.push({
public async queryPath(from: string, to: string, maxDistance = Infinity) {
let queue: TinyQueue;
if (this.useWeightedCost) {
queue = new TinyQueue([], (a, b) => a[COST] - b[COST]);
} else {
queue = new TinyQueue([], (a, b) => a[DURATION] - b[DURATION]);
}
this.costs = this.costs.fill(Infinity);
this.previousNodes = this.previousNodes.fill(undefined);
const fromIndex = this.graph.getNodeIndex(from);
this.setCost(fromIndex, 0);
const state = new Float32Array(4);
state[COST] = 0;
state[POSITION] = fromIndex;
state[DISTANCE] = 0;
state[DURATION] = 0;
queue.push(state);
constructor(asyncIterator: AsyncIterator) {
this.closed = false;
this.asyncIterator = asyncIterator;
this.queue = new TinyQueue([], (a, b) => {
return a.departureTime - b.departureTime;
});
}
public async queryPath(from: string, to: string, maxDistance = Infinity) {
let forwardQueue: TinyQueue;
let backwardQueue: TinyQueue;
if (this.useWeightedCost) {
forwardQueue = new TinyQueue([], (a, b) => a.cost - b.cost);
backwardQueue = new TinyQueue([], (a, b) => a.cost - b.cost);
} else {
forwardQueue = new TinyQueue([], (a, b) => a.duration - b.duration);
backwardQueue = new TinyQueue([], (a, b) => a.duration - b.duration);
}
this.forwardCosts = this.forwardCosts.fill(Infinity);
this.forwardParents = this.forwardParents.fill(undefined);
this.backwardCosts = this.backwardCosts.fill(Infinity);
this.backwardParents = this.backwardParents.fill(undefined);
const fromIndex = this.graph.getNodeIndex(from);
const toIndex = this.graph.getNodeIndex(to);
this.setForwardCost(fromIndex, 0);
this.setBackwardCost(toIndex, 0);
forwardQueue.push({ distance: 0, duration: 0, cost: 0, position: fromIndex });
backwardQueue.push({ distance: 0, duration: 0, cost: 0, position: toIndex });
while (forwardQueue.length && backwardQueue.length) {
const [forwardResult, backwardResult] = await Promise.all([
public async queryPath(from: string, to: string, maxDistance = Infinity) {
let forwardQueue: TinyQueue;
let backwardQueue: TinyQueue;
if (this.useWeightedCost) {
forwardQueue = new TinyQueue([], (a, b) => a.cost - b.cost);
backwardQueue = new TinyQueue([], (a, b) => a.cost - b.cost);
} else {
forwardQueue = new TinyQueue([], (a, b) => a.duration - b.duration);
backwardQueue = new TinyQueue([], (a, b) => a.duration - b.duration);
}
this.forwardCosts = this.forwardCosts.fill(Infinity);
this.forwardParents = this.forwardParents.fill(undefined);
this.backwardCosts = this.backwardCosts.fill(Infinity);
this.backwardParents = this.backwardParents.fill(undefined);
const fromIndex = this.graph.getNodeIndex(from);
const toIndex = this.graph.getNodeIndex(to);
this.setForwardCost(fromIndex, 0);
this.setBackwardCost(toIndex, 0);
forwardQueue.push({ distance: 0, duration: 0, cost: 0, position: fromIndex });