src/queue.h
branchgamebalance
changeset 9906 6f41b8713b65
parent 9895 7bd07f43b0e3
child 6743 cabfaa4a0295
equal deleted inserted replaced
9905:91eca6fdee8d 9906:6f41b8713b65
     1 /* $Id$ */
     1 /* $Id$ */
       
     2 
       
     3 /** @file queue.h */
     2 
     4 
     3 #ifndef QUEUE_H
     5 #ifndef QUEUE_H
     4 #define QUEUE_H
     6 #define QUEUE_H
     5 
     7 
     6 //#define NOFREE
     8 //#define NOFREE
    62 			InsSortNode* first;
    64 			InsSortNode* first;
    63 		} inssort;
    65 		} inssort;
    64 		struct {
    66 		struct {
    65 			uint max_size;
    67 			uint max_size;
    66 			uint size;
    68 			uint size;
    67 			uint blocks; /* The amount of blocks for which space is reserved in elements */
    69 			uint blocks; ///< The amount of blocks for which space is reserved in elements
    68 			BinaryHeapNode** elements;
    70 			BinaryHeapNode** elements;
    69 		} binaryheap;
    71 		} binaryheap;
    70 	} data;
    72 	} data;
    71 };
    73 };
    72 
    74 
    73 
    75 
    74 /*
    76 /**
    75  * Insertion Sorter
    77  * Insertion Sorter
    76  */
    78  */
    77 
    79 
    78 /* Initializes a inssort and allocates internal memory. There is no maximum
    80 /* Initializes a inssort and allocates internal memory. There is no maximum
    79  * size */
    81  * size */
    87  */
    89  */
    88 
    90 
    89 /* The amount of elements that will be malloc'd at a time */
    91 /* The amount of elements that will be malloc'd at a time */
    90 #define BINARY_HEAP_BLOCKSIZE_BITS 10
    92 #define BINARY_HEAP_BLOCKSIZE_BITS 10
    91 
    93 
    92 /* Initializes a binary heap and allocates internal memory for maximum of
    94 /** Initializes a binary heap and allocates internal memory for maximum of
    93  * max_size elements */
    95  * max_size elements */
    94 void init_BinaryHeap(Queue* q, uint max_size);
    96 void init_BinaryHeap(Queue* q, uint max_size);
    95 
    97 
    96 
    98 
    97 /*
    99 /*
   122 	bool* buckets_in_use;
   124 	bool* buckets_in_use;
   123 };
   125 };
   124 
   126 
   125 /* Call these function to manipulate a hash */
   127 /* Call these function to manipulate a hash */
   126 
   128 
   127 /* Deletes the value with the specified key pair from the hash and returns
   129 /** Deletes the value with the specified key pair from the hash and returns
   128  * that value. Returns NULL when the value was not present. The value returned
   130  * that value. Returns NULL when the value was not present. The value returned
   129  * is _not_ free()'d! */
   131  * is _not_ free()'d! */
   130 void* Hash_Delete(Hash* h, uint key1, uint key2);
   132 void* Hash_Delete(Hash* h, uint key1, uint key2);
   131 /* Sets the value associated with the given key pair to the given value.
   133 /** Sets the value associated with the given key pair to the given value.
   132  * Returns the old value if the value was replaced, NULL when it was not yet present. */
   134  * Returns the old value if the value was replaced, NULL when it was not yet present. */
   133 void* Hash_Set(Hash* h, uint key1, uint key2, void* value);
   135 void* Hash_Set(Hash* h, uint key1, uint key2, void* value);
   134 /* Gets the value associated with the given key pair, or NULL when it is not
   136 /** Gets the value associated with the given key pair, or NULL when it is not
   135  * present. */
   137  * present. */
   136 void* Hash_Get(const Hash* h, uint key1, uint key2);
   138 void* Hash_Get(const Hash* h, uint key1, uint key2);
   137 
   139 
   138 /* Call these function to create/destroy a hash */
   140 /* Call these function to create/destroy a hash */
   139 
   141 
   140 /* Builds a new hash in an existing struct. Make sure that hash() always
   142 /** Builds a new hash in an existing struct. Make sure that hash() always
   141  * returns a hash less than num_buckets! Call delete_hash after use */
   143  * returns a hash less than num_buckets! Call delete_hash after use */
   142 void init_Hash(Hash* h, Hash_HashProc* hash, uint num_buckets);
   144 void init_Hash(Hash* h, Hash_HashProc* hash, uint num_buckets);
   143 /*
   145 /**
   144  * Deletes the hash and cleans up. Only cleans up memory allocated by new_Hash
   146  * Deletes the hash and cleans up. Only cleans up memory allocated by new_Hash
   145  * & friends. If free is true, it will call free() on all the values that
   147  * & friends. If free is true, it will call free() on all the values that
   146  * are left in the hash.
   148  * are left in the hash.
   147  */
   149  */
   148 void delete_Hash(Hash* h, bool free_values);
   150 void delete_Hash(Hash* h, bool free_values);
   149 /*
   151 /**
   150  * Cleans the hash, but keeps the memory allocated
   152  * Cleans the hash, but keeps the memory allocated
   151  */
   153  */
   152 void clear_Hash(Hash* h, bool free_values);
   154 void clear_Hash(Hash* h, bool free_values);
   153 /*
   155 /**
   154  * Gets the current size of the Hash
   156  * Gets the current size of the Hash
   155  */
   157  */
   156 uint Hash_Size(const Hash* h);
   158 uint Hash_Size(const Hash* h);
   157 
   159 
   158 #endif /* QUEUE_H */
   160 #endif /* QUEUE_H */