-
Notifications
You must be signed in to change notification settings - Fork 0
/
llfifo.h
102 lines (86 loc) · 2 KB
/
llfifo.h
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/*
* llfifo.h - a dynamically-growing FIFO
*
* Author: Howdy Pierce, [email protected]
* Modeified : Arpit Savarakar, [email protected]
*/
#ifndef _LLFIFO_H_
#define _LLFIFO_H_
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <stdio.h>
#include <assert.h>
/*
* The llfifo's main data structure.
*
* Defined here as an incomplete type, in order to hide the
* implementation from the user. You will need to define this struct
* in your .c file.
*/
typedef struct llfifo_s llfifo_t;
/*
* Initializes the FIFO
*
* Parameters:
* capacity the initial size of the fifo, in number of elements
*
* Returns:
* A pointer to an llfifo_t, or NULL in case of an error.
*/
llfifo_t *llfifo_create(int capacity);
/*
* Enqueues an element onto the FIFO, growing the FIFO by adding
* additional elements, if necessary
*
* Parameters:
* fifo The fifo in question
* element The element to enqueue
*
* Returns:
* The new length of the FIFO on success, -1 on failure
*/
int llfifo_enqueue(llfifo_t *fifo, void *element);
/*
* Removes ("dequeues") an element from the FIFO, and returns it
*
* Parameters:
* fifo The fifo in question
*
* Returns:
* The dequeued element, or NULL if the FIFO was empty
*/
void *llfifo_dequeue(llfifo_t *fifo);
/*
* Returns the number of elements currently on the FIFO.
*
* Parameters:
* fifo The fifo in question
*
* Returns:
* The number of elements currently on the FIFO
*/
int llfifo_length(llfifo_t *fifo);
/*
* Returns the FIFO's current capacity
*
* Parameters:
* fifo The fifo in question
*
* Returns:
* The current capacity, in number of elements, for the FIFO
*/
int llfifo_capacity(llfifo_t *fifo);
/*
* Teardown function. The llfifo will free all dynamically allocated
* memory. After calling this function, the fifo should not be used
* again!
*
* Parameters:
* fifo The fifo in question
*
* Returns:
* none
*/
void llfifo_destroy(llfifo_t *fifo);
#endif // _LLFIFO_H_