yocto-queue
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|
Yocto-queue is a tiny queue data structure developed for JavaScript programming. It should be used instead of an array for operations that involve a lot of Array#push()
and Array#shift()
on large arrays. This is due to the fact that while Array#shift()
has linear time complexity O(n), the Queue#dequeue()
function in yocto-queue has constant time complexity O(1). This results in huge efficiency advantages, especially for large arrays. A queue, as the name suggests, is an ordered list of elements where an element is inserted at the end (enqueued) and is removed from the front (dequeued) based on a first-in, first-out principle (FIFO). This tiny data structure is incredibly beneficial in optimizing performance when managing large data in your applications.
To use yocto-queue in your JavaScript project, first, you need to install it using npm by npm install yocto-queue
command. Here is a simple usage example in JavaScript:
import Queue from 'yocto-queue';
const queue = new Queue();
queue.enqueue('π¦');
queue.enqueue('π');
console.log(queue.size); // Outputs: 2
console.log(...queue); // Outputs: 'π¦ π'
console.log(queue.dequeue()); // Outputs: 'π¦'
console.log(queue.dequeue()); // Outputs: 'π'
In the above example, two elements are enqueued to the queue instance. The size of the queue and the elements in it are printed to the console. After that, the two elements are dequeued one-by-one.
The documentation for yocto-queue can be found within the README in the package's GitHub repository. The API section of the README provides details on the usage of the data structure's methods such as .enqueue(value)
, .dequeue()
, .clear()
, and .size
. The repository also includes related resources and packages which are useful for developers working on similar tasks.