src/queue.h
branchgamebalance
changeset 9895 7bd07f43b0e3
parent 6431 7f89731a0507
child 6303 84c215fc8eb8
equal deleted inserted replaced
9894:70d78ac95d6c 9895:7bd07f43b0e3
     7 //#define QUEUE_DEBUG
     7 //#define QUEUE_DEBUG
     8 //#define HASH_DEBUG
     8 //#define HASH_DEBUG
     9 //#define HASH_STATS
     9 //#define HASH_STATS
    10 
    10 
    11 
    11 
    12 typedef struct Queue Queue;
    12 struct Queue;
    13 typedef bool Queue_PushProc(Queue* q, void* item, int priority);
    13 typedef bool Queue_PushProc(Queue* q, void* item, int priority);
    14 typedef void* Queue_PopProc(Queue* q);
    14 typedef void* Queue_PopProc(Queue* q);
    15 typedef bool Queue_DeleteProc(Queue* q, void* item, int priority);
    15 typedef bool Queue_DeleteProc(Queue* q, void* item, int priority);
    16 typedef void Queue_ClearProc(Queue* q, bool free_values);
    16 typedef void Queue_ClearProc(Queue* q, bool free_values);
    17 typedef void Queue_FreeProc(Queue* q, bool free_values);
    17 typedef void Queue_FreeProc(Queue* q, bool free_values);
    18 
    18 
    19 typedef struct InsSortNode InsSortNode;
       
    20 struct InsSortNode {
    19 struct InsSortNode {
    21 	void* item;
    20 	void* item;
    22 	int priority;
    21 	int priority;
    23 	InsSortNode* next;
    22 	InsSortNode* next;
    24 };
    23 };
    25 
    24 
    26 typedef struct BinaryHeapNode BinaryHeapNode;
       
    27 struct BinaryHeapNode {
    25 struct BinaryHeapNode {
    28 	void* item;
    26 	void* item;
    29 	int priority;
    27 	int priority;
    30 };
    28 };
    31 
    29 
    97 
    95 
    98 
    96 
    99 /*
    97 /*
   100  * Hash
    98  * Hash
   101  */
    99  */
   102 typedef struct HashNode HashNode;
       
   103 struct HashNode {
   100 struct HashNode {
   104 	uint key1;
   101 	uint key1;
   105 	uint key2;
   102 	uint key2;
   106 	void* value;
   103 	void* value;
   107 	HashNode* next;
   104 	HashNode* next;
   109 /**
   106 /**
   110  * Generates a hash code from the given key pair. You should make sure that
   107  * Generates a hash code from the given key pair. You should make sure that
   111  * the resulting range is clearly defined.
   108  * the resulting range is clearly defined.
   112  */
   109  */
   113 typedef uint Hash_HashProc(uint key1, uint key2);
   110 typedef uint Hash_HashProc(uint key1, uint key2);
   114 typedef struct Hash {
   111 struct Hash {
   115 	/* The hash function used */
   112 	/* The hash function used */
   116 	Hash_HashProc* hash;
   113 	Hash_HashProc* hash;
   117 	/* The amount of items in the hash */
   114 	/* The amount of items in the hash */
   118 	uint size;
   115 	uint size;
   119 	/* The number of buckets allocated */
   116 	/* The number of buckets allocated */
   121 	/* A pointer to an array of num_buckets buckets. */
   118 	/* A pointer to an array of num_buckets buckets. */
   122 	HashNode* buckets;
   119 	HashNode* buckets;
   123 	/* A pointer to an array of numbuckets booleans, which will be true if
   120 	/* A pointer to an array of numbuckets booleans, which will be true if
   124 	 * there are any Nodes in the bucket */
   121 	 * there are any Nodes in the bucket */
   125 	bool* buckets_in_use;
   122 	bool* buckets_in_use;
   126 } Hash;
   123 };
   127 
   124 
   128 /* Call these function to manipulate a hash */
   125 /* Call these function to manipulate a hash */
   129 
   126 
   130 /* Deletes the value with the specified key pair from the hash and returns
   127 /* Deletes the value with the specified key pair from the hash and returns
   131  * that value. Returns NULL when the value was not present. The value returned
   128  * that value. Returns NULL when the value was not present. The value returned