Coder Social home page Coder Social logo

queue's Introduction

Queue
- thread-safe
- ability to define max number of elements
- sort elements into queue
- get in O(1), except when filtered (worst case O(n))
- put in O(1) when unsorted, in O(n) in the worst case when sorted
- MIT license (windows support relies on LGPL licensed pthreads-win32 (http://sourceware.org/pthreads-win32/))

sorted queue:
  your elements in the queue will be ordered according to the sort function which is given.

Build steps:
- mkdir build && cd build
- cmake ..
- make / build VS project under windows

Building 32-/64-bit:
- OS X: universal binaries are built
- Linux: use 'cmake -DBUILT_32=ON ..' to force 32-bit built, -DBUILT_64=ON for 64-bit
- Windows: use 'cmake -G "Visual Studio 11 Win64" -DBUILT_64=ON ..' to force a 64-bit build, 'cmake -G "Visual Studio 11" -DBUILT_32=ON ..' for 32-bit

TODO:
- proper test suite, so that everybody can easily see whats tested and run the tests himself
- ability to turn of element counting => only unlimited queue
- function to peek at next element

error codes:
 < 0 => error
 = 0 => okay

 0 - everything alright

-1 - invalid queue
-2 - could not acquire lock
-3 - could not allocate memory
-4 - no new data allowed
-5 - invalid element in queue
-6 - invalid callback
-7 - max_elements reached or no elements in queue

queue's People

Contributors

tobithiel avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

queue's Issues

queue_get returns incorrect value when no elements in queue

according to the doc , if you call queue_get on a queue with no elements, it should return > 0.

/**
 * get the first element of the queue
 *
 * q - the queue
 * e - pointer which will be set to the element
 *
 * returns 0 if everything worked, > 0 if no elements in queue, < 0 if error occured
 */
int8_t queue_get(queue_t *q, void **e);

It currently returns Q_ERR_NUM_ELEMENTS (-7) instead.

int8_t queue_get(queue_t *q, void **e) {
    *e = NULL;
    if (q == NULL)
        return Q_ERR_INVALID;
    if (0 != queue_lock_internal(q))
        return Q_ERR_LOCK;

    int8_t r = queue_get_internal(q, e, NULL, NULL, NULL);

    if (0 != queue_unlock_internal(q))
        return Q_ERR_LOCK;
    return r;
}

queue_get calls queue_get_internal which sets this here

int8_t queue_get_internal(queue_t *q, void **e, int (*action)(pthread_cond_t *, pthread_mutex_t *),
                          int (*cmp)(void *, void *), void *cmpel) {
    if (q == NULL) { // queue not valid
        *e = NULL;
        return Q_ERR_INVALID;
    }

    // are elements in the queue?
    if (q->num_els == 0) {
        if (action == NULL) {
            *e = NULL;
            return Q_ERR_NUM_ELEMENTS;  <------------- here
        } else {

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.