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 struct BinaryHeapNode {
00019 void *item;
00020 int priority;
00021 };
00022
00023
00028 struct BinaryHeap {
00029 static const int BINARY_HEAP_BLOCKSIZE;
00030 static const int BINARY_HEAP_BLOCKSIZE_BITS;
00031 static const int BINARY_HEAP_BLOCKSIZE_MASK;
00032
00033 void Init(uint max_size);
00034
00035 bool Push(void *item, int priority);
00036 void *Pop();
00037 bool Delete(void *item, int priority);
00038 void Clear(bool free_values);
00039 void Free(bool free_values);
00040
00046 FORCEINLINE BinaryHeapNode &GetElement(uint i)
00047 {
00048 assert(i > 0);
00049 return this->elements[(i - 1) >> BINARY_HEAP_BLOCKSIZE_BITS][(i - 1) & BINARY_HEAP_BLOCKSIZE_MASK];
00050 }
00051
00052 uint max_size;
00053 uint size;
00054 uint blocks;
00055 BinaryHeapNode **elements;
00056 };
00057
00058
00059
00060
00061
00062 struct HashNode {
00063 uint key1;
00064 uint key2;
00065 void *value;
00066 HashNode *next;
00067 };
00072 typedef uint Hash_HashProc(uint key1, uint key2);
00073 struct Hash {
00074
00075 Hash_HashProc *hash;
00076
00077 uint size;
00078
00079 uint num_buckets;
00080
00081 HashNode *buckets;
00082
00083
00084 bool *buckets_in_use;
00085
00086 void Init(Hash_HashProc *hash, uint num_buckets);
00087
00088 void *Get(uint key1, uint key2) const;
00089 void *Set(uint key1, uint key2, void *value);
00090
00091 void *DeleteValue(uint key1, uint key2);
00092
00093 void Clear(bool free_values);
00094 void Delete(bool free_values);
00095
00099 FORCEINLINE uint GetSize() const
00100 {
00101 return this->size;
00102 }
00103
00104 protected:
00105 #ifdef HASH_STATS
00106 void PrintStatistics() const;
00107 #endif
00108 HashNode *FindNode(uint key1, uint key2, HashNode** prev_out) const;
00109 };
00110
00111 #endif