1
#ifndef HEADER_lp_utils
2
#define HEADER_lp_utils
6
#include "lp_fortify.h"
8
#define allocCHAR allocCHAR_FORTIFY
9
#define allocMYBOOL allocMYBOOL_FORTIFY
10
#define allocINT allocINT_FORTIFY
11
#define allocREAL allocREAL_FORTIFY
12
#define allocLREAL allocLREAL_FORTIFY
18
/* Temporary data storage arrays */
19
typedef struct _workarraysrec
30
int size; /* The allocated list size */
31
int count; /* The current entry count */
34
int *map; /* The list of forward and backward-mapped entries */
39
int count; /* The allocated list item count */
40
int *startpos; /* Starting index of the current value */
41
REAL *value; /* The list of forward and backward-mapped entries */
42
struct _PVrec *parent; /* The parent record in a pushed chain */
50
/* Put function headers here */
51
STATIC MYBOOL allocCHAR(lprec *lp, char **ptr, int size, MYBOOL clear);
52
STATIC MYBOOL allocMYBOOL(lprec *lp, MYBOOL **ptr, int size, MYBOOL clear);
53
STATIC MYBOOL allocINT(lprec *lp, int **ptr, int size, MYBOOL clear);
54
STATIC MYBOOL allocREAL(lprec *lp, REAL **ptr, int size, MYBOOL clear);
55
STATIC MYBOOL allocLREAL(lprec *lp, LREAL **ptr, int size, MYBOOL clear);
56
STATIC MYBOOL allocFREE(lprec *lp, void **ptr);
57
REAL *cloneREAL(lprec *lp, REAL *origlist, int size);
58
MYBOOL *cloneMYBOOL(lprec *lp, MYBOOL *origlist, int size);
59
int *cloneINT(lprec *lp, int *origlist, int size);
61
int comp_bits(MYBOOL *bitarray1, MYBOOL *bitarray2, int items);
63
STATIC workarraysrec *mempool_create(lprec *lp);
64
STATIC char *mempool_obtainVector(workarraysrec *mempool, int count, int unitsize);
65
STATIC MYBOOL mempool_releaseVector(workarraysrec *mempool, char *memvector, MYBOOL forcefree);
66
STATIC MYBOOL mempool_free(workarraysrec **mempool);
68
STATIC void roundVector(LREAL *myvector, int endpos, LREAL roundzero);
69
STATIC REAL normalizeVector(REAL *myvector, int endpos);
71
STATIC void swapINT(int *item1, int *item2);
72
STATIC void swapREAL(REAL *item1, REAL *item2);
73
STATIC void swapPTR(void **item1, void **item2);
74
STATIC REAL restoreINT(REAL valREAL, REAL epsilon);
75
STATIC REAL roundToPrecision(REAL value, REAL precision);
77
STATIC int searchFor(int target, int *attributes, int size, int offset, MYBOOL absolute);
79
STATIC MYBOOL isINT(lprec *lp, REAL value);
80
STATIC MYBOOL isOrigFixed(lprec *lp, int varno);
81
STATIC void chsign_bounds(REAL *lobound, REAL *upbound);
82
STATIC REAL rand_uniform(lprec *lp, REAL range);
84
/* Doubly linked list routines */
85
STATIC int createLink(int size, LLrec **linkmap, MYBOOL *usedpos);
86
STATIC MYBOOL freeLink(LLrec **linkmap);
87
STATIC int sizeLink(LLrec *linkmap);
88
STATIC MYBOOL isActiveLink(LLrec *linkmap, int itemnr);
89
STATIC int countActiveLink(LLrec *linkmap);
90
STATIC int countInactiveLink(LLrec *linkmap);
91
STATIC int firstActiveLink(LLrec *linkmap);
92
STATIC int lastActiveLink(LLrec *linkmap);
93
STATIC MYBOOL appendLink(LLrec *linkmap, int newitem);
94
STATIC MYBOOL insertLink(LLrec *linkmap, int afteritem, int newitem);
95
STATIC MYBOOL setLink(LLrec *linkmap, int newitem);
96
STATIC MYBOOL fillLink(LLrec *linkmap);
97
STATIC int nextActiveLink(LLrec *linkmap, int backitemnr);
98
STATIC int prevActiveLink(LLrec *linkmap, int forwitemnr);
99
STATIC int firstInactiveLink(LLrec *linkmap);
100
STATIC int lastInactiveLink(LLrec *linkmap);
101
STATIC int nextInactiveLink(LLrec *linkmap, int backitemnr);
102
STATIC int prevInactiveLink(LLrec *linkmap, int forwitemnr);
103
STATIC int removeLink(LLrec *linkmap, int itemnr);
104
STATIC LLrec *cloneLink(LLrec *sourcemap, int newsize, MYBOOL freesource);
105
STATIC int compareLink(LLrec *linkmap1, LLrec *linkmap2);
106
STATIC MYBOOL verifyLink(LLrec *linkmap, int itemnr, MYBOOL doappend);
108
/* Packed vector routines */
109
STATIC PVrec *createPackedVector(int size, REAL *values, int *workvector);
110
STATIC void pushPackedVector(PVrec *PV, PVrec *parent);
111
STATIC MYBOOL unpackPackedVector(PVrec *PV, REAL **target);
112
STATIC REAL getvaluePackedVector(PVrec *PV, int index);
113
STATIC PVrec *popPackedVector(PVrec *PV);
114
STATIC MYBOOL freePackedVector(PVrec **PV);
120
#endif /* HEADER_lp_utils */
124
#if defined CODE_lp_utils && !defined CODE_lp_utils_
127
extern int _Fortify_ret;
131
#define CODE_lp_utils_
138
# define allocCHAR(lp, ptr, size, clear) (Fortify_LINE(__LINE__), Fortify_FILE(__FILE__), _Fortify_ret = allocCHAR_FORTIFY(lp, ptr, size, clear), Fortify_LINE(0), Fortify_FILE(NULL), _Fortify_ret)
139
# define allocMYBOOL(lp, ptr, size, clear) (Fortify_LINE(__LINE__), Fortify_FILE(__FILE__), _Fortify_ret = allocMYBOOL_FORTIFY(lp, ptr, size, clear), Fortify_LINE(0), Fortify_FILE(NULL), _Fortify_ret)
140
# define allocINT(lp, ptr, size, clear) (Fortify_LINE(__LINE__), Fortify_FILE(__FILE__), _Fortify_ret = allocINT_FORTIFY(lp, ptr, size, clear), Fortify_LINE(0), Fortify_FILE(NULL), _Fortify_ret)
141
# define allocREAL(lp, ptr, size, clear) (Fortify_LINE(__LINE__), Fortify_FILE(__FILE__), _Fortify_ret = allocREAL_FORTIFY(lp, ptr, size, clear), Fortify_LINE(0), Fortify_FILE(NULL), _Fortify_ret)
142
# define allocLREAL(lp, ptr, size, clear) (Fortify_LINE(__LINE__), Fortify_FILE(__FILE__), _Fortify_ret = allocLREAL_FORTIFY(lp, ptr, size, clear), Fortify_LINE(0), Fortify_FILE(NULL), _Fortify_ret)