82 lines
2.0 KiB
C
82 lines
2.0 KiB
C
#ifndef BLUE_CORE_QUEUE_H_
|
|
#define BLUE_CORE_QUEUE_H_
|
|
|
|
#include <blue/core/iterator.h>
|
|
#include <blue/core/macros.h>
|
|
#include <blue/core/status.h>
|
|
#include <stdbool.h>
|
|
#include <string.h>
|
|
|
|
B_DECLS_BEGIN;
|
|
|
|
#define B_TYPE_QUEUE_ITERATOR (b_queue_iterator_get_type())
|
|
|
|
B_DECLARE_TYPE(b_queue_iterator);
|
|
|
|
B_TYPE_CLASS_DECLARATION_BEGIN(b_queue_iterator)
|
|
B_TYPE_CLASS_DECLARATION_END(b_queue_iterator)
|
|
|
|
#define B_QUEUE_INIT ((b_queue) {.q_first = NULL, .q_last = NULL})
|
|
#define B_QUEUE_ENTRY_INIT ((b_queue_entry) {.qe_next = NULL, .qe_prev = NULL})
|
|
|
|
typedef struct b_queue_entry {
|
|
struct b_queue_entry *qe_next;
|
|
struct b_queue_entry *qe_prev;
|
|
} b_queue_entry;
|
|
|
|
typedef struct b_queue {
|
|
b_queue_entry *q_first;
|
|
b_queue_entry *q_last;
|
|
} b_queue;
|
|
|
|
static inline void b_queue_init(b_queue *q)
|
|
{
|
|
memset(q, 0x00, sizeof *q);
|
|
}
|
|
static inline bool b_queue_empty(const b_queue *q)
|
|
{
|
|
return q->q_first == NULL;
|
|
}
|
|
|
|
static inline b_queue_entry *b_queue_first(const b_queue *q)
|
|
{
|
|
return q->q_first;
|
|
}
|
|
static inline b_queue_entry *b_queue_last(const b_queue *q)
|
|
{
|
|
return q->q_last;
|
|
}
|
|
static inline b_queue_entry *b_queue_next(const b_queue_entry *entry)
|
|
{
|
|
return entry->qe_next;
|
|
}
|
|
static inline b_queue_entry *b_queue_prev(const b_queue_entry *entry)
|
|
{
|
|
return entry->qe_prev;
|
|
}
|
|
|
|
BLUE_API b_type b_queue_iterator_get_type(void);
|
|
|
|
BLUE_API size_t b_queue_length(const b_queue *q);
|
|
|
|
BLUE_API void b_queue_insert_before(
|
|
b_queue *q, b_queue_entry *entry, b_queue_entry *before);
|
|
BLUE_API void b_queue_insert_after(
|
|
b_queue *q, b_queue_entry *entry, b_queue_entry *after);
|
|
|
|
BLUE_API void b_queue_push_front(b_queue *q, b_queue_entry *entry);
|
|
BLUE_API void b_queue_push_back(b_queue *q, b_queue_entry *entry);
|
|
|
|
BLUE_API b_queue_entry *b_queue_pop_front(b_queue *q);
|
|
BLUE_API b_queue_entry *b_queue_pop_back(b_queue *q);
|
|
|
|
BLUE_API void b_queue_delete(b_queue *q, b_queue_entry *entry);
|
|
BLUE_API void b_queue_delete_all(b_queue *q);
|
|
|
|
BLUE_API b_iterator *b_queue_begin(b_queue *q);
|
|
BLUE_API b_iterator *b_queue_cbegin(const b_queue *q);
|
|
|
|
B_DECLS_END;
|
|
|
|
#endif
|