1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180
|
/*-----------------------------------------------------------------------
File : clb_pqueues.c
Author: Stephan Schulz
Contents
LIFO-Lists of pointers and (long) integers.
Copyright 1998, 1999 by the author.
This code is released under the GNU General Public Licence and
the GNU Lesser General Public License.
See the file COPYING in the main E directory for details..
Run "eprover -h" for contact information.
Changes
<1> Tue Jun 30 17:34:19 MET DST 1998
New
-----------------------------------------------------------------------*/
#include "clb_pqueue.h"
/*---------------------------------------------------------------------*/
/* Global Variables */
/*---------------------------------------------------------------------*/
/*---------------------------------------------------------------------*/
/* Forward Declarations */
/*---------------------------------------------------------------------*/
/*---------------------------------------------------------------------*/
/* Internal Functions */
/*---------------------------------------------------------------------*/
/*---------------------------------------------------------------------*/
/* Exported Functions */
/*---------------------------------------------------------------------*/
/*-----------------------------------------------------------------------
//
// Function: PQueueGrow()
//
// Increase the size of queue.
//
// Global Variables: -
//
// Side Effects : Memory operations.
//
/----------------------------------------------------------------------*/
void PQueueGrow(PQueue_p queue)
{
long new_size, i;
IntOrP *new_mem;
new_size = queue->size*2;
new_mem = SizeMalloc(new_size*sizeof(IntOrP));
for(i=0; i<queue->head; i++)
{
new_mem[i] = queue->queue[i];
}
for(i=queue->head; i<queue->size; i++)
{
new_mem[i+queue->size] = queue->queue[i];
}
queue->tail+= queue->size;
SizeFree(queue->queue, queue->size*sizeof(IntOrP));
queue->queue = new_mem;
queue->size = new_size;
}
/*-----------------------------------------------------------------------
//
// Function: PQueueCardinality()
//
// Return the number of elements in the queue.
//
// Global Variables: -
//
// Side Effects : -
/
/----------------------------------------------------------------------*/
long PQueueCardinality(PQueue_p queue)
{
long res;
if(queue->head>=queue->tail)
{
res = queue->head-queue->tail;
}
else
{
res = queue->tail+(queue->size-queue->head);
}
/* printf("Card(%ld, %ld) = %ld\n", queue->head, queue->tail,
res); */
return res;
}
/*-----------------------------------------------------------------------
//
// Function: PQueueElement()
//
// Retutn the entry at absolute index index.
//
// Global Variables: -
//
// Side Effects : -
//
/----------------------------------------------------------------------*/
IntOrP PQueueElement(PQueue_p queue, long index)
{
return queue->queue[index];
}
/*-----------------------------------------------------------------------
//
// Function: PQueueTailIndex()
//
// Return the index of the tail (oldest, last) element (or -1 if the
// queue is empty).
//
// Global Variables:
//
// Side Effects :
//
/----------------------------------------------------------------------*/
long PQueueTailIndex(PQueue_p queue)
{
if(PQueueEmpty(queue))
{
return -1;
}
return queue->tail;
}
/*-----------------------------------------------------------------------
//
// Function: PQueueIncIndex()
//
// Given an index to a (used) element in the queue, return a similar
// index to to next element (or -1 if there is no next element).
//
// Global Variables: -
//
// Side Effects : -
//
/----------------------------------------------------------------------*/
long PQueueIncIndex(PQueue_p queue, long index)
{
index = (index+1) % queue->size;
if(index == queue->head)
{
return -1;
}
return index;
}
/*---------------------------------------------------------------------*/
/* End of File */
/*---------------------------------------------------------------------*/
|