queue.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00012 #ifndef QUEUE_H
00013 #define QUEUE_H
00014
00015
00016
00017
00018
00019
00020
00021 struct Queue;
00022 typedef bool Queue_PushProc(Queue *q, void *item, int priority);
00023 typedef void *Queue_PopProc(Queue *q);
00024 typedef bool Queue_DeleteProc(Queue *q, void *item, int priority);
00025 typedef void Queue_ClearProc(Queue *q, bool free_values);
00026 typedef void Queue_FreeProc(Queue *q, bool free_values);
00027
00028 struct InsSortNode {
00029 void *item;
00030 int priority;
00031 InsSortNode *next;
00032 };
00033
00034 struct BinaryHeapNode {
00035 void *item;
00036 int priority;
00037 };
00038
00039
00040 struct Queue {
00041
00042
00043
00044
00045 Queue_PushProc *push;
00046
00047
00048
00049
00050 Queue_PopProc *pop;
00051
00052
00053
00054
00055
00056 Queue_DeleteProc *del;
00057
00058
00059
00060
00061
00062 Queue_ClearProc *clear;
00063
00064
00065
00066
00067 Queue_FreeProc *free;
00068
00069 union {
00070 struct {
00071 InsSortNode *first;
00072 } inssort;
00073 struct {
00074 uint max_size;
00075 uint size;
00076 uint blocks;
00077 BinaryHeapNode **elements;
00078 } binaryheap;
00079 } data;
00080 };
00081
00082
00087
00088
00089 void init_InsSort(Queue *q);
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099 #define BINARY_HEAP_BLOCKSIZE_BITS 10
00100
00103 void init_BinaryHeap(Queue *q, uint max_size);
00104
00105
00106
00107
00108
00109 struct HashNode {
00110 uint key1;
00111 uint key2;
00112 void *value;
00113 HashNode *next;
00114 };
00119 typedef uint Hash_HashProc(uint key1, uint key2);
00120 struct Hash {
00121
00122 Hash_HashProc *hash;
00123
00124 uint size;
00125
00126 uint num_buckets;
00127
00128 HashNode *buckets;
00129
00130
00131 bool *buckets_in_use;
00132 };
00133
00134
00135
00139 void *Hash_Delete(Hash *h, uint key1, uint key2);
00142 void *Hash_Set(Hash *h, uint key1, uint key2, void *value);
00145 void *Hash_Get(const Hash *h, uint key1, uint key2);
00146
00147
00148
00151 void init_Hash(Hash *h, Hash_HashProc *hash, uint num_buckets);
00157 void delete_Hash(Hash *h, bool free_values);
00161 void clear_Hash(Hash *h, bool free_values);
00165 uint Hash_Size(const Hash *h);
00166
00167 #endif