Added queues.h

* source/server/queues.h (QUEUES_H): Defined the interface and structures for universal queues.
This commit is contained in:
Barra Ó Catháin 2024-04-17 14:06:45 +01:00
parent bbcde81eaf
commit 19fa527d73
1 changed files with 54 additions and 0 deletions

54
source/server/queues.h Normal file
View File

@ -0,0 +1,54 @@
// =========================================
// | SilverMUD Server - queues.h |
// | Copyright (C) 2023, Barra Ó Catháin |
// | See end of file for copyright notice. |
// =========================================
#ifndef QUEUES_H
#define QUEUES_H
#include "data-type.h"
#include <stdbool.h>
struct Queue
{
size_t itemCount;
enum DataType type;
struct QueueNode * front;
struct QueueNode * back;
};
struct QueueNode
{
struct QueueNode * next;
void * data;
};
// Functions:
// ==========
struct Queue * createQueue(enum DataType type);
int destroyQueue(struct Queue * queue);
int destroyQueueAndContents(void (*deallocationFunction)(void *), struct Queue * queue);
void * peekFromQueue(struct Queue * queue);
size_t popFromQueue(struct Queue * queue);
size_t pushToQueue(enum DataType type, void * data, struct Queue * queue);
size_t popFromQueueAndDestroy(void (*deallocationFunction)(void *), struct Queue * queue);
#endif
// ==============================================
// | End of queues.h, copyright notice follows. |
// ==============================================
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.