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
|
/*-----------------------------------------------------------------------
File : clb_pdrangearrays.h
Author: Stephan Schulz
Contents
Dynamic arrays of pointers and long integers with an index range
defined by upper and lower bound.
You can define the growth behaviour by specifying a value. If it is
GROW_EXPONENTIAL, arrays will always grow by a factor that is the
lowest power of two that will make the array big enough. Otherwise
it will grow by the smallest multiple of the value specified that
creates the requested position.
Copyright 2010 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> Thu May 27 18:09:45 CEST 2010
New
-----------------------------------------------------------------------*/
#ifndef CLB_PDRANGEARRAYS
#define CLB_PDRANGEARRAYS
#include <clb_pdarrays.h>
/*---------------------------------------------------------------------*/
/* Data type declarations */
/*---------------------------------------------------------------------*/
typedef struct pdrangearrcell
{
bool integer;
long offset; /* Indices go from offset (inclusive) to offset+size
(exclusive) */
long size;
long grow;
IntOrP *array;
}PDRangeArrCell, *PDRangeArr_p;
/*---------------------------------------------------------------------*/
/* Exported Functions and Variables */
/*---------------------------------------------------------------------*/
#define PDRangeArrCellAlloc() (PDRangeArrCell*)SizeMalloc(sizeof(PDRangeArrCell))
#define PDRangeArrCellFree(junk) SizeFree(junk, sizeof(PDRangeArrCell))
#ifdef CONSTANT_MEM_ESTIMATE
#define PDRANGEARRELL_MEM 20
#else
#define PDRANGEARR_MEM MEMSIZE(PDRangeArrCell)
#endif
#define PDRangeArrStorage(arr) (PDRANGEARRL_MEM+INTORP_MEM+((arr)->size*INTORP_MEM))
PDRangeArr_p PDRangeArrAlloc(long idx, long grow);
PDRangeArr_p PDIntRangeArrAlloc(long idx, long grow);
void PDRangeArrFree(PDRangeArr_p junk);
void PDRangeArrEnlarge(PDRangeArr_p array, long idx);
PDRangeArr_p PDRangeArrCopy(PDRangeArr_p array);
static inline IntOrP* PDRangeArrElementRef(PDRangeArr_p array, long idx);
void PDRangeArrElementDeleteP(PDRangeArr_p array, long idx);
void PDRangeArrElementDeleteInt(PDRangeArr_p array, long idx);
#define PDRangeArrAssign(array, idx, value) \
*PDRangeArrElementRef((array), (idx)) = (value)
#define PDRangeArrAssignP(array, idx, value) \
PDRangeArrElementRef((array), (idx))->p_val = (value)
#define PDRangeArrAssignInt(array, idx, value) \
PDRangeArrElementRef((array), (idx))->i_val = (value)
#define PDRangeArrElement(array, idx) \
*PDRangeArrElementRef((array), (idx))
#define PDRangeArrElementP(array, idx) \
(PDRangeArrElementRef((array), (idx))->p_val)
#define PDRangeArrElementInt(array, idx) \
(PDRangeArrElementRef((array), (idx))->i_val)
#define PDRangeArrLowKey(array) ((array)->offset)
#define PDRangeArrLimitKey(array) ((array)->offset+(array)->size)
#define PDRangeArrIndexIsCovered(array, idx) \
(((idx)>=PDRangeArrLowKey(array))&&(((idx)<PDRangeArrLimitKey(array))))
long PDRangeArrElementIncInt(PDRangeArr_p array, long idx, long value);
/*---------------------------------------------------------------------*/
/* Inline functions */
/*---------------------------------------------------------------------*/
/*-----------------------------------------------------------------------
//
// Function: PDRangeArrElementRef()
//
// Return a reference to an element in a dynamic array. This
// reference is only good until the next call to this function! User
// programs are expected to use this function only extremely rarely
// and with special care. Use PDRangeArrElement()/PDRangeArrAssign()
// instead.
//
// Global Variables: -
//
// Side Effects : May enlarge and move array.
//
/----------------------------------------------------------------------*/
static inline IntOrP* PDRangeArrElementRef(PDRangeArr_p array, long idx)
{
assert(array);
if(!PDRangeArrIndexIsCovered(array, idx))
{
PDRangeArrEnlarge(array, idx);
}
assert(PDRangeArrIndexIsCovered(array, idx));
assert(idx>=array->offset);
assert((idx-array->offset)<array->size);
return &(array->array[idx-(array->offset)]);
}
#endif
/*---------------------------------------------------------------------*/
/* End of File */
/*---------------------------------------------------------------------*/
|