summaryrefslogtreecommitdiff
path: root/node_modules/dir-compare/src/fs/Queue.js
diff options
context:
space:
mode:
authorLinuxWizard42 <computerwizard@linuxmail.org>2022-10-12 22:54:37 +0300
committerLinuxWizard42 <computerwizard@linuxmail.org>2022-10-12 22:54:37 +0300
commit703e03aba33f234712206769f57717ba7d92d23d (patch)
tree0041f04ccb75bd5379c764e9fe42249fffe75fc3 /node_modules/dir-compare/src/fs/Queue.js
parentab6e257e6e9d9a483d7e86f220d8b209a2cd7753 (diff)
downloadFlashRunner-703e03aba33f234712206769f57717ba7d92d23d.tar.gz
FlashRunner-703e03aba33f234712206769f57717ba7d92d23d.tar.zst
Added export_allowed file to make repository visible in cgit
Diffstat (limited to 'node_modules/dir-compare/src/fs/Queue.js')
-rw-r--r--node_modules/dir-compare/src/fs/Queue.js63
1 files changed, 63 insertions, 0 deletions
diff --git a/node_modules/dir-compare/src/fs/Queue.js b/node_modules/dir-compare/src/fs/Queue.js
new file mode 100644
index 0000000..4d86dd5
--- /dev/null
+++ b/node_modules/dir-compare/src/fs/Queue.js
@@ -0,0 +1,63 @@
+/*
+
+Queue.js
+
+A function to represent a queue
+
+Created by Kate Morley - http://code.iamkate.com/ - and released under the terms
+of the CC0 1.0 Universal legal code:
+
+http://creativecommons.org/publicdomain/zero/1.0/legalcode
+
+*/
+
+var MAX_UNUSED_ARRAY_SIZE = 10000
+
+/* Creates a new queue. A queue is a first-in-first-out (FIFO) data structure -
+ * items are added to the end of the queue and removed from the front.
+ */
+function Queue() {
+
+ // initialise the queue and offset
+ var queue = []
+ var offset = 0
+
+ // Returns the length of the queue.
+ this.getLength = function () {
+ return (queue.length - offset)
+ }
+
+ /* Enqueues the specified item. The parameter is:
+ *
+ * item - the item to enqueue
+ */
+ this.enqueue = function (item) {
+ queue.push(item)
+ }
+
+ /* Dequeues an item and returns it. If the queue is empty, the value
+ * 'undefined' is returned.
+ */
+ this.dequeue = function () {
+
+ // if the queue is empty, return immediately
+ if (queue.length === 0) {
+ return undefined
+ }
+
+ // store the item at the front of the queue
+ var item = queue[offset]
+
+ // increment the offset and remove the free space if necessary
+ if (++offset > MAX_UNUSED_ARRAY_SIZE) {
+ queue = queue.slice(offset)
+ offset = 0
+ }
+
+ // return the dequeued item
+ return item
+
+ }
+}
+
+module.exports = Queue