1 /* 2 * queue.h 3 * 4 * Version: 2.2.5 5 * 6 * ----------------------------------------------------------------------------- 7 * 8 * SPDX-License-Identifier: MIT 9 * 10 * Copyright (c) 2018-2024 Ryan M. Lederman <lederman@gmail.com> 11 * 12 * Permission is hereby granted, free of charge, to any person obtaining a copy of 13 * this software and associated documentation files (the "Software"), to deal in 14 * the Software without restriction, including without limitation the rights to 15 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 16 * the Software, and to permit persons to whom the Software is furnished to do so, 17 * subject to the following conditions: 18 * 19 * The above copyright notice and this permission notice shall be included in all 20 * copies or substantial portions of the Software. 21 * 22 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 23 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 24 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 25 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 26 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 27 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 28 * 29 * ----------------------------------------------------------------------------- 30 */ 31 32 #ifndef _SIR_QUEUE_H_INCLUDED 33 # define _SIR_QUEUE_H_INCLUDED 34 35 # include "sir/types.h" 36 37 /** Creates a sir_queue_node and sets its data property. */ 38 sir_queue_node* _sir_queue_node_create(void* data); 39 40 /** Deletes a previously created sir_queue_node and optionally returns its 41 * data. */ 42 bool _sir_queue_node_destroy(sir_queue_node** node, void** data); 43 44 /** Creates an empty sir_queue. */ 45 bool _sir_queue_create(sir_queue** q); 46 47 /** Destroys a sir_queue (empty or otherwise). */ 48 bool _sir_queue_destroy(sir_queue** q); 49 50 /** Returns the number of nodes in a queue. */ 51 size_t _sir_queue_size(sir_queue* q); 52 53 /** `true` if the queue contains zero nodes, `false` otherwise. */ 54 bool _sir_queue_isempty(const sir_queue* q); 55 56 /** Pushes a new node onto the back of a queue. */ 57 bool _sir_queue_push(sir_queue* q, void* data); 58 59 /** Pops a node off the front of a queue, if one is available. */ 60 bool _sir_queue_pop(sir_queue* q, void** data); 61 62 #endif /* !_SIR_QUEUE_H_INCLUDED */