50 lines
1.9 KiB
C
50 lines
1.9 KiB
C
/*
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*
|
|
* -----------------------------------------------------------------------------
|
|
* File: Queue.h
|
|
* Description:
|
|
* This file contains the Queue structure and the functions for modifying it.
|
|
* It includes functions to Push, Pop, Peek and check if empty.
|
|
*
|
|
* Author: Mineplay
|
|
* -----------------------------------------------------------------------------
|
|
*/
|
|
#ifndef FLEDASTY_QUEUE
|
|
#define FLEDASTY_QUEUE
|
|
|
|
#include <stddef.h>
|
|
#include <stdbool.h>
|
|
|
|
#include "../Utils/Error.h"
|
|
|
|
typedef struct {
|
|
size_t size, capacity;
|
|
size_t head, tail;
|
|
|
|
size_t element_byte_size;
|
|
unsigned char *buffer;
|
|
} FledastyQueue;
|
|
|
|
FledastyError fledasty_queue_initialize(FledastyQueue *new_queue, void *values, const size_t values_size, const size_t element_byte_size);
|
|
FledastyError fledasty_queue_destroy(FledastyQueue *current_queue);
|
|
|
|
FledastyError fledasty_queue_push(FledastyQueue *current_queue, void *value);
|
|
void *fledasty_queue_pop(FledastyQueue *current_queue);
|
|
|
|
FledastyError fledasty_queue_clear(FledastyQueue *current_queue);
|
|
|
|
static inline void *fledasty_queue_peek(const FledastyQueue *current_queue) { return (current_queue == NULL) ? NULL : current_queue->buffer + (current_queue->head * current_queue->element_byte_size); }
|
|
static inline bool fledasty_queue_is_empty(const FledastyQueue *current_queue) { return current_queue == NULL || current_queue->size == 0; }
|
|
|
|
#endif
|