forked from phhusson/mptcp-proxy
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtp_heap.h
51 lines (31 loc) · 1.08 KB
/
tp_heap.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
//TP_HEAP: Heap structure to save events based on due time.
// Adapted from binheap.c @ http://cprogramminglanguage.net/binary-heap-c-code.aspx
// Heap stores pointers of tp_event based on tp_event's member "time".
// Heap represents min-priority queue, i.e. earliest tp_event is on top.
#include <sys/time.h>
#define HeapCapInc (50)
struct tp_event{
struct timeval time;
int type;
void *data;
};
typedef struct tp_event *ElementType;
struct HeapStruct {
int Capacity;
int Size;
ElementType *Elements;
};
typedef struct HeapStruct *PriorityQueue;
extern PriorityQueue PQ;
int earlier(struct tp_event *ev1, struct tp_event *ev2);
int is_due(struct tp_event *ev, struct timeval *tm);
PriorityQueue Initialize(int MaxElements);
void Destroy(PriorityQueue H);
void MakeEmpty(PriorityQueue H);
void Insert(ElementType X, PriorityQueue H);
ElementType DeleteMin(PriorityQueue H);
ElementType FindMin(PriorityQueue H);
int IsEmpty(PriorityQueue H);
int IsFull(PriorityQueue H);
void Error(char *str);
void FatalError(char *str);