1 /*-----------------------------------------------------------------------
2
3 File : clb_pdarrays.h
4
5 Author: Stephan Schulz
6
7 Contents
8
9 Dynamic arrays of pointers and long integers. You can define the
10 growth behaviour by specifying a value. If it is GROW_EXPONENTIAL,
11 arrays will always grow by a factor that is the lowest power of two
12 that will make the array big enough. Otherwise it will grow by the
13 smallest multiple of the value specified that creates the requested
14 position.
15
16 Copyright 1998, 1999, 2004 by the author.
17 This code is released under the GNU General Public Licence and
18 the GNU Lesser General Public License.
19 See the file COPYING in the main E directory for details..
20 Run "eprover -h" for contact information.
21
22 Changes
23
24 <1> Wed Jul 22 21:34:41 MET DST 1998
25 New
26 <2> Tue Mar 23 00:30:16 CET 2004
27 Added comments about growth behaviour.
28
29 -----------------------------------------------------------------------*/
30
31 #ifndef CLB_PDARRAYS
32
33 #define CLB_PDARRAYS
34
35 #include <clb_memory.h>
36
37
38 /*---------------------------------------------------------------------*/
39 /* Data type declarations */
40 /*---------------------------------------------------------------------*/
41
42 typedef struct pdarraycell
43 {
44 bool integer;
45 long size;
46 long grow;
47 IntOrP *array;
48 }PDArrayCell, *PDArray_p;
49
50 #define GROW_EXPONENTIAL 0
51
52 /*---------------------------------------------------------------------*/
53 /* Exported Functions and Variables */
54 /*---------------------------------------------------------------------*/
55
56 #define PDArrayCellAlloc() (PDArrayCell*)SizeMalloc(sizeof(PDArrayCell))
57 #define PDArrayCellFree(junk) SizeFree(junk, sizeof(PDArrayCell))
58
59 #ifdef CONSTANT_MEM_ESTIMATE
60 #define PDARRAYCELL_MEM 20
61 #else
62 #define PDARRAYCELL_MEM MEMSIZE(PDArrayCell)
63 #endif
64 #define PDArrayStorage(arr) (PDARRAYCELL_MEM+INTORP_MEM+((arr)->size*INTORP_MEM))
65
66 PDArray_p PDArrayAlloc(long init_size, long grow);
67 PDArray_p PDIntArrayAlloc(long init_size, long grow);
68 void PDArrayFree(PDArray_p junk);
69 #define PDArraySize(array) ((array)->size)
70
71 PDArray_p PDArrayCopy(PDArray_p array);
72
73 void PDArrayEnlarge(PDArray_p array, long idx);
74 static __inline__ IntOrP* PDArrayElementRef(PDArray_p array, long idx);
75
76 void PDArrayElementDeleteP(PDArray_p array, long idx);
77 void PDArrayElementDeleteInt(PDArray_p array, long idx);
78
79 #define PDArrayElementClear(arr, idx) ((arr)->array[(idx)].p_val = NULL)
80 #define PDArrayAssign(array, idx, value) \
81 *PDArrayElementRef((array), (idx)) = (value)
82 #define PDArrayAssignP(array, idx, value) \
83 PDArrayElementRef((array), (idx))->p_val = (value)
84 #define PDArrayAssignInt(array, idx, value) \
85 PDArrayElementRef((array), (idx))->i_val = (value)
86
87 #define PDArrayElement(array, idx) \
88 *PDArrayElementRef((array), (idx))
89 #define PDArrayElementP(array, idx) \
90 (PDArrayElementRef((array), (idx))->p_val)
91 #define PDArrayElementInt(array, idx) \
92 (PDArrayElementRef((array), (idx))->i_val)
93
94 long PDArrayMembers(PDArray_p array);
95 long PDArrayFirstUnused(PDArray_p array);
96 long PDArrayStore(PDArray_p array, IntOrP value);
97 long PDArrayStoreP(PDArray_p array, void* value);
98 long PDArrayStoreInt(PDArray_p array, long value);
99 void PDArrayAdd(PDArray_p collect, PDArray_p data, long limit);
100
101 long PDArrayElementIncInt(PDArray_p array, long idx, long value);
102
103 /*---------------------------------------------------------------------*/
104 /* Inline functions */
105 /*---------------------------------------------------------------------*/
106
107
108 /*-----------------------------------------------------------------------
109 //
110 // Function: PDArrayElementRef()
111 //
112 // Return a reference to an element in a dynamic array. This
113 // reference is only good until the next call to this function! User
114 // programs are expected to use this function only extremely rarely
115 // and with special care. Use PDArrayElement()/PDArrayAssign()
116 // instead.
117 //
118 // Global Variables: -
119 //
120 // Side Effects : May enlarge and move array.
121 //
122 /----------------------------------------------------------------------*/
123
PDArrayElementRef(PDArray_p array,long idx)124 static __inline__ IntOrP* PDArrayElementRef(PDArray_p array, long idx)
125 {
126 assert(array);
127 assert(idx >= 0);
128
129 if(UNLIKELY(idx >= array->size))
130 {
131 PDArrayEnlarge(array, idx);
132 }
133 return &(array->array[idx]);
134 }
135
136 #endif
137
138 /*---------------------------------------------------------------------*/
139 /* End of File */
140 /*---------------------------------------------------------------------*/
141
142
143
144
145
146