CoinUtils 2.11.4
Loading...
Searching...
No Matches
CoinIndexedVector.hpp
Go to the documentation of this file.
1/* $Id$ */
2// Copyright (C) 2000, International Business Machines
3// Corporation and others. All Rights Reserved.
4// This code is licensed under the terms of the Eclipse Public License (EPL).
5
6#ifndef CoinIndexedVector_H
7#define CoinIndexedVector_H
8
9#if defined(_MSC_VER)
10// Turn off compiler warning about long names
11#pragma warning(disable : 4786)
12#endif
13
14#include <map>
15#include "CoinFinite.hpp"
16#ifndef CLP_NO_VECTOR
18#endif
19#include "CoinSort.hpp"
21#include <cassert>
22
23#ifndef COIN_FLOAT
24#define COIN_INDEXED_TINY_ELEMENT 1.0e-50
25#define COIN_INDEXED_REALLY_TINY_ELEMENT 1.0e-100
26#else
27#define COIN_INDEXED_TINY_ELEMENT 1.0e-35
28#define COIN_INDEXED_REALLY_TINY_ELEMENT 1.0e-39
29#endif
30
106
107public:
111 inline int getNumElements() const { return nElements_; }
113 inline const int *getIndices() const { return indices_; }
115 // ** No longer supported virtual const double * getElements() const ;
117 inline int *getIndices() { return indices_; }
121 inline double *denseVector() const { return elements_; }
123 inline void setDenseVector(double *array)
124 {
125 elements_ = array;
126 }
128 inline void setIndexVector(int *array)
129 {
130 indices_ = array;
131 }
134 double &operator[](int i) const;
135
137
138 //-------------------------------------------------------------------
139 // Set indices and elements
140 //-------------------------------------------------------------------
143
144 inline void setNumElements(int value)
145 {
146 nElements_ = value;
147 if (!nElements_)
148 packedMode_ = false;
149 }
151 void clear();
153 void empty();
158#ifndef CLP_NO_VECTOR
162#endif
166 void copy(const CoinIndexedVector &rhs, double multiplier = 1.0);
167
170 void borrowVector(int size, int numberIndices, int *inds, double *elems);
171
176
181 void setVector(int numberIndices, const int *inds, const double *elems);
182
187 void setVector(int size, int numberIndices, const int *inds, const double *elems);
188
190 void setConstant(int size, const int *inds, double elems);
191
193 void setFull(int size, const double *elems);
194
198 void setElement(int index, double element);
199
201 void insert(int index, double element);
203 inline void quickInsert(int index, double element)
204 {
205 assert(!elements_[index]);
206 indices_[nElements_++] = index;
207 assert(nElements_ <= capacity_);
208 elements_[index] = element;
209 }
212 void add(int index, double element);
216 inline void quickAdd(int index, double element)
217 {
218 if (elements_[index]) {
219 element += elements_[index];
220 if ((element > 0 ? element : -element) >= COIN_INDEXED_TINY_ELEMENT) {
221 elements_[index] = element;
222 } else {
223 elements_[index] = 1.0e-100;
224 }
225 } else if ((element > 0 ? element : -element) >= COIN_INDEXED_TINY_ELEMENT) {
226 indices_[nElements_++] = index;
227 assert(nElements_ <= capacity_);
228 elements_[index] = element;
229 }
230 }
235 inline void quickAddNonZero(int index, double element)
236 {
237 assert(element);
238 if (elements_[index]) {
239 element += elements_[index];
240 if ((element > 0 ? element : -element) >= COIN_INDEXED_TINY_ELEMENT) {
241 elements_[index] = element;
242 } else {
243 elements_[index] = COIN_DBL_MIN;
244 }
245 } else {
246 indices_[nElements_++] = index;
247 assert(nElements_ <= capacity_);
248 elements_[index] = element;
249 }
250 }
253 inline void zero(int index)
254 {
255 if (elements_[index])
256 elements_[index] = COIN_DBL_MIN;
257 }
260 int clean(double tolerance);
262 int cleanAndPack(double tolerance);
264 int cleanAndPackSafe(double tolerance);
266 inline void setPacked()
267 {
268 packedMode_ = true;
269 }
270#ifndef NDEBUG
275#else
276 inline void checkClear() {};
277 inline void checkClean() {};
278#endif
280 int scan();
284 int scan(int start, int end);
287 int scan(double tolerance);
291 int scan(int start, int end, double tolerance);
294 int scanAndPack(int start, int end);
295 int scanAndPack(double tolerance);
296 int scanAndPack(int start, int end, double tolerance);
298 void createPacked(int number, const int *indices,
299 const double *elements);
301 void createUnpacked(int number, const int *indices,
302 const double *elements);
304 void createOneUnpackedElement(int index, double element);
306 void expand();
307#ifndef CLP_NO_VECTOR
309 void append(const CoinPackedVectorBase &caboose);
310#endif
312 void append(const CoinIndexedVector &caboose);
314 void append(CoinIndexedVector &other, int adjustIndex, bool zapElements = false);
315
317 void swap(int i, int j);
318
320 void truncate(int newSize);
322 void print() const;
324
327 void operator+=(double value);
329 void operator-=(double value);
331 void operator*=(double value);
333 void operator/=(double value);
335
338#ifndef CLP_NO_VECTOR
341 bool operator==(const CoinPackedVectorBase &rhs) const;
343 bool operator!=(const CoinPackedVectorBase &rhs) const;
344#endif
347 bool operator==(const CoinIndexedVector &rhs) const;
349 bool operator!=(const CoinIndexedVector &rhs) const;
351 int isApproximatelyEqual(const CoinIndexedVector &rhs, double tolerance = 1.0e-8) const;
353
357 int getMaxIndex() const;
359 int getMinIndex() const;
361
365 void sort()
366 {
367 std::sort(indices_, indices_ + nElements_);
368 }
369
371 {
372 std::sort(indices_, indices_ + nElements_);
373 }
374
376
378
381
383
384 //#############################################################################
385
399 const CoinIndexedVector &op2);
400
403 const CoinIndexedVector &op2);
404
407 const CoinIndexedVector &op2);
408
411 const CoinIndexedVector &op2);
414
417
420
424
431 void reserve(int n);
435 inline int capacity() const { return capacity_; }
436 inline void setCapacity(int value)
437 {
438 capacity_ = value;
439 }
441 inline void setPackedMode(bool yesNo)
442 {
443 packedMode_ = yesNo;
444 }
446 inline bool packedMode() const
447 {
448 return packedMode_;
449 }
451
457 CoinIndexedVector(int size, const int *inds, const double *elems);
459 CoinIndexedVector(int size, const int *inds, double element);
462 CoinIndexedVector(int size, const double *elements);
469#ifndef CLP_NO_VECTOR
472#endif
476
477private:
481 void gutsOfSetVector(int size,
482 const int *inds, const double *elems);
483 void gutsOfSetVector(int size, int numberIndices,
484 const int *inds, const double *elems);
485 void gutsOfSetPackedVector(int size, int numberIndices,
486 const int *inds, const double *elems);
488 void gutsOfSetConstant(int size,
489 const int *inds, double value);
491
492protected:
498 double *elements_;
508};
509
510//#############################################################################
534
535public:
539 inline CoinBigIndex getSize() const
540 {
541 return static_cast< CoinBigIndex >(size_);
542 }
544 inline CoinBigIndex rawSize() const
545 {
546 return static_cast< CoinBigIndex >(size_);
547 }
549 inline bool switchedOn() const
550 {
551 return size_ != -1;
552 }
554 inline CoinBigIndex capacity() const
555 {
556 return (size_ > -2) ? static_cast< CoinBigIndex >(size_) : static_cast< CoinBigIndex >((-size_) - 2);
557 }
559 inline void setCapacity()
560 {
561 if (size_ <= -2)
562 size_ = (-size_) - 2;
563 }
565 inline const char *array() const
566 {
567 return (size_ > -2) ? array_ : NULL;
568 }
570
574 inline void setSize(int value)
575 {
576 size_ = value;
577 }
578#if COIN_BIG_INDEX
580 inline void setSize(long long value)
581 {
582 size_ = value;
583 }
584#endif
586 inline void switchOff()
587 {
588 size_ = -1;
589 }
591 inline void switchOn(int alignment = 3)
592 {
593 size_ = -2;
594 alignment_ = alignment;
595 }
597 void setPersistence(int flag, int currentLength);
599 void clear();
603 void extend(int newSize);
604#if COIN_BIG_INDEX
606 void extend(long long newSize);
607#endif
609
613 char *conditionalNew(CoinBigIndex sizeWanted);
617
622 : array_(NULL)
623 , size_(-1)
624 , offset_(0)
625 , alignment_(0)
626 {
627 }
630 : size_(-1)
631 , offset_(0)
632 , alignment_(0)
633 {
634 array_ = new char[size];
635 }
650 void copy(const CoinArrayWithLength &rhs, int numberBytes = -1);
652 void allocate(const CoinArrayWithLength &rhs, CoinBigIndex numberBytes);
660 void getCapacity(CoinBigIndex numberBytes, CoinBigIndex numberIfNeeded = -1);
662
663protected:
667 char *array_;
675};
677
679
680public:
684 inline CoinBigIndex getSize() const
685 {
686 return size_ / CoinSizeofAsInt(double);
687 }
689 inline double *array() const
690 {
691 return reinterpret_cast< double * >((size_ > -2) ? array_ : NULL);
692 }
694
698 inline void setSize(int value)
699 {
700 size_ = value * CoinSizeofAsInt(double);
701 }
703
707 inline double *conditionalNew(CoinBigIndex sizeWanted)
708 {
709 return reinterpret_cast< double * >(CoinArrayWithLength::conditionalNew(sizeWanted >= 0 ? static_cast< long long >((sizeWanted)*CoinSizeofAsInt(double)) : -1));
710 }
712
717 {
718 array_ = NULL;
719 size_ = -1;
720 }
723 {
724 array_ = new char[size * CoinSizeofAsInt(double)];
725 size_ = -1;
726 }
731 inline CoinDoubleArrayWithLength(int size, int mode)
732 : CoinArrayWithLength(size * CoinSizeofAsInt(double), mode)
733 {
734 }
738 {
739 }
743 {
744 }
747 {
749 return *this;
750 }
752};
754
756
757public:
761 inline CoinBigIndex getSize() const
762 {
764 }
767 {
768 return reinterpret_cast< CoinFactorizationDouble * >((size_ > -2) ? array_ : NULL);
769 }
771
775 inline void setSize(int value)
776 {
778 }
780
785 {
786 return reinterpret_cast< CoinFactorizationDouble * >(CoinArrayWithLength::conditionalNew(sizeWanted >= 0 ? static_cast< long long >((sizeWanted)*CoinSizeofAsInt(CoinFactorizationDouble)) : -1));
787 }
789
794 {
795 array_ = NULL;
796 size_ = -1;
797 }
800 {
802 size_ = -1;
803 }
808 inline CoinFactorizationDoubleArrayWithLength(int size, int mode)
810 {
811 }
815 {
816 }
820 {
821 }
824 {
826 return *this;
827 }
829};
831
833
834public:
838 inline CoinBigIndex getSize() const
839 {
840 return size_ / CoinSizeofAsInt(long double);
841 }
843 inline long double *array() const
844 {
845 return reinterpret_cast< long double * >((size_ > -2) ? array_ : NULL);
846 }
848
852 inline void setSize(int value)
853 {
854 size_ = value * CoinSizeofAsInt(long double);
855 }
857
861 inline long double *conditionalNew(CoinBigIndex sizeWanted)
862 {
863 return reinterpret_cast< long double * >(CoinArrayWithLength::conditionalNew(sizeWanted >= 0 ? static_cast< long long >((sizeWanted)*CoinSizeofAsInt(long double)) : -1));
864 }
866
871 {
872 array_ = NULL;
873 size_ = -1;
874 }
877 {
878 array_ = new char[size * CoinSizeofAsInt(long double)];
879 size_ = -1;
880 }
886 : CoinArrayWithLength(size * CoinSizeofAsInt(long double), mode)
887 {
888 }
892 {
893 }
897 {
898 }
901 {
903 return *this;
904 }
906};
908
910
911public:
915 inline CoinBigIndex getSize() const
916 {
917 return size_ / CoinSizeofAsInt(int);
918 }
920 inline int *array() const
921 {
922 return reinterpret_cast< int * >((size_ > -2) ? array_ : NULL);
923 }
925
929 inline void setSize(int value)
930 {
931 size_ = value * CoinSizeofAsInt(int);
932 }
934
938 inline int *conditionalNew(CoinBigIndex sizeWanted)
939 {
940 return reinterpret_cast< int * >(CoinArrayWithLength::conditionalNew(sizeWanted >= 0 ? static_cast< long long >((sizeWanted)*CoinSizeofAsInt(int)) : -1));
941 }
943
948 {
949 array_ = NULL;
950 size_ = -1;
951 }
953 inline CoinIntArrayWithLength(int size)
954 {
955 array_ = new char[size * CoinSizeofAsInt(int)];
956 size_ = -1;
957 }
962 inline CoinIntArrayWithLength(int size, int mode)
963 : CoinArrayWithLength(size * CoinSizeofAsInt(int), mode)
964 {
965 }
969 {
970 }
974 {
975 }
978 {
980 return *this;
981 }
983};
985
987
988public:
992 inline CoinBigIndex getSize() const
993 {
995 }
997 inline CoinBigIndex *array() const
998 {
999 return reinterpret_cast< CoinBigIndex * >((size_ > -2) ? array_ : NULL);
1000 }
1002
1006 inline void setSize(CoinBigIndex value)
1007 {
1009 }
1011
1016 {
1017 return reinterpret_cast< CoinBigIndex * >(CoinArrayWithLength::conditionalNew(sizeWanted >= 0 ? static_cast< long long >((sizeWanted)*CoinSizeofAsInt(CoinBigIndex)) : -1));
1018 }
1020
1025 {
1026 array_ = NULL;
1027 size_ = -1;
1028 }
1031 {
1032 array_ = new char[size * CoinSizeofAsInt(CoinBigIndex)];
1033 size_ = -1;
1034 }
1041 {
1042 }
1045 : CoinArrayWithLength(rhs)
1046 {
1047 }
1050 : CoinArrayWithLength(rhs)
1051 {
1052 }
1055 {
1057 return *this;
1058 }
1060};
1062
1064
1065public:
1069 inline CoinBigIndex getSize() const
1070 {
1071 return size_ / CoinSizeofAsInt(unsigned int);
1072 }
1074 inline unsigned int *array() const
1075 {
1076 return reinterpret_cast< unsigned int * >((size_ > -2) ? array_ : NULL);
1077 }
1079
1083 inline void setSize(int value)
1084 {
1085 size_ = value * CoinSizeofAsInt(unsigned int);
1086 }
1088
1092 inline unsigned int *conditionalNew(CoinBigIndex sizeWanted)
1093 {
1094 return reinterpret_cast< unsigned int * >(CoinArrayWithLength::conditionalNew(sizeWanted >= 0 ? static_cast< long long >((sizeWanted)*CoinSizeofAsInt(unsigned int)) : -1));
1095 }
1097
1102 {
1103 array_ = NULL;
1104 size_ = -1;
1105 }
1108 {
1109 array_ = new char[size * CoinSizeofAsInt(unsigned int)];
1110 size_ = -1;
1111 }
1116 inline CoinUnsignedIntArrayWithLength(int size, int mode)
1117 : CoinArrayWithLength(size * CoinSizeofAsInt(unsigned int), mode)
1118 {
1119 }
1122 : CoinArrayWithLength(rhs)
1123 {
1124 }
1127 : CoinArrayWithLength(rhs)
1128 {
1129 }
1132 {
1134 return *this;
1135 }
1137};
1139
1141
1142public:
1146 inline CoinBigIndex getSize() const
1147 {
1148 return size_ / CoinSizeofAsInt(void *);
1149 }
1151 inline void **array() const
1152 {
1153 return reinterpret_cast< void ** >((size_ > -2) ? array_ : NULL);
1154 }
1156
1160 inline void setSize(int value)
1161 {
1162 size_ = value * CoinSizeofAsInt(void *);
1163 }
1165
1169 inline void **conditionalNew(CoinBigIndex sizeWanted)
1170 {
1171 return reinterpret_cast< void ** >(CoinArrayWithLength::conditionalNew(sizeWanted >= 0 ? static_cast< long long >((sizeWanted)*CoinSizeofAsInt(void *)) : -1));
1172 }
1174
1179 {
1180 array_ = NULL;
1181 size_ = -1;
1182 }
1185 {
1186 array_ = new char[size * CoinSizeofAsInt(void *)];
1187 size_ = -1;
1188 }
1193 inline CoinVoidStarArrayWithLength(int size, int mode)
1194 : CoinArrayWithLength(size * CoinSizeofAsInt(void *), mode)
1195 {
1196 }
1199 : CoinArrayWithLength(rhs)
1200 {
1201 }
1204 : CoinArrayWithLength(rhs)
1205 {
1206 }
1209 {
1211 return *this;
1212 }
1214};
1216
1218
1219public:
1223 inline CoinBigIndex getSize() const
1224 {
1225 return size_ / lengthInBytes_;
1226 }
1228 inline void **array() const
1229 {
1230 return reinterpret_cast< void ** >((size_ > -2) ? array_ : NULL);
1231 }
1233
1237 inline void setSize(int value)
1238 {
1239 size_ = value * lengthInBytes_;
1240 }
1242
1246 inline char *conditionalNew(CoinBigIndex length, CoinBigIndex sizeWanted)
1247 {
1248 lengthInBytes_ = length;
1249 return reinterpret_cast< char * >(CoinArrayWithLength::conditionalNew(sizeWanted >= 0 ? static_cast< long long >((sizeWanted)*lengthInBytes_) : -1));
1250 }
1252
1256 inline CoinArbitraryArrayWithLength(int length = 1)
1257 {
1258 array_ = NULL;
1259 size_ = -1;
1260 lengthInBytes_ = length;
1261 }
1263 inline CoinArbitraryArrayWithLength(int length, int size)
1264 {
1265 array_ = new char[size * length];
1266 size_ = -1;
1267 lengthInBytes_ = length;
1268 }
1273 inline CoinArbitraryArrayWithLength(int length, int size, int mode)
1274 : CoinArrayWithLength(size * length, mode)
1275 {
1276 lengthInBytes_ = length;
1277 }
1280 : CoinArrayWithLength(rhs)
1281 {
1282 }
1285 : CoinArrayWithLength(rhs)
1286 {
1287 }
1290 {
1292 return *this;
1293 }
1295
1296protected:
1302};
1304
1305public:
1306#ifndef COIN_PARTITIONS
1307#define COIN_PARTITIONS 8
1308#endif
1312 inline int getNumElements(int partition) const
1313 {
1314 assert(partition < COIN_PARTITIONS);
1315 return numberElementsPartition_[partition];
1316 }
1318 inline int getNumPartitions() const
1319 {
1320 return numberPartitions_;
1321 }
1323 inline int getNumElements() const { return nElements_; }
1325 inline int startPartition(int partition) const
1326 {
1327 assert(partition <= COIN_PARTITIONS);
1328 return startPartition_[partition];
1329 }
1331 inline const int *startPartitions() const
1332 {
1333 return startPartition_;
1334 }
1336
1337 //-------------------------------------------------------------------
1338 // Set indices and elements
1339 //-------------------------------------------------------------------
1342
1343 inline void setNumElementsPartition(int partition, int value)
1344 {
1345 assert(partition < COIN_PARTITIONS);
1347 numberElementsPartition_[partition] = value;
1348 }
1350 inline void setTempNumElementsPartition(int partition, int value)
1351 {
1352 assert(partition < COIN_PARTITIONS);
1353 numberElementsPartition_[partition] = value;
1354 }
1358 void compact();
1361 void reserve(int n);
1363 void setPartitions(int number, const int *starts);
1369 void clearPartition(int partition);
1370#ifndef NDEBUG
1375#else
1376 inline void checkClear() {};
1377 inline void checkClean() {};
1378#endif
1380 int scan(int partition, double tolerance = 0.0);
1385 void print() const;
1387
1391 void sort();
1393
1399 CoinPartitionedVector(int size, const int *inds, const double *elems);
1401 CoinPartitionedVector(int size, const int *inds, double element);
1404 CoinPartitionedVector(int size, const double *elements);
1416protected:
1426};
1427inline double *roundUpDouble(double *address)
1428{
1429 // align on 64 byte boundary
1430 CoinInt64 xx = reinterpret_cast< CoinInt64 >(address);
1431 int iBottom = static_cast< int >(xx & 63);
1432 if (iBottom)
1433 return address + ((64 - iBottom) >> 3);
1434 else
1435 return address;
1436}
1437#endif
const double COIN_DBL_MIN
Definition: CoinFinite.hpp:17
#define CoinSizeofAsInt(type)
Cube Root.
void CoinIndexedVectorUnitTest()
A function that tests the methods in the CoinIndexedVector class.
#define COIN_PARTITIONS
double * roundUpDouble(double *address)
#define COIN_INDEXED_TINY_ELEMENT
double CoinFactorizationDouble
Definition: CoinTypes.hpp:57
#define CoinInt64
Definition: CoinTypes.hpp:18
int CoinBigIndex
void ** array() const
Get Array.
CoinArbitraryArrayWithLength(const CoinArbitraryArrayWithLength *rhs)
Copy constructor.2.
CoinArbitraryArrayWithLength(int length=1)
Default constructor - NULL.
CoinBigIndex lengthInBytes_
Length in bytes.
CoinArbitraryArrayWithLength(const CoinArbitraryArrayWithLength &rhs)
Copy constructor.
char * conditionalNew(CoinBigIndex length, CoinBigIndex sizeWanted)
Conditionally gets new array.
CoinArbitraryArrayWithLength(int length, int size)
Alternate Constructor - length in bytes - size_ -1.
CoinArbitraryArrayWithLength(int length, int size, int mode)
Alternate Constructor - length in bytes mode - 0 size_ set to size 1 size_ set to size and zeroed.
CoinArbitraryArrayWithLength & operator=(const CoinArbitraryArrayWithLength &rhs)
Assignment operator.
void setSize(int value)
Set the size.
CoinBigIndex getSize() const
Get the size.
Pointer with length in bytes.
CoinArrayWithLength(CoinBigIndex size, int mode)
Alternate Constructor - length in bytes mode - 0 size_ set to size mode>0 size_ set to size and zeroe...
void allocate(const CoinArrayWithLength &rhs, CoinBigIndex numberBytes)
Assignment with length - does not copy.
void reallyFreeArray()
Really get rid of array with alignment.
void switchOff()
Set the size to -1.
void switchOn(int alignment=3)
Set the size to -2 and alignment.
CoinArrayWithLength(const CoinArrayWithLength &rhs)
Copy constructor.
void copy(const CoinArrayWithLength &rhs, int numberBytes=-1)
Assignment with length (if -1 use internal length)
CoinArrayWithLength()
Default constructor - NULL.
void swap(CoinArrayWithLength &other)
Swaps memory between two members.
void setCapacity()
Set the capacity to >=0 if <=-2.
CoinBigIndex rawSize() const
Get the size.
void conditionalDelete()
Conditionally deletes.
CoinArrayWithLength & operator=(const CoinArrayWithLength &rhs)
Assignment operator.
CoinBigIndex getSize() const
Get the size.
int alignment_
Alignment wanted (power of 2)
void setPersistence(int flag, int currentLength)
Does what is needed to set persistence.
void extend(int newSize)
Extend a persistent array keeping data (size in bytes)
int offset_
Offset of array.
CoinArrayWithLength(const CoinArrayWithLength *rhs)
Copy constructor.2.
~CoinArrayWithLength()
Destructor.
CoinBigIndex capacity() const
Get the capacity (just read it)
void clear()
Zero out array.
CoinBigIndex size_
Size of array in bytes.
bool switchedOn() const
See if persistence already on.
CoinArrayWithLength(CoinBigIndex size)
Alternate Constructor - length in bytes - size_ -1.
void setSize(int value)
Set the size.
char * conditionalNew(CoinBigIndex sizeWanted)
Conditionally gets new array.
const char * array() const
Get Array.
void getCapacity(CoinBigIndex numberBytes, CoinBigIndex numberIfNeeded=-1)
Get enough space (if more needed then do at least needed)
void getArray(CoinBigIndex size)
Get array with alignment.
CoinBigIndex * version.
CoinBigIndexArrayWithLength()
Default constructor - NULL.
CoinBigIndexArrayWithLength(const CoinBigIndexArrayWithLength &rhs)
Copy constructor.
CoinBigIndex * conditionalNew(CoinBigIndex sizeWanted)
Conditionally gets new array.
void setSize(CoinBigIndex value)
Set the size.
CoinBigIndex * array() const
Get Array.
CoinBigIndexArrayWithLength(const CoinBigIndexArrayWithLength *rhs)
Copy constructor.2.
CoinBigIndexArrayWithLength(CoinBigIndex size, int mode)
Alternate Constructor - length in bytes mode - 0 size_ set to size 1 size_ set to size and zeroed.
CoinBigIndexArrayWithLength & operator=(const CoinBigIndexArrayWithLength &rhs)
Assignment operator.
CoinBigIndex getSize() const
Get the size.
CoinBigIndexArrayWithLength(CoinBigIndex size)
Alternate Constructor - length in bytes - size_ -1.
CoinDoubleArrayWithLength()
Default constructor - NULL.
CoinDoubleArrayWithLength & operator=(const CoinDoubleArrayWithLength &rhs)
Assignment operator.
CoinDoubleArrayWithLength(int size, int mode)
Alternate Constructor - length in bytes mode - 0 size_ set to size 1 size_ set to size and zeroed.
CoinBigIndex getSize() const
Get the size.
double * conditionalNew(CoinBigIndex sizeWanted)
Conditionally gets new array.
void setSize(int value)
Set the size.
double * array() const
Get Array.
CoinDoubleArrayWithLength(int size)
Alternate Constructor - length in bytes - size_ -1.
CoinDoubleArrayWithLength(const CoinDoubleArrayWithLength &rhs)
Copy constructor.
CoinDoubleArrayWithLength(const CoinDoubleArrayWithLength *rhs)
Copy constructor.2.
CoinFactorizationDouble * version.
CoinBigIndex getSize() const
Get the size.
CoinFactorizationDoubleArrayWithLength()
Default constructor - NULL.
CoinFactorizationDoubleArrayWithLength(const CoinFactorizationDoubleArrayWithLength &rhs)
Copy constructor.
CoinFactorizationDoubleArrayWithLength & operator=(const CoinFactorizationDoubleArrayWithLength &rhs)
Assignment operator.
CoinFactorizationDouble * array() const
Get Array.
CoinFactorizationDouble * conditionalNew(CoinBigIndex sizeWanted)
Conditionally gets new array.
CoinFactorizationDoubleArrayWithLength(int size)
Alternate Constructor - length in bytes - size_ -1.
CoinFactorizationDoubleArrayWithLength(int size, int mode)
Alternate Constructor - length in bytes mode - 0 size_ set to size 1 size_ set to size and zeroed.
CoinFactorizationDoubleArrayWithLength(const CoinFactorizationDoubleArrayWithLength *rhs)
Copy constructor.2.
void setSize(int value)
Set the size.
CoinFactorizationLongDouble * version.
CoinFactorizationLongDoubleArrayWithLength(const CoinFactorizationLongDoubleArrayWithLength &rhs)
Copy constructor.
CoinBigIndex getSize() const
Get the size.
CoinFactorizationLongDoubleArrayWithLength(const CoinFactorizationLongDoubleArrayWithLength *rhs)
Copy constructor.2.
CoinFactorizationLongDoubleArrayWithLength & operator=(const CoinFactorizationLongDoubleArrayWithLength &rhs)
Assignment operator.
long double * conditionalNew(CoinBigIndex sizeWanted)
Conditionally gets new array.
CoinFactorizationLongDoubleArrayWithLength(int size, int mode)
Alternate Constructor - length in bytes mode - 0 size_ set to size 1 size_ set to size and zeroed.
CoinFactorizationLongDoubleArrayWithLength(int size)
Alternate Constructor - length in bytes - size_ -1.
CoinFactorizationLongDoubleArrayWithLength()
Default constructor - NULL.
int getMaxIndex() const
Get value of maximum index.
int * indices_
Vector indices.
void returnVector()
Return ownership of the arguments to this vector.
void setNumElements(int value)
Set the size.
CoinIndexedVector(int size, const double *elements)
Alternate Constructors - construct full storage with indices 0 through size-1.
CoinIndexedVector(const CoinIndexedVector &)
Copy constructor.
CoinIndexedVector operator-(const CoinIndexedVector &op2)
Return the difference of two indexed vectors.
void gutsOfSetVector(int size, const int *inds, const double *elems)
Copy internal data.
bool operator==(const CoinPackedVectorBase &rhs) const
Equal.
void setVector(int numberIndices, const int *inds, const double *elems)
Set vector numberIndices, indices, and elements.
void append(const CoinPackedVectorBase &caboose)
Append a CoinPackedVector to the end.
int clean(double tolerance)
set all small values to zero and return number remaining
int scanAndPack(int start, int end, double tolerance)
void setPacked()
Mark as packed.
void reallyClear()
Clear even if in a bad way.
CoinIndexedVector(int size, const int *inds, const double *elems)
Alternate Constructors - set elements to vector of doubles.
friend void CoinIndexedVectorUnitTest()
A function that tests the methods in the CoinIndexedVector class.
void setPackedMode(bool yesNo)
Sets packed mode.
double & operator[](int i) const
Access the i'th element of the full storage vector.
int cleanAndPackSafe(double tolerance)
Same but packs down and is safe (i.e. if order is odd)
int isApproximatelyEqual(const CoinIndexedVector &rhs, double tolerance=1.0e-8) const
Equal with a tolerance (returns -1 or position of inequality).
void operator+=(const CoinIndexedVector &op2)
The sum of two indexed vectors.
void setIndexVector(int *array)
For very temporary use when user needs to borrow an index vector.
void createPacked(int number, const int *indices, const double *elements)
Create packed array.
void setElement(int index, double element)
Set an existing element in the indexed vector The first argument is the "index" into the elements() a...
double * elements_
Vector elements.
void empty()
Reset the vector (as if were just created an empty vector)
bool packedMode_
If true then is operating in packed mode.
void gutsOfSetConstant(int size, const int *inds, double value)
void sort()
Sort the indexed storage vector (increasing indices).
void append(CoinIndexedVector &other, int adjustIndex, bool zapElements=false)
Append a CoinIndexedVector to the end and modify indices.
bool operator==(const CoinIndexedVector &rhs) const
Equal.
void zero(int index)
Makes nonzero tiny.
int scan(int start, int end, double tolerance)
Scan dense region from start to < end and set up indices returns number found.
CoinIndexedVector operator+(const CoinIndexedVector &op2)
Return the sum of two indexed vectors.
bool operator!=(const CoinPackedVectorBase &rhs) const
Not equal.
void operator*=(const CoinIndexedVector &op2)
The element-wise product of two indexed vectors.
void checkClean()
For debug check vector is clean i.e. elements match indices.
void quickInsert(int index, double element)
Insert a nonzero element into the vector.
void setFull(int size, const double *elems)
Indices are not specified and are taken to be 0,1,...,size-1.
int scan(int start, int end)
Scan dense region from start to < end and set up indices returns number found.
CoinIndexedVector(const CoinPackedVectorBase &rhs)
Copy constructor from a PackedVectorBase.
void checkClear()
For debug check vector is clear i.e. no elements.
CoinIndexedVector & operator=(const CoinIndexedVector &)
Assignment operator.
void append(const CoinIndexedVector &caboose)
Append a CoinIndexedVector to the end (with extra space)
void setDenseVector(double *array)
For very temporary use when user needs to borrow a dense vector.
void operator+=(double value)
add value to every entry
void borrowVector(int size, int numberIndices, int *inds, double *elems)
Borrow ownership of the arguments to this vector.
int scanAndPack(int start, int end)
int * getIndices()
Get element values.
int capacity() const
capacity returns the size which could be accomodated without having to reallocate storage.
CoinIndexedVector()
Default constructor.
void expand()
This is mainly for testing - goes from packed to indexed.
CoinIndexedVector(int size)
Alternate Constructors - just size.
int scanAndPack(double tolerance)
int scan()
Scan dense region and set up indices (returns number found)
void operator*=(double value)
multiply every entry by value
~CoinIndexedVector()
Destructor.
int getNumElements() const
Get the size.
void operator-=(const CoinIndexedVector &op2)
The difference of two indexed vectors.
int scanAndPack()
These are same but pack down.
void setVector(int size, int numberIndices, const int *inds, const double *elems)
Set vector size, indices, and elements.
void operator-=(double value)
subtract value from every entry
int offset_
Offset to get where new allocated array.
void gutsOfSetVector(int size, int numberIndices, const int *inds, const double *elems)
void gutsOfSetPackedVector(int size, int numberIndices, const int *inds, const double *elems)
void setConstant(int size, const int *inds, double elems)
Elements set to have the same scalar value.
int cleanAndPack(double tolerance)
Same but packs down.
CoinIndexedVector & operator=(const CoinPackedVectorBase &rhs)
Assignment operator from a CoinPackedVectorBase.
int capacity_
Amount of memory allocated for indices_, and elements_.
void add(int index, double element)
Insert or if exists add an element into the vector Any resulting zero elements will be made tiny.
bool operator!=(const CoinIndexedVector &rhs) const
Not equal.
void reserve(int n)
Reserve space.
double * denseVector() const
Get the vector as a dense vector.
CoinIndexedVector operator/(const CoinIndexedVector &op2)
Return the element-wise ratio of two indexed vectors (0.0/0.0 => 0.0) (0 vanishes)
CoinIndexedVector operator*(const CoinIndexedVector &op2)
Return the element-wise product of two indexed vectors.
bool packedMode() const
Gets packed mode.
void truncate(int newSize)
Throw away all entries in rows >= newSize.
CoinIndexedVector(const CoinIndexedVector *)
Copy constructor.2.
int getMinIndex() const
Get value of minimum index.
void swap(int i, int j)
Swap values in positions i and j of indices and elements.
void clear()
Reset the vector (as if were just created an empty vector). This leaves arrays!
void operator/=(const CoinIndexedVector &op2)
The element-wise ratio of two indexed vectors (0.0/0.0 => 0.0) (0 vanishes)
void copy(const CoinIndexedVector &rhs, double multiplier=1.0)
Copy the contents of one vector into another.
void quickAdd(int index, double element)
Insert or if exists add an element into the vector Any resulting zero elements will be made tiny.
void insert(int index, double element)
Insert an element into the vector.
void print() const
Print out.
void createUnpacked(int number, const int *indices, const double *elements)
Create unpacked array.
CoinIndexedVector(int size, const int *inds, double element)
Alternate Constructors - set elements to same scalar value.
void setCapacity(int value)
int nElements_
Size of indices and packed elements vectors.
int scan(double tolerance)
Scan dense region and set up indices (returns number found).
const int * getIndices() const
Get indices of elements.
void operator/=(double value)
divide every entry by value (** 0 vanishes)
void createOneUnpackedElement(int index, double element)
Create unpacked singleton.
void quickAddNonZero(int index, double element)
Insert or if exists add an element into the vector Any resulting zero elements will be made tiny.
CoinIntArrayWithLength(const CoinIntArrayWithLength *rhs)
Copy constructor.2.
CoinBigIndex getSize() const
Get the size.
CoinIntArrayWithLength(const CoinIntArrayWithLength &rhs)
Copy constructor.
int * array() const
Get Array.
CoinIntArrayWithLength(int size)
Alternate Constructor - length in bytes - size_ -1.
CoinIntArrayWithLength & operator=(const CoinIntArrayWithLength &rhs)
Assignment operator.
void setSize(int value)
Set the size.
int * conditionalNew(CoinBigIndex sizeWanted)
Conditionally gets new array.
CoinIntArrayWithLength(int size, int mode)
Alternate Constructor - length in bytes mode - 0 size_ set to size 1 size_ set to size and zeroed.
CoinIntArrayWithLength()
Default constructor - NULL.
Abstract base class for various sparse vectors.
CoinPartitionedVector()
Default constructor.
int startPartition_[COIN_PARTITIONS+1]
Starts.
void computeNumberElements()
Add up number of elements in partitions.
CoinPartitionedVector(const CoinPartitionedVector *)
Copy constructor.2.
CoinPartitionedVector(const CoinPartitionedVector &)
Copy constructor.
CoinPartitionedVector & operator=(const CoinPartitionedVector &)
Assignment operator.
int getNumElements(int partition) const
Get the size of a partition.
~CoinPartitionedVector()
Destructor.
void print() const
Scan dense region from start to < end and set up indices returns number found.
void compact()
Add up number of elements in partitions and pack and get rid of partitions.
int getNumPartitions() const
Get number of partitions.
void reserve(int n)
Reserve space.
int scan(int partition, double tolerance=0.0)
Scan dense region and set up indices (returns number found)
void sort()
Sort the indexed storage vector (increasing indices).
int numberPartitions_
Number of partitions (0 means off)
void clearPartition(int partition)
Clear a partition.
void setPartitions(int number, const int *starts)
Setup partitions (needs end as well)
CoinPartitionedVector(int size, const int *inds, const double *elems)
Alternate Constructors - set elements to vector of doubles.
void setTempNumElementsPartition(int partition, int value)
Set the size of a partition (just for a tiny while)
void checkClean()
For debug check vector is clean i.e. elements match indices.
CoinPartitionedVector(int size, const int *inds, double element)
Alternate Constructors - set elements to same scalar value.
void checkClear()
For debug check vector is clear i.e. no elements.
void setNumElementsPartition(int partition, int value)
Set the size of a partition.
int getNumElements() const
Get the size.
CoinPartitionedVector(int size)
Alternate Constructors - just size.
const int * startPartitions() const
Get starts.
CoinPartitionedVector(int size, const double *elements)
Alternate Constructors - construct full storage with indices 0 through size-1.
void clearAndKeep()
Reset the vector (as if were just created an empty vector). Keeps partitions.
void clearAndReset()
Reset the vector (as if were just created an empty vector). Gets rid of partitions.
int numberElementsPartition_[COIN_PARTITIONS]
Size of indices in a partition.
int startPartition(int partition) const
Get starts.
unsigned int * array() const
Get Array.
CoinUnsignedIntArrayWithLength(int size)
Alternate Constructor - length in bytes - size_ -1.
void setSize(int value)
Set the size.
CoinUnsignedIntArrayWithLength()
Default constructor - NULL.
unsigned int * conditionalNew(CoinBigIndex sizeWanted)
Conditionally gets new array.
CoinUnsignedIntArrayWithLength(const CoinUnsignedIntArrayWithLength &rhs)
Copy constructor.
CoinUnsignedIntArrayWithLength(const CoinUnsignedIntArrayWithLength *rhs)
Copy constructor.2.
CoinUnsignedIntArrayWithLength & operator=(const CoinUnsignedIntArrayWithLength &rhs)
Assignment operator.
CoinUnsignedIntArrayWithLength(int size, int mode)
Alternate Constructor - length in bytes mode - 0 size_ set to size 1 size_ set to size and zeroed.
CoinBigIndex getSize() const
Get the size.
CoinBigIndex getSize() const
Get the size.
CoinVoidStarArrayWithLength & operator=(const CoinVoidStarArrayWithLength &rhs)
Assignment operator.
CoinVoidStarArrayWithLength(int size)
Alternate Constructor - length in bytes - size_ -1.
void ** conditionalNew(CoinBigIndex sizeWanted)
Conditionally gets new array.
CoinVoidStarArrayWithLength(const CoinVoidStarArrayWithLength *rhs)
Copy constructor.2.
CoinVoidStarArrayWithLength(const CoinVoidStarArrayWithLength &rhs)
Copy constructor.
void setSize(int value)
Set the size.
CoinVoidStarArrayWithLength(int size, int mode)
Alternate Constructor - length in bytes mode - 0 size_ set to size 1 size_ set to size and zeroed.
void ** array() const
Get Array.
CoinVoidStarArrayWithLength()
Default constructor - NULL.