-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsqueue.h
83 lines (66 loc) · 2.29 KB
/
squeue.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
/* Generated by specialize genericqueue SQueue "struct State *"
* Queues are a sequence of some domain.
* Operations:
* create, destroy, insert, remove, insertfront, removeback, size, print
* foreach
*/
#ifndef _EMERALD_SQUEUE_H
#define _EMERALD_SQUEUE_H
/*
* Before using this, one must define the following:
* SQueueDomainType - a typedef for the domain
*/
typedef struct State * SQueueDomainType;
/*
* Hidden, private type declarations. The only thing
* that applications of this package are to see is SQueue,
* and they are to treat it as opaque: that is, they may
* assign it, and pass it as arguments, but not manipulate
* what it points to directly.
*/
typedef struct SQueueRecord {
SQueueDomainType *table;
int size, first, count;
} SQueueRecord, *SQueue;
/* OPERATIONS */
/* Return a new, empty queue */
SQueue SQueueCreate(void);
/* Destroy a queue */
void SQueueDestroy(SQueue);
/* Insert the value at the rear of the queue */
void SQueueInsert(SQueue q, SQueueDomainType v);
/* Insert the value at the front of the queue */
void SQueueInsertFront(SQueue q, SQueueDomainType v);
/* Remove and return the value at the front of the queue */
SQueueDomainType SQueueRemove(SQueue q);
/* Remove and return the value at the back of the queue */
SQueueDomainType SQueueRemoveBack(SQueue q);
/* Remove a specific element from the SQueue, return 1 if found */
int SQueueYank(SQueue q, SQueueDomainType e);
/* DEBUGGING: Print the queue */
void SQueuePrint(SQueue q);
/* Iterate over the elements of the queue
* At each iteration, SQueueValue is set to the next element
* Usage:
* SQueueForEach(someSq, key) {
* / * whatever you want to do with key * /
* } SQueueNext();
*/
#define SQueueForEach(q, value) \
{ \
int SQueuexx_index, SQueuexx_count; \
for (SQueuexx_index = (((q) && !ISNIL(q)) ? (q)->first: 0), SQueuexx_count = 0; \
SQueuexx_count < (((q) && !ISNIL(q)) ? (q)->count : 0); \
SQueuexx_count++, \
SQueuexx_index += \
(SQueuexx_index == (q)->size -1 ? -((q)->size - 1) : 1)) { \
*(SQueueDomainType*)(&(value)) = (q)->table[SQueuexx_index]; \
{
#define SQueueNext() \
} \
} \
}
/* Return the number of elements in SQueue */
#define SQueueSize(q) (((q) && !ISNIL(q)) ? (q)->count : 0)
#include "storage.h"
#endif /* _EMERALD_SQUEUE_H */