summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortron <tron@openttd.org>2007-02-22 06:57:21 +0000
committertron <tron@openttd.org>2007-02-22 06:57:21 +0000
commit0d041a87cc475253176f796c156a3c49032eb415 (patch)
treef99d762539afc364b27fbe4cc8c68b8ae649ab24
parent56c38973ec0be4824bc648af8d0b8f2d3a192ece (diff)
downloadopenttd-0d041a87cc475253176f796c156a3c49032eb415.tar.xz
(svn r8840) -Fix
Remove FIFO and Stack. They have never been used and could not be used anyway because the declarations of some functions are spelled different than the definitions they should correspond to. Also remove some other unused helpers and related struct attributes.
-rw-r--r--src/queue.cpp166
-rw-r--r--src/queue.h47
2 files changed, 0 insertions, 213 deletions
diff --git a/src/queue.cpp b/src/queue.cpp
index b371908e0..6bd305a5a 100644
--- a/src/queue.cpp
+++ b/src/queue.cpp
@@ -5,140 +5,6 @@
#include "queue.h"
#include "helpers.hpp"
-static void Stack_Clear(Queue* q, bool free_values)
-{
- if (free_values) {
- uint i;
-
- for (i = 0; i < q->data.stack.size; i++) free(q->data.stack.elements[i]);
- }
- q->data.stack.size = 0;
-}
-
-static void Stack_Free(Queue* q, bool free_values)
-{
- q->clear(q, free_values);
- free(q->data.stack.elements);
- if (q->freeq) free(q);
-}
-
-static bool Stack_Push(Queue* q, void* item, int priority)
-{
- if (q->data.stack.size == q->data.stack.max_size) return false;
- q->data.stack.elements[q->data.stack.size++] = item;
- return true;
-}
-
-static void* Stack_Pop(Queue* q)
-{
- if (q->data.stack.size == 0) return NULL;
- return q->data.stack.elements[--q->data.stack.size];
-}
-
-static bool Stack_Delete(Queue* q, void* item, int priority)
-{
- return false;
-}
-
-static Queue* init_stack(Queue* q, uint max_size)
-{
- q->push = Stack_Push;
- q->pop = Stack_Pop;
- q->del = Stack_Delete;
- q->clear = Stack_Clear;
- q->free = Stack_Free;
- q->data.stack.max_size = max_size;
- q->data.stack.size = 0;
- q->data.stack.elements = MallocT<void*>(max_size);
- q->freeq = false;
- return q;
-}
-
-Queue* new_Stack(uint max_size)
-{
- Queue* q = MallocT<Queue>(1);
-
- init_stack(q, max_size);
- q->freeq = true;
- return q;
-}
-
-/*
- * Fifo
- */
-
-static void Fifo_Clear(Queue* q, bool free_values)
-{
- if (free_values) {
- uint head = q->data.fifo.head;
- uint tail = q->data.fifo.tail; /* cache for speed */
-
- while (head != tail) {
- free(q->data.fifo.elements[tail]);
- tail = (tail + 1) % q->data.fifo.max_size;
- }
- }
- q->data.fifo.head = 0;
- q->data.fifo.tail = 0;
-}
-
-static void Fifo_Free(Queue* q, bool free_values)
-{
- q->clear(q, free_values);
- free(q->data.fifo.elements);
- if (q->freeq) free(q);
-}
-
-static bool Fifo_Push(Queue* q, void* item, int priority)
-{
- uint next = (q->data.fifo.head + 1) % q->data.fifo.max_size;
-
- if (next == q->data.fifo.tail) return false;
- q->data.fifo.elements[q->data.fifo.head] = item;
-
- q->data.fifo.head = next;
- return true;
-}
-
-static void* Fifo_Pop(Queue* q)
-{
- void* result;
-
- if (q->data.fifo.head == q->data.fifo.tail) return NULL;
- result = q->data.fifo.elements[q->data.fifo.tail];
-
- q->data.fifo.tail = (q->data.fifo.tail + 1) % q->data.fifo.max_size;
- return result;
-}
-
-static bool Fifo_Delete(Queue* q, void* item, int priority)
-{
- return false;
-}
-
-static Queue* init_fifo(Queue* q, uint max_size)
-{
- q->push = Fifo_Push;
- q->pop = Fifo_Pop;
- q->del = Fifo_Delete;
- q->clear = Fifo_Clear;
- q->free = Fifo_Free;
- q->data.fifo.max_size = max_size;
- q->data.fifo.head = 0;
- q->data.fifo.tail = 0;
- q->data.fifo.elements = MallocT<void*>(max_size);
- q->freeq = false;
- return q;
-}
-
-Queue* new_Fifo(uint max_size)
-{
- Queue* q = MallocT<Queue>(1);
- init_fifo(q, max_size);
- q->freeq = true;
- return q;
-}
-
/*
* Insertion Sorter
@@ -161,7 +27,6 @@ static void InsSort_Clear(Queue* q, bool free_values)
static void InsSort_Free(Queue* q, bool free_values)
{
q->clear(q, free_values);
- if (q->freeq) free(q);
}
static bool InsSort_Push(Queue* q, void* item, int priority)
@@ -215,16 +80,6 @@ void init_InsSort(Queue* q)
q->clear = InsSort_Clear;
q->free = InsSort_Free;
q->data.inssort.first = NULL;
- q->freeq = false;
-}
-
-Queue* new_InsSort(void)
-{
- Queue* q = MallocT<Queue>(1);
-
- init_InsSort(q);
- q->freeq = true;
- return q;
}
@@ -284,7 +139,6 @@ static void BinaryHeap_Free(Queue* q, bool free_values)
free(q->data.binaryheap.elements[i]);
}
free(q->data.binaryheap.elements);
- if (q->freeq) free(q);
}
static bool BinaryHeap_Push(Queue* q, void* item, int priority)
@@ -430,21 +284,11 @@ void init_BinaryHeap(Queue* q, uint max_size)
q->data.binaryheap.elements = CallocT<BinaryHeapNode*>((max_size - 1) / BINARY_HEAP_BLOCKSIZE + 1);
q->data.binaryheap.elements[0] = MallocT<BinaryHeapNode>(BINARY_HEAP_BLOCKSIZE);
q->data.binaryheap.blocks = 1;
- q->freeq = false;
#ifdef QUEUE_DEBUG
printf("[BinaryHeap] Initial size of elements is %d nodes\n", BINARY_HEAP_BLOCKSIZE);
#endif
}
-Queue* new_BinaryHeap(uint max_size)
-{
- Queue* q = MallocT<Queue>(1);
-
- init_BinaryHeap(q, max_size);
- q->freeq = true;
- return q;
-}
-
// Because we don't want anyone else to bother with our defines
#undef BIN_HEAP_ARR
@@ -469,18 +313,9 @@ void init_Hash(Hash* h, Hash_HashProc* hash, uint num_buckets)
debug("Buckets = %p", h->buckets);
#endif
h->buckets_in_use = (bool*)(h->buckets + num_buckets);
- h->freeh = false;
for (i = 0; i < num_buckets; i++) h->buckets_in_use[i] = false;
}
-Hash* new_Hash(Hash_HashProc* hash, int num_buckets)
-{
- Hash* h = MallocT<Hash>(1);
-
- init_Hash(h, hash, num_buckets);
- h->freeh = true;
- return h;
-}
void delete_Hash(Hash* h, bool free_values)
{
@@ -511,7 +346,6 @@ void delete_Hash(Hash* h, bool free_values)
#ifdef HASH_DEBUG
debug("Freeing Hash: %p", h);
#endif
- if (h->freeh) free(h);
}
#ifdef HASH_STATS
diff --git a/src/queue.h b/src/queue.h
index 1bbdf353c..d65dee466 100644
--- a/src/queue.h
+++ b/src/queue.h
@@ -61,17 +61,6 @@ struct Queue{
union {
struct {
- uint max_size;
- uint size;
- void** elements;
- } stack;
- struct {
- uint max_size;
- uint head; /* The index where the last element should be inserted */
- uint tail; /* The index where the next element should be read */
- void** elements;
- } fifo;
- struct {
InsSortNode* first;
} inssort;
struct {
@@ -81,32 +70,8 @@ struct Queue{
BinaryHeapNode** elements;
} binaryheap;
} data;
-
- /* If true, this struct will be free'd when the
- * Queue is deleted. */
- bool freeq;
};
-/* Initializes a stack and allocates internal memory. */
-void init_Stack(Queue* q, uint max_size);
-
-/* Allocate a new stack with a maximum of max_size elements. */
-Queue* new_Stack(uint max_size);
-
-/*
- * Fifo
- */
-
-/* Initializes a fifo and allocates internal memory for maximum of max_size
- * elements */
-void init_Fifo(Queue* q, uint max_size);
-
-/* Allocate a new fifo and initializes it with a maximum of max_size elements. */
-Queue* new_Fifo(uint max_size);
-
-Queue* new_Fifo_in_buffer(uint max_size, void* buffer);
-
-int build_Fifo(void* buffer, uint size);
/*
* Insertion Sorter
@@ -116,8 +81,6 @@ int build_Fifo(void* buffer, uint size);
* size */
void init_InsSort(Queue* q);
-/* Allocate a new fifo and initializes it. There is no maximum size */
-Queue* new_InsSort(void);
/*
* Binary Heap
@@ -132,9 +95,6 @@ Queue* new_InsSort(void);
* max_size elements */
void init_BinaryHeap(Queue* q, uint max_size);
-/* Allocate a new binary heap and initializes it with a maximum of max_size
- * elements. */
-Queue* new_BinaryHeap(uint max_size);
/*
* Hash
@@ -163,10 +123,6 @@ typedef struct Hash {
/* A pointer to an array of numbuckets booleans, which will be true if
* there are any Nodes in the bucket */
bool* buckets_in_use;
- /* If true, buckets will be freed in delete_hash */
- bool freeb;
- /* If true, the pointer to this struct will be freed in delete_hash */
- bool freeh;
} Hash;
/* Call these function to manipulate a hash */
@@ -184,9 +140,6 @@ void* Hash_Get(const Hash* h, uint key1, uint key2);
/* Call these function to create/destroy a hash */
-/* Builds a new hash, with num_buckets buckets. Make sure that hash() always
- * returns a hash less than num_buckets! Call delete_hash after use */
-Hash* new_Hash(Hash_HashProc* hash, int num_buckets);
/* Builds a new hash in an existing struct. Make sure that hash() always
* returns a hash less than num_buckets! Call delete_hash after use */
void init_Hash(Hash* h, Hash_HashProc* hash, uint num_buckets);