{"name":"yocto-queue","version":"1.0.0","keywords":["queue","data","structure","algorithm","queues","queuing","list","array","linkedlist","fifo","enqueue","dequeue","data-structure"],"author":{"url":"https://sindresorhus.com","name":"Sindre Sorhus","email":"sindresorhus@gmail.com"},"license":"MIT","_id":"yocto-queue@1.0.0","homepage":"https://github.com/sindresorhus/yocto-queue#readme","bugs":{"url":"https://github.com/sindresorhus/yocto-queue/issues"},"dist":{"shasum":"7f816433fb2cbc511ec8bf7d263c3b58a1a3c251","tarball":"http://registry-npm.ywwl.com/yocto-queue/download/yocto-queue-1.0.0.tgz","fileCount":5,"integrity":"sha512-9bnSc/HEW2uRy67wc+T8UwauLuPJVn28jb+GtJY16iiKWyvmYJRXVT4UamsAEGQfPohgr2q4Tq0sQbQlxTfi1g==","signatures":[{"sig":"MEUCIQCgpquEkkrOvziIIdkPS60Zmbl1a3cy9CW+fyss6yD+gQIgex85tTH7ZLeMp/djFhHgZ7e9HvigzwOiEE7hUPg+4rI=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":6409,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJhFbNRCRA9TVsSAnZWagAAyWcQAKEhMtwhQLcTexqOYTrf\np094W6yti0MY6bltGszSDhfoXBVgMBlou8YSk/s7EF/Fbl6356tMK6OClWWf\nvU2kaUWeSdlngv+S5baQ7fk9liA29jIGOHKXgt4h6XFzSfLA9b5hVbmQ0QBR\n37Fj96bt0756N7N/8J2lXREiPvOwkZ7QMhv5l1W8WV11j2QWn5Z64vCehbXJ\ns4M7leEOBA3/+HZYSdgBhK9Xm42+TJP3VtiyXZMnz+evPlydAvt1DmwPDbIx\nVU68PvQIA0/+RgtjiRD6rAX3LD2CG4g2YmdjBXYgq+xlTW76EM11aZbqCkkI\nfv/qevquZsYOn2JWwYHd2dRs7/xTm+AcLV2sdV0hS/bVeQx4AqBWwyA9uk2E\nOiYZ9KcfkQxMNae7+1Bw6bPL5dwpO5vim6OZ7+Wo7Qa83Bk/piK4r9cAZuOK\nYq4F0yxntA6+rHMSQ4EYluiN+mrqVqn2um7WvAO857YRSuOQf6cBt+zfEq3N\nnR3Iqm6V108sjxv79y3U1REAV7l2YZGGQH3BsM+XjVmjqmvlTxWDm/Uyhlzj\nMhw13HW32uWvkY8bIN5iEYKuaT5eDltFSVN83WFv0+kOV1hmvm2b8u4ZDFCS\n6n8rREm+yYSpgaLXf+VA/cTzqPmkOqp8qwwfk6DbJDNhATWdDt4h4TazXUrX\npIJG\r\n=Vcs5\r\n-----END PGP SIGNATURE-----\r\n","size":2915,"noattachment":false,"key":"/yocto-queue/-/yocto-queue-1.0.0.tgz"},"type":"module","engines":{"node":">=12.20"},"exports":"./index.js","funding":"https://github.com/sponsors/sindresorhus","gitHead":"2e57f8c95e5e1f40379c6f85d18aee962662eb22","scripts":{"test":"ava && tsd","//test":"xo && ava && tsd"},"_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"repository":{"url":"git+https://github.com/sindresorhus/yocto-queue.git","type":"git"},"_npmVersion":"7.10.0","description":"Tiny queue data structure","directories":{},"_nodeVersion":"12.22.1","_hasShrinkwrap":false,"devDependencies":{"xo":"^0.44.0","ava":"^3.15.0","tsd":"^0.17.0"},"_npmOperationalInternal":{"tmp":"tmp/yocto-queue_1.0.0_1628812112939_0.12892570466581454","host":"s3://npm-registry-packages"},"readme":"# yocto-queue [![](https://badgen.net/bundlephobia/minzip/yocto-queue)](https://bundlephobia.com/result?p=yocto-queue)\n\n> Tiny queue data structure\n\nYou should use this package instead of an array if you do a lot of `Array#push()` and `Array#shift()` on large arrays, since `Array#shift()` has [linear time complexity](https://medium.com/@ariel.salem1989/an-easy-to-use-guide-to-big-o-time-complexity-5dcf4be8a444#:~:text=O(N)%E2%80%94Linear%20Time) *O(n)* while `Queue#dequeue()` has [constant time complexity](https://medium.com/@ariel.salem1989/an-easy-to-use-guide-to-big-o-time-complexity-5dcf4be8a444#:~:text=O(1)%20%E2%80%94%20Constant%20Time) *O(1)*. That makes a huge difference for large arrays.\n\n> A [queue](https://en.wikipedia.org/wiki/Queue_(abstract_data_type)) is an ordered list of elements where an element is inserted at the end of the queue and is removed from the front of the queue. A queue works based on the first-in, first-out ([FIFO](https://en.wikipedia.org/wiki/FIFO_(computing_and_electronics))) principle.\n\n## Install\n\n```sh\nnpm install yocto-queue\n```\n\n## Usage\n\n```js\nimport Queue from 'yocto-queue';\n\nconst queue = new Queue();\n\nqueue.enqueue('🦄');\nqueue.enqueue('🌈');\n\nconsole.log(queue.size);\n//=> 2\n\nconsole.log(...queue);\n//=> '🦄 🌈'\n\nconsole.log(queue.dequeue());\n//=> '🦄'\n\nconsole.log(queue.dequeue());\n//=> '🌈'\n```\n\n## API\n\n### `queue = new Queue()`\n\nThe instance is an [`Iterable`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols), which means you can iterate over the queue front to back with a “for…of” loop, or use spreading to convert the queue to an array. Don't do this unless you really need to though, since it's slow.\n\n#### `.enqueue(value)`\n\nAdd a value to the queue.\n\n#### `.dequeue()`\n\nRemove the next value in the queue.\n\nReturns the removed value or `undefined` if the queue is empty.\n\n#### `.peek()`\n\nGet the next value in the queue without removing it.\n\nReturns the value or `undefined` if the queue is empty.\n\n#### `.clear()`\n\nClear the queue.\n\n#### `.size`\n\nThe size of the queue.\n\n## Related\n\n- [quick-lru](https://github.com/sindresorhus/quick-lru) - Simple “Least Recently Used” (LRU) cache\n","publish_time":1628812113113,"maintainers":[{"name":"sindresorhus","email":"sindresorhus@gmail.com"}],"_cnpm_publish_time":1628812113113,"dist-tags":{"latest":"1.2.2"}}