Options
All
  • Public
  • Public/Protected
  • All
Menu

Module src/core/queue/order

core/queue/order

This module provides a class to organize an ordered Queue data structure. See core/queue for more information.

Usage

import OrderedQueue from 'core/queue/order';

const
queue = new OrderedQueue<number>((a, b) => a - b);

queue.push(1);
queue.push(5);
queue.push(2);
queue.push(-1);
queue.push(5);
queue.push(2);
queue.push(-1);
queue.push(5);

console.log(queue.length); // 8

console.log(queue.head); // 5
console.log(queue.pop()); // 5

console.log(queue.head); // 5
console.log(queue.pop()); // 5

console.log(queue.pop()); // 5
console.log(queue.pop()); // 2
console.log(queue.pop()); // 2

queue.clear();
console.log(queue.length); // 0

Providing a comparator

To compare different elements from the queue, a special comparator function is used, which has the same API as the native comparator Array.prototype.sort. To provide a comparator, use the structure constructor.

import OrderedQueue from 'core/queue/order';

const
queue = new OrderedQueue<number>((a, b) => a - b);

queue.push(1);
queue.push(5);

Index

References

Re-exports CreateInnerQueue
Re-exports ElsComparator
Re-exports InnerQueue
Re-exports QueueOptions