Cbc  2.10.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CoinIndexedVector.hpp
Go to the documentation of this file.
1 /* $Id: CoinIndexedVector.hpp 2084 2019-01-09 14:17:08Z forrest $ */
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
17 #include "CoinPackedVectorBase.hpp"
18 #endif
19 #include "CoinSort.hpp"
20 #include "CoinHelperFunctions.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 
105  friend void CoinIndexedVectorUnitTest();
106 
107 public:
110  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  inline void setNumElements(int value)
145  {
146  nElements_ = value;
147  if (!nElements_)
148  packedMode_ = false;
149  }
151  void clear();
153  void empty();
155  void reallyClear();
158 #ifndef CLP_NO_VECTOR
159 
162 #endif
163 
166  void copy(const CoinIndexedVector &rhs, double multiplier = 1.0);
167 
170  void borrowVector(int size, int numberIndices, int *inds, double *elems);
171 
175  void returnVector();
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
271  void checkClear();
274  void checkClean();
275 #else
276  inline void checkClear() {};
277  inline void checkClean() {};
278 #endif
279  int scan();
284  int scan(int start, int end);
287  int scan(double tolerance);
291  int scan(int start, int end, double tolerance);
293  int scanAndPack();
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
308  void append(const CoinPackedVectorBase &caboose);
310 #endif
311  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 
326  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
339 
341  bool operator==(const CoinPackedVectorBase &rhs) const;
343  bool operator!=(const CoinPackedVectorBase &rhs) const;
344 #endif
345 
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 
356  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 
375  void sortDecrIndex();
376 
377  void sortIncrElement();
378 
379  void sortDecrElement();
380  void sortPacked();
381 
383 
384  //#############################################################################
385 
399  const CoinIndexedVector &op2);
400 
403  const CoinIndexedVector &op2);
404 
407  const CoinIndexedVector &op2);
408 
411  const CoinIndexedVector &op2);
413  void operator+=(const CoinIndexedVector &op2);
414 
416  void operator-=(const CoinIndexedVector &op2);
417 
419  void operator*=(const CoinIndexedVector &op2);
420 
422  void operator/=(const CoinIndexedVector &op2);
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);
464  CoinIndexedVector(int size);
469 #ifndef CLP_NO_VECTOR
470 
472 #endif
473 
476 
477 private:
480  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 
492 protected:
495  int *indices_;
498  double *elements_;
504  int offset_;
508 };
509 
510 //#############################################################################
534 
535 public:
538  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 
573  inline void setSize(int value)
575  {
576  size_ = value;
577  }
578 #if COIN_BIG_INDEX
579  inline void setSize(long long value)
581  {
582  size_ = value;
583  }
584 #endif
585  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();
601  void swap(CoinArrayWithLength &other);
603  void extend(int newSize);
604 #if COIN_BIG_INDEX
605  void extend(long long newSize);
607 #endif
608 
609 
612  char *conditionalNew(CoinBigIndex sizeWanted);
615  void conditionalDelete();
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  }
642  CoinArrayWithLength(CoinBigIndex size, int mode);
650  void copy(const CoinArrayWithLength &rhs, int numberBytes = -1);
652  void allocate(const CoinArrayWithLength &rhs, CoinBigIndex numberBytes);
656  void getArray(CoinBigIndex size);
658  void reallyFreeArray();
660  void getCapacity(CoinBigIndex numberBytes, CoinBigIndex numberIfNeeded = -1);
662 
663 protected:
666  char *array_;
671  int offset_;
675 };
677 
679 
680 public:
683  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 
697  inline void setSize(int value)
699  {
700  size_ = value * CoinSizeofAsInt(double);
701  }
703 
706  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  }
722  inline CoinDoubleArrayWithLength(int size)
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  }
737  : CoinArrayWithLength(rhs)
738  {
739  }
742  : CoinArrayWithLength(rhs)
743  {
744  }
747  {
749  return *this;
750  }
752 };
754 
756 
757 public:
760  inline CoinBigIndex getSize() const
762  {
764  }
767  {
768  return reinterpret_cast< CoinFactorizationDouble * >((size_ > -2) ? array_ : NULL);
769  }
771 
774  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  {
801  array_ = new char[size * CoinSizeofAsInt(CoinFactorizationDouble)];
802  size_ = -1;
803  }
808  inline CoinFactorizationDoubleArrayWithLength(int size, int mode)
810  {
811  }
814  : CoinArrayWithLength(rhs)
815  {
816  }
819  : CoinArrayWithLength(rhs)
820  {
821  }
824  {
826  return *this;
827  }
829 };
831 
833 
834 public:
837  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 
851  inline void setSize(int value)
853  {
854  size_ = value * CoinSizeofAsInt(long double);
855  }
857 
860  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  }
891  : CoinArrayWithLength(rhs)
892  {
893  }
896  : CoinArrayWithLength(rhs)
897  {
898  }
901  {
903  return *this;
904  }
906 };
908 
910 
911 public:
914  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 
928  inline void setSize(int value)
930  {
931  size_ = value * CoinSizeofAsInt(int);
932  }
934 
937  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  }
968  : CoinArrayWithLength(rhs)
969  {
970  }
973  : CoinArrayWithLength(rhs)
974  {
975  }
978  {
980  return *this;
981  }
983 };
985 
987 
988 public:
991  inline CoinBigIndex getSize() const
993  {
995  }
997  inline CoinBigIndex *array() const
998  {
999  return reinterpret_cast< CoinBigIndex * >((size_ > -2) ? array_ : NULL);
1000  }
1002 
1005  inline void setSize(CoinBigIndex value)
1007  {
1008  size_ = value * CoinSizeofAsInt(CoinBigIndex);
1009  }
1011 
1014  inline CoinBigIndex *conditionalNew(CoinBigIndex sizeWanted)
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 
1065 public:
1068  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 
1082  inline void setSize(int value)
1084  {
1085  size_ = value * CoinSizeofAsInt(unsigned int);
1086  }
1088 
1091  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 
1142 public:
1145  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 
1159  inline void setSize(int value)
1161  {
1162  size_ = value * CoinSizeofAsInt(void *);
1163  }
1165 
1168  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 
1219 public:
1222  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 
1236  inline void setSize(int value)
1238  {
1239  size_ = value * lengthInBytes_;
1240  }
1242 
1245  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 
1296 protected:
1302 };
1304 
1305 public:
1306 #ifndef COIN_PARTITIONS
1307 #define COIN_PARTITIONS 8
1308 #endif
1309 
1311  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  inline void setNumElementsPartition(int partition, int value)
1344  {
1345  assert(partition < COIN_PARTITIONS);
1346  if (numberPartitions_)
1347  numberElementsPartition_[partition] = value;
1348  }
1350  inline void setTempNumElementsPartition(int partition, int value)
1351  {
1352  assert(partition < COIN_PARTITIONS);
1353  numberElementsPartition_[partition] = value;
1354  }
1356  void computeNumberElements();
1358  void compact();
1361  void reserve(int n);
1363  void setPartitions(int number, const int *starts);
1365  void clearAndReset();
1367  void clearAndKeep();
1369  void clearPartition(int partition);
1370 #ifndef NDEBUG
1371  void checkClear();
1374  void checkClean();
1375 #else
1376  inline void checkClear() {};
1377  inline void checkClean() {};
1378 #endif
1379  int scan(int partition, double tolerance = 0.0);
1384  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);
1406  CoinPartitionedVector(int size);
1416 protected:
1426 };
1427 inline 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
CoinBigIndex * array() const
Get Array.
int getNumPartitions() const
Get number of partitions.
CoinDoubleArrayWithLength()
Default constructor - NULL.
int alignment_
Alignment wanted (power of 2)
CoinFactorizationLongDoubleArrayWithLength(const CoinFactorizationLongDoubleArrayWithLength *rhs)
Copy constructor.2.
CoinArbitraryArrayWithLength(const CoinArbitraryArrayWithLength *rhs)
Copy constructor.2.
void setPartitions(int number, const int *starts)
Setup partitions (needs end as well)
CoinFactorizationDoubleArrayWithLength(int size, int mode)
Alternate Constructor - length in bytes mode - 0 size_ set to size 1 size_ set to size and zeroed...
Pointer with length in bytes.
void setVector(int numberIndices, const int *inds, const double *elems)
Set vector numberIndices, indices, and elements.
void quickAddNonZero(int index, double element)
Insert or if exists add an element into the vector Any resulting zero elements will be made tiny...
CoinBigIndex getSize() const
Get the size.
CoinIndexedVector operator-(const CoinIndexedVector &op2)
Return the difference of two indexed vectors.
CoinIntArrayWithLength(const CoinIntArrayWithLength &rhs)
Copy constructor.
void reserve(int n)
Reserve space.
void setConstant(int size, const int *inds, double elems)
Elements set to have the same scalar value.
void clearAndReset()
Reset the vector (as if were just created an empty vector). Gets rid of partitions.
unsigned int * conditionalNew(CoinBigIndex sizeWanted)
Conditionally gets new array.
long double * conditionalNew(CoinBigIndex sizeWanted)
Conditionally gets new array.
CoinBigIndex getSize() const
Get the size.
void operator+=(double value)
add value to every entry
int getNumElements() const
Get the size.
int * indices_
Vector indices.
CoinFactorizationLongDoubleArrayWithLength(const CoinFactorizationLongDoubleArrayWithLength &rhs)
Copy constructor.
void copy(const CoinIndexedVector &rhs, double multiplier=1.0)
Copy the contents of one vector into another.
CoinUnsignedIntArrayWithLength(const CoinUnsignedIntArrayWithLength &rhs)
Copy constructor.
void clear()
Zero out array.
double & operator[](int i) const
Access the i&#39;th element of the full storage vector.
CoinArbitraryArrayWithLength(int length, int size)
Alternate Constructor - length in bytes - size_ -1.
CoinBigIndex getSize() const
Get the size.
void switchOff()
Set the size to -1.
void setElement(int index, double element)
Set an existing element in the indexed vector The first argument is the &quot;index&quot; into the elements() a...
void reallyFreeArray()
Really get rid of array with alignment.
int offset_
Offset to get where new allocated array.
long double * array() const
Get Array.
bool packedMode() const
Gets packed mode.
CoinFactorizationDoubleArrayWithLength(int size)
Alternate Constructor - length in bytes - size_ -1.
void setSize(int value)
Set the size.
void setSize(int value)
Set the size.
int numberPartitions_
Number of partitions (0 means off)
void reallyClear()
Clear even if in a bad way.
CoinUnsignedIntArrayWithLength & operator=(const CoinUnsignedIntArrayWithLength &rhs)
Assignment operator.
void add(int index, double element)
Insert or if exists add an element into the vector Any resulting zero elements will be made tiny...
void setPersistence(int flag, int currentLength)
Does what is needed to set persistence.
void getArray(CoinBigIndex size)
Get array with alignment.
CoinIndexedVector operator+(const CoinIndexedVector &op2)
Return the sum of two indexed vectors.
CoinFactorizationDouble * conditionalNew(CoinBigIndex sizeWanted)
Conditionally gets new array.
void checkClear()
For debug check vector is clear i.e. no elements.
CoinPartitionedVector()
Default constructor.
void print() const
Print out.
void zero(int index)
Makes nonzero tiny.
CoinArbitraryArrayWithLength & operator=(const CoinArbitraryArrayWithLength &rhs)
Assignment operator.
~CoinPartitionedVector()
Destructor.
CoinBigIndexArrayWithLength()
Default constructor - NULL.
void setSize(int value)
Set the size.
CoinBigIndex capacity() const
Get the capacity (just read it)
void setCapacity()
Set the capacity to &gt;=0 if &lt;=-2.
double * denseVector() const
Get the vector as a dense vector.
bool operator!=(const CoinPackedVectorBase &rhs) const
Not equal.
CoinUnsignedIntArrayWithLength(int size, int mode)
Alternate Constructor - length in bytes mode - 0 size_ set to size 1 size_ set to size and zeroed...
void setPackedMode(bool yesNo)
Sets packed mode.
void setIndexVector(int *array)
For very temporary use when user needs to borrow an index vector.
double * elements_
Vector elements.
bool packedMode_
If true then is operating in packed mode.
void returnVector()
Return ownership of the arguments to this vector.
CoinBigIndex lengthInBytes_
Length in bytes.
CoinFactorizationLongDoubleArrayWithLength()
Default constructor - NULL.
CoinArrayWithLength(CoinBigIndex size)
Alternate Constructor - length in bytes - size_ -1.
#define COIN_PARTITIONS
void reserve(int n)
Reserve space.
CoinBigIndexArrayWithLength(const CoinBigIndexArrayWithLength *rhs)
Copy constructor.2.
void operator*=(double value)
multiply every entry by value
void sort()
Sort the indexed storage vector (increasing indices).
const double COIN_DBL_MIN
Definition: CoinFinite.hpp:17
CoinArbitraryArrayWithLength(int length=1)
Default constructor - NULL.
int nElements_
Size of indices and packed elements vectors.
Abstract base class for various sparse vectors.
void setNumElements(int value)
Set the size.
CoinUnsignedIntArrayWithLength(int size)
Alternate Constructor - length in bytes - size_ -1.
void swap(int i, int j)
Swap values in positions i and j of indices and elements.
CoinIntArrayWithLength(const CoinIntArrayWithLength *rhs)
Copy constructor.2.
void borrowVector(int size, int numberIndices, int *inds, double *elems)
Borrow ownership of the arguments to this vector.
int getNumElements() const
Get the size.
void print() const
Scan dense region from start to &lt; end and set up indices returns number found.
void operator-=(double value)
subtract value from every entry
int cleanAndPack(double tolerance)
Same but packs down.
CoinFactorizationDouble * array() const
Get Array.
CoinBigIndex getSize() const
Get the size.
~CoinIndexedVector()
Destructor.
#define CoinSizeofAsInt(type)
Cube Root.
double CoinFactorizationDouble
Definition: CoinTypes.hpp:57
CoinVoidStarArrayWithLength()
Default constructor - NULL.
void setSize(int value)
Set the size.
CoinBigIndexArrayWithLength(const CoinBigIndexArrayWithLength &rhs)
Copy constructor.
CoinIntArrayWithLength(int size)
Alternate Constructor - length in bytes - size_ -1.
int getMaxIndex() const
Get value of maximum index.
void swap(CoinArrayWithLength &other)
Swaps memory between two members.
void expand()
This is mainly for testing - goes from packed to indexed.
CoinBigIndex * version.
Indexed Vector.
int clean(double tolerance)
set all small values to zero and return number remaining
CoinFactorizationDoubleArrayWithLength(const CoinFactorizationDoubleArrayWithLength &rhs)
Copy constructor.
int scan()
Scan dense region and set up indices (returns number found)
CoinIntArrayWithLength(int size, int mode)
Alternate Constructor - length in bytes mode - 0 size_ set to size 1 size_ set to size and zeroed...
int capacity_
Amount of memory allocated for indices_, and elements_.
CoinVoidStarArrayWithLength(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.
CoinArrayWithLength & operator=(const CoinArrayWithLength &rhs)
Assignment operator.
void createOneUnpackedElement(int index, double element)
Create unpacked singleton.
void createUnpacked(int number, const int *indices, const double *elements)
Create unpacked array.
CoinDoubleArrayWithLength(const CoinDoubleArrayWithLength *rhs)
Copy constructor.2.
double * array() const
Get Array.
CoinIndexedVector operator/(const CoinIndexedVector &op2)
Return the element-wise ratio of two indexed vectors (0.0/0.0 =&gt; 0.0) (0 vanishes) ...
CoinUnsignedIntArrayWithLength(const CoinUnsignedIntArrayWithLength *rhs)
Copy constructor.2.
CoinIntArrayWithLength & operator=(const CoinIntArrayWithLength &rhs)
Assignment operator.
void empty()
Reset the vector (as if were just created an empty vector)
const int * getIndices() const
Get indices of elements.
void gutsOfSetPackedVector(int size, int numberIndices, const int *inds, const double *elems)
CoinBigIndex size_
Size of array in bytes.
CoinBigIndexArrayWithLength(CoinBigIndex size)
Alternate Constructor - length in bytes - size_ -1.
void append(const CoinPackedVectorBase &caboose)
Append a CoinPackedVector to the end.
CoinVoidStarArrayWithLength(int size)
Alternate Constructor - length in bytes - size_ -1.
CoinPartitionedVector & operator=(const CoinPartitionedVector &)
Assignment operator.
void gutsOfSetConstant(int size, const int *inds, double value)
void ** array() const
Get Array.
CoinBigIndex getSize() const
Get the size.
void setFull(int size, const double *elems)
Indices are not specified and are taken to be 0,1,...,size-1.
void sort()
Sort the indexed storage vector (increasing indices).
CoinFactorizationLongDoubleArrayWithLength(int size, int mode)
Alternate Constructor - length in bytes mode - 0 size_ set to size 1 size_ set to size and zeroed...
void gutsOfSetVector(int size, const int *inds, const double *elems)
Copy internal data.
int capacity() const
capacity returns the size which could be accomodated without having to reallocate storage...
CoinVoidStarArrayWithLength(const CoinVoidStarArrayWithLength *rhs)
Copy constructor.2.
CoinArrayWithLength()
Default constructor - NULL.
void checkClear()
For debug check vector is clear i.e. no elements.
void setSize(int value)
Set the size.
char * conditionalNew(CoinBigIndex length, CoinBigIndex sizeWanted)
Conditionally gets new array.
int offset_
Offset of array.
double * roundUpDouble(double *address)
void getCapacity(CoinBigIndex numberBytes, CoinBigIndex numberIfNeeded=-1)
Get enough space (if more needed then do at least needed)
CoinDoubleArrayWithLength & operator=(const CoinDoubleArrayWithLength &rhs)
Assignment operator.
CoinIntArrayWithLength()
Default constructor - NULL.
void clearAndKeep()
Reset the vector (as if were just created an empty vector). Keeps partitions.
void checkClean()
For debug check vector is clean i.e. elements match indices.
CoinDoubleArrayWithLength(int size)
Alternate Constructor - length in bytes - size_ -1.
CoinBigIndex getSize() const
Get the size.
void CoinIndexedVectorUnitTest()
A function that tests the methods in the CoinIndexedVector class.
CoinBigIndex getSize() const
Get the size.
void conditionalDelete()
Conditionally deletes.
CoinBigIndexArrayWithLength(CoinBigIndex size, int mode)
Alternate Constructor - length in bytes mode - 0 size_ set to size 1 size_ set to size and zeroed...
CoinFactorizationDoubleArrayWithLength()
Default constructor - NULL.
CoinUnsignedIntArrayWithLength()
Default constructor - NULL.
unsigned int * array() const
Get Array.
void ** conditionalNew(CoinBigIndex sizeWanted)
Conditionally gets new array.
CoinVoidStarArrayWithLength & operator=(const CoinVoidStarArrayWithLength &rhs)
Assignment operator.
int isApproximatelyEqual(const CoinIndexedVector &rhs, double tolerance=1.0e-8) const
Equal with a tolerance (returns -1 or position of inequality).
void setSize(CoinBigIndex value)
Set the size.
void quickInsert(int index, double element)
Insert a nonzero element into the vector.
void switchOn(int alignment=3)
Set the size to -2 and alignment.
CoinFactorizationDouble * version.
int CoinBigIndex
void ** array() const
Get Array.
void allocate(const CoinArrayWithLength &rhs, CoinBigIndex numberBytes)
Assignment with length - does not copy.
int numberElementsPartition_[COIN_PARTITIONS]
Size of indices in a partition.
char * conditionalNew(CoinBigIndex sizeWanted)
Conditionally gets new array.
CoinVoidStarArrayWithLength(const CoinVoidStarArrayWithLength &rhs)
Copy constructor.
void setPacked()
Mark as packed.
void compact()
Add up number of elements in partitions and pack and get rid of partitions.
#define CoinInt64
Definition: CoinTypes.hpp:18
CoinFactorizationLongDouble * version.
CoinFactorizationLongDoubleArrayWithLength(int size)
Alternate Constructor - length in bytes - size_ -1.
~CoinArrayWithLength()
Destructor.
void createPacked(int number, const int *indices, const double *elements)
Create packed array.
void setNumElementsPartition(int partition, int value)
Set the size of a partition.
int * array() const
Get Array.
int startPartition_[COIN_PARTITIONS+1]
Starts.
int * getIndices()
Get element values.
CoinArbitraryArrayWithLength(const CoinArbitraryArrayWithLength &rhs)
Copy constructor.
void extend(int newSize)
Extend a persistent array keeping data (size in bytes)
int * conditionalNew(CoinBigIndex sizeWanted)
Conditionally gets new array.
CoinIndexedVector()
Default constructor.
CoinFactorizationDoubleArrayWithLength & operator=(const CoinFactorizationDoubleArrayWithLength &rhs)
Assignment operator.
void copy(const CoinArrayWithLength &rhs, int numberBytes=-1)
Assignment with length (if -1 use internal length)
int cleanAndPackSafe(double tolerance)
Same but packs down and is safe (i.e. if order is odd)
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...
void setTempNumElementsPartition(int partition, int value)
Set the size of a partition (just for a tiny while)
double * conditionalNew(CoinBigIndex sizeWanted)
Conditionally gets new array.
int startPartition(int partition) const
Get starts.
int getMinIndex() const
Get value of minimum index.
CoinDoubleArrayWithLength(int size, int mode)
Alternate Constructor - length in bytes mode - 0 size_ set to size 1 size_ set to size and zeroed...
CoinBigIndex rawSize() const
Get the size.
CoinBigIndexArrayWithLength & operator=(const CoinBigIndexArrayWithLength &rhs)
Assignment operator.
CoinBigIndex getSize() const
Get the size.
CoinIndexedVector operator*(const CoinIndexedVector &op2)
Return the element-wise product of two indexed vectors.
CoinIndexedVector & operator=(const CoinIndexedVector &)
Assignment operator.
void quickAdd(int index, double element)
Insert or if exists add an element into the vector Any resulting zero elements will be made tiny...
CoinFactorizationLongDoubleArrayWithLength & operator=(const CoinFactorizationLongDoubleArrayWithLength &rhs)
Assignment operator.
void clear()
Reset the vector (as if were just created an empty vector). This leaves arrays!
void setDenseVector(double *array)
For very temporary use when user needs to borrow a dense vector.
bool operator==(const CoinPackedVectorBase &rhs) const
Equal.
void computeNumberElements()
Add up number of elements in partitions.
void setCapacity(int value)
CoinBigIndex * conditionalNew(CoinBigIndex sizeWanted)
Conditionally gets new array.
const char * array() const
Get Array.
#define COIN_INDEXED_TINY_ELEMENT
void operator/=(double value)
divide every entry by value (** 0 vanishes)
CoinDoubleArrayWithLength(const CoinDoubleArrayWithLength &rhs)
Copy constructor.
void clearPartition(int partition)
Clear a partition.
friend void CoinIndexedVectorUnitTest()
A function that tests the methods in the CoinIndexedVector class.
void checkClean()
For debug check vector is clean i.e. elements match indices.
void insert(int index, double element)
Insert an element into the vector.
const int * startPartitions() const
Get starts.
void setSize(int value)
Set the size.
CoinBigIndex getSize() const
Get the size.
bool switchedOn() const
See if persistence already on.
int scanAndPack()
These are same but pack down.
void truncate(int newSize)
Throw away all entries in rows &gt;= newSize.
void setSize(int value)
Set the size.