GithubHelp home page GithubHelp logo

cnc4less / arduinoqueue Goto Github PK

View Code? Open in Web Editor NEW

This project forked from einararnason/arduinoqueue

0.0 0.0 0.0 58 KB

A lightweight linked list type queue implementation, meant for microcontrollers.

License: MIT License

C++ 82.92% CMake 17.08%

arduinoqueue's Introduction

ArduinoQueue

Build Status

A lightweight linked list type queue implementation, meant for microcontrollers. Written as a C++ template class.

Constructors

Creates a queue up to <maximum_number_of_items> items:

ArduinoQueue<T> intQueue(maximum_number_of_items);

Creates a queue up to <maximum_size_in_bytes> bytes:

ArduinoQueue<T> intQueue(0, maximum_size_in_bytes);

Creates a queue up to <maximum_number_of_items> items or <maximum_size_in_bytes> bytes, whatever comes first:

ArduinoQueue<T> intQueue(maximum_number_of_items, maximum_size_in_bytes);

How to use

Include the header file on your code:

#include <ArduinoQueue.h>

Then create the queue according to your needs, examples:

  • To create a queue of int, capable of holding 20 items:
ArduinoQueue<int> intQueue(20);
  • To create a queue of int, capable of holding 20 items or a maximum size of 10 bytes (whatever comes first):
ArduinoQueue<int> intQueue(20, 10);
  • To create a queue of your defined structure, capable of holding 50 items:
struct car {
    char brand[10];
    char model[10];
    int nr_doors;
};
ArduinoQueue<car> myCarsQueue(50);

Finally use the following functions:

intQueue.enqueue(1);    // Adds number 1 to the queue
intQueue.enqueue(123);    // Adds number 123 to the queue
int number = intQueue.dequeue();    // Will return number 1 and remove it from the queue
int number = intQueue.getHead();    // Will return number 123 but leave it still in the queue
int number = intQueue.dequeue();    // Will return number 123 and remove it from the queue

You can use also the following functions to get more queue properties:

bool state = intQueue.isEmpty();    // Returns true if the queue is empty, false otherwise
bool state = intQueue.isFull();    // Returns true if the queue is full, false otherwise
unsigned int n = intQueue.itemCount();    // Returns the number of items currently on the queue
unsigned int n = intQueue.itemSize();    // Returns the size of the item being stored (bytes)
unsigned int n = intQueue.maxQueueSize();    // Returns the maximum possible size of the queue (items)*
unsigned int n = intQueue.maxMemorySize();    // Returns the maximum possible size of the queue (bytes)*

Thread safety

This library is not thread safe. Mutexes are often hardware specific on the way they are optimized to operate. So for the sake of performance and portability, it is left out.

Memory safety

The memory for the queue nodes are dynamically allocated. Note that while the Queue class cleans up the nodes in memory after destructor or dequeue is called, it keeps a copy of the item being queued. So for example if you are queuing pointers, you will need to keep track of the memory behind them.

Performance

CPU: Intel i7-6500U
RAM: DDR4L

Benchmark result (1000 samples):
Enqueued 1000000 ints in average 0.018749799 seconds
Dequeued 1000000 ints in average 0.016496857 seconds
Allocated 15.2588 MB (16 bytes per item)

arduinoqueue's People

Contributors

einararnason avatar guysoft avatar vascojdb avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.