Skip to content

Queue

Useful queue implementations

I needed to use queues while developing some libraries and i was like why dont i make this and put it in github.

In current version (2.0.0) it only features FIFO and priority max and a queue implementation.

Type Enqueue Complexity Dequeue Complexity Space Complexity
FIFO Queue O(1) O(1) O(n)
Priority Max O(log n) O(log n) O(n)

Check out time complexities: Desmos Time Complexities

To install this to your computer you have this options;

  1. Clone this repository by running following command
    Terminal window
    git clone https://github.com/Cod2rDude/queues
  2. Get the latest release of .rbxm file from releases
  3. Or add this as a submodule to your project
    Terminal window
    git submodule add https://github.com/Cod2rDude/queues [PATH]

Wally will be added in future (I hope).

local queues = require(path.to.module)
local size = 10 -- 2 <= size <= 1024
local myFifoQueue = queues.fifo.new(size)
-- enqueing first item
myFifoQueue:enqueue(5)
-- enqueing second item
myFifoQueue:enqueue(6)
-- dequeing will return 5 since we added 5 first
print(myFifoQueue:dequeue()) -- 5
-- dequeueing again will return 6 because we added 6 after 5
print(myFifoQueue:dequeue())
local queues = require(path.to.module)
local size = 10 -- 2 <= size <= 1024
local myPriorityQueue = queues.priorityMax.new(size)
-- object, priority
myPriorityQueue:enqueue("low", 1)
myPriorityQueue:enqueue("high", 100)
myPriorityQueue:enqueue("mid", 50)
print(myPriorityQueue:dequeue()) -- high
print(myPriorityQueue:dequeue()) -- mid
print(myPriorityQueue:dequeue()) -- low

Please check out source code for further info about api. (Sorry!)

(I plan to make a project to autoconvert it to a documentation automatically.)

  • Add a consumer loop function to both queues.
  • Add a way to search for a specific item in both queues.
  • Let user remove a specific item (either an index or order or just an object) in both queues.
  • Add raw iteration to both queues.

If you encounter any issues or unexpected behavior, please let me know! Your feedback helps make this library more stable.

  1. Check the existing issues to see if it has already been reported.
  2. If not, open a new issue and describe the problem.
  3. Provide a small code snippet to reproduce the bug if possible.

Contributions are what make the open-source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.

To maintain the stability of the library, direct commits to the main branch are restricted. Please follow the workflow below to suggest changes:

  1. Fork the Project: Create your own copy of this repository.
  2. Create a Feature Branch:
    Terminal window
    git checkout -b feature/AmazingFeature
  3. Commit your changes:
    Terminal window
    git commit -m 'Add some AmazingFeature'
  4. Push to branch:
    Terminal window
    git push origin feature/AmazingFeature
  5. Open a Pull Request: Navigate to the original repository and click “New Pull Request”. Describe your changes in detail so they can be reviewed.

Once your Pull Request is merged, GitHub will automatically list you in the official “Contributors” section of the repository. (i guess so)

After a successful merge, I will also manually add your name and contribution to the table below!

We appreciate contributions you will make but we will also highly appreciate you to follow our guidelines while contributing.

  1. Of course make sure your code is efficient.
  2. No nsfw links, swearing or anything like those.
  3. Maybe follow the coding style we do.
  4. That’s it!

Contributors

Contributor Description
Cod2rDude Creator
scrpt2r Helped on __log__

This project is licensed under The MIT License