-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathqueue.h
39 lines (30 loc) · 917 Bytes
/
queue.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
#ifndef _queue_h_INCLUDED
#define _queue_h_INCLUDED
#include <assert.h>
#include <stdbool.h>
#include <stdint.h>
struct link {
struct link *prev, *next;
uint64_t stamp;
};
struct queue {
struct link *links;
struct link *first, *last;
struct link *search;
uint64_t stamp;
};
/*------------------------------------------------------------------------*/
void enqueue (struct queue *queue, struct link *link, bool update);
void dequeue (struct queue *queue, struct link *link);
/*------------------------------------------------------------------------*/
static inline void update_queue_search (struct queue *queue,
struct link *link) {
struct link *search = queue->search;
assert (search);
if (search->stamp < link->stamp)
queue->search = link;
}
static inline void reset_queue_search (struct queue *queue) {
queue->search = queue->last;
}
#endif