summaryrefslogtreecommitdiff
path: root/archive/src/std/containers/ring_queue.h
blob: 15d5da4b4d387d792c8f38601b1001705f431c36 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/**
 * @file ring_queue.h
 * @author your name (you@domain.com)
 * @brief
 * @version 0.1
 * @date 2024-02-24
 *
 * @copyright Copyright (c) 2024
 *
 */
#pragma once
#include "defines.h"

/**
 * @brief a fixed-size ring queue
 */
typedef struct ring_queue {
  size_t len;
  size_t capacity;
  size_t type_size;
  void* data;
  bool owns_memory;
  int32_t head;
  int32_t tail;
} ring_queue;

ring_queue* ring_queue_new(size_t type_size, size_t capacity, void* memory_block);

void ring_queue_free(ring_queue* queue);

bool ring_queue_enqueue(ring_queue* queue, const void* value);

bool ring_queue_dequeue(ring_queue* queue, void* out_value);

bool ring_queue_peek(const ring_queue* queue, void* out_value);