cdsa-queue 0.1.0
Loading...
Searching...
No Matches
queue.h
Go to the documentation of this file.
1/*
2BSD 3-Clause License
3
4Copyright (c) 2022, KriztoferY (https://github.com/KriztoferY)
5All rights reserved.
6
7Redistribution and use in source and binary forms, with or without
8modification, are permitted provided that the following conditions are met:
9
101. Redistributions of source code must retain the above copyright notice, this
11 list of conditions and the following disclaimer.
12
132. Redistributions in binary form must reproduce the above copyright notice,
14 this list of conditions and the following disclaimer in the documentation
15 and/or other materials provided with the distribution.
16
173. Neither the name of the copyright holder nor the names of its
18 contributors may be used to endorse or promote products derived from
19 this software without specific prior written permission.
20
21THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
25FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31*/
32
54#ifndef QUEUE_H
55#define QUEUE_H
56
57#include <stddef.h> // size_t
58#include <stdbool.h> // bool
59
61typedef struct queue Queue;
62
74Queue* Queue_create(size_t elem_sz);
75
83void Queue_destroy(Queue* queue);
84
94size_t Queue_capacity(Queue* queue);
95
102bool Queue_empty(Queue* queue);
103
110size_t Queue_size(Queue* queue);
111
120bool Queue_front(Queue* queue, void* elem);
121
130bool Queue_enqueue(Queue* queue, void const* elem);
131
138bool Queue_dequeue(Queue* queue);
139
155void Queue_print(Queue* queue, char const* sep, bool vertical,
156 void (*print_element)(void const*));
157
158#endif /* QUEUE_H */
bool Queue_dequeue(Queue *queue)
Removes the front element from a queue.
bool Queue_enqueue(Queue *queue, void const *elem)
Adds an element to the end of a queue.
size_t Queue_capacity(Queue *queue)
Queries the capacity of a queue.
Queue * Queue_create(size_t elem_sz)
Creates an empty, heap-allocated queue.
bool Queue_empty(Queue *queue)
Determines whether a queue is empty.
struct queue Queue
Definition: queue.h:61
bool Queue_front(Queue *queue, void *elem)
Accesses the front element of a queue.
void Queue_destroy(Queue *queue)
Destroys a heap-allocated queue.
void Queue_print(Queue *queue, char const *sep, bool vertical, void(*print_element)(void const *))
Prints a string representation of the elements in a queue to the standard output.
size_t Queue_size(Queue *queue)
Queries the size of a queue.