queue.h
Go to the documentation of this file.00001
00002
00005 #ifndef QUEUE_H
00006 #define QUEUE_H
00007
00008
00009
00010
00011
00012
00013
00014 struct Queue;
00015 typedef bool Queue_PushProc(Queue *q, void *item, int priority);
00016 typedef void* Queue_PopProc(Queue *q);
00017 typedef bool Queue_DeleteProc(Queue *q, void* item, int priority);
00018 typedef void Queue_ClearProc(Queue *q, bool free_values);
00019 typedef void Queue_FreeProc(Queue *q, bool free_values);
00020
00021 struct InsSortNode {
00022 void *item;
00023 int priority;
00024 InsSortNode* next;
00025 };
00026
00027 struct BinaryHeapNode {
00028 void *item;
00029 int priority;
00030 };
00031
00032
00033 struct Queue{
00034
00035
00036
00037
00038 Queue_PushProc *push;
00039
00040
00041
00042
00043 Queue_PopProc *pop;
00044
00045
00046
00047
00048
00049 Queue_DeleteProc *del;
00050
00051
00052
00053
00054
00055 Queue_ClearProc *clear;
00056
00057
00058
00059
00060 Queue_FreeProc *free;
00061
00062 union {
00063 struct {
00064 InsSortNode *first;
00065 } inssort;
00066 struct {
00067 uint max_size;
00068 uint size;
00069 uint blocks;
00070 BinaryHeapNode **elements;
00071 } binaryheap;
00072 } data;
00073 };
00074
00075
00080
00081
00082 void init_InsSort(Queue *q);
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092 #define BINARY_HEAP_BLOCKSIZE_BITS 10
00093
00096 void init_BinaryHeap(Queue *q, uint max_size);
00097
00098
00099
00100
00101
00102 struct HashNode {
00103 uint key1;
00104 uint key2;
00105 void *value;
00106 HashNode *next;
00107 };
00112 typedef uint Hash_HashProc(uint key1, uint key2);
00113 struct Hash {
00114
00115 Hash_HashProc *hash;
00116
00117 uint size;
00118
00119 uint num_buckets;
00120
00121 HashNode *buckets;
00122
00123
00124 bool *buckets_in_use;
00125 };
00126
00127
00128
00132 void *Hash_Delete(Hash *h, uint key1, uint key2);
00135 void *Hash_Set(Hash *h, uint key1, uint key2, void *value);
00138 void *Hash_Get(const Hash *h, uint key1, uint key2);
00139
00140
00141
00144 void init_Hash(Hash *h, Hash_HashProc *hash, uint num_buckets);
00150 void delete_Hash(Hash *h, bool free_values);
00154 void clear_Hash(Hash *h, bool free_values);
00158 uint Hash_Size(const Hash *h);
00159
00160 #endif