CoinUtils  2.9.15
CoinIndexedVector.hpp
Go to the documentation of this file.
1 /* $Id: CoinIndexedVector.hpp 1554 2012-10-31 16:52:28Z 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  { elements_ = array;}
126  inline void setIndexVector(int * array)
127  { indices_ = array;}
130  double & operator[](int i) const;
131 
133 
134  //-------------------------------------------------------------------
135  // Set indices and elements
136  //-------------------------------------------------------------------
139  inline void setNumElements(int value) { nElements_ = value;
141  if (!nElements_) packedMode_=false;}
143  void clear();
145  void empty();
148 #ifndef CLP_NO_VECTOR
149 
152 #endif
153 
156  void copy(const CoinIndexedVector & rhs, double multiplier=1.0);
157 
160  void borrowVector(int size, int numberIndices, int* inds, double* elems);
161 
165  void returnVector();
166 
171  void setVector(int numberIndices, const int * inds, const double * elems);
172 
177  void setVector(int size, int numberIndices, const int * inds, const double * elems);
178 
180  void setConstant(int size, const int * inds, double elems);
181 
183  void setFull(int size, const double * elems);
184 
188  void setElement(int index, double element);
189 
191  void insert(int index, double element);
193  inline void quickInsert(int index, double element)
194  {
195  assert (!elements_[index]);
196  indices_[nElements_++] = index;
197  assert (nElements_<=capacity_);
198  elements_[index] = element;
199  }
202  void add(int index, double element);
206  inline void quickAdd(int index, double element)
207  {
208  if (elements_[index]) {
209  element += elements_[index];
210  if ((element > 0 ? element : -element) >= COIN_INDEXED_TINY_ELEMENT) {
211  elements_[index] = element;
212  } else {
213  elements_[index] = 1.0e-100;
214  }
215  } else if ((element > 0 ? element : -element) >= COIN_INDEXED_TINY_ELEMENT) {
216  indices_[nElements_++] = index;
217  assert (nElements_<=capacity_);
218  elements_[index] = element;
219  }
220  }
225  inline void quickAddNonZero(int index, double element)
226  {
227  assert (element);
228  if (elements_[index]) {
229  element += elements_[index];
230  if ((element > 0 ? element : -element) >= COIN_INDEXED_TINY_ELEMENT) {
231  elements_[index] = element;
232  } else {
233  elements_[index] = COIN_DBL_MIN;
234  }
235  } else {
236  indices_[nElements_++] = index;
237  assert (nElements_<=capacity_);
238  elements_[index] = element;
239  }
240  }
243  inline void zero(int index)
244  {
245  if (elements_[index])
246  elements_[index] = COIN_DBL_MIN;
247  }
250  int clean(double tolerance);
252  int cleanAndPack(double tolerance);
254  int cleanAndPackSafe(double tolerance);
256  inline void setPacked()
257  { packedMode_ = true;}
258 #ifndef NDEBUG
259  void checkClear();
262  void checkClean();
263 #else
264  inline void checkClear() {};
265  inline void checkClean() {};
266 #endif
267  int scan();
272  int scan(int start, int end);
275  int scan(double tolerance);
279  int scan(int start, int end, double tolerance);
281  int scanAndPack();
282  int scanAndPack(int start, int end);
283  int scanAndPack(double tolerance);
284  int scanAndPack(int start, int end, double tolerance);
286  void createPacked(int number, const int * indices,
287  const double * elements);
289  void createUnpacked(int number, const int * indices,
290  const double * elements);
292  void createOneUnpackedElement(int index, double element);
294  void expand();
295 #ifndef CLP_NO_VECTOR
296  void append(const CoinPackedVectorBase & caboose);
298 #endif
299  void append(const CoinIndexedVector & caboose);
302  void append(CoinIndexedVector & other,int adjustIndex,bool zapElements=false);
303 
305  void swap(int i, int j);
306 
308  void truncate(int newSize);
310  void print() const;
312 
314  void operator+=(double value);
317  void operator-=(double value);
319  void operator*=(double value);
321  void operator/=(double value);
323 
326 #ifndef CLP_NO_VECTOR
327 
329  bool operator==(const CoinPackedVectorBase & rhs) const;
331  bool operator!=(const CoinPackedVectorBase & rhs) const;
332 #endif
333 
335  bool operator==(const CoinIndexedVector & rhs) const;
337  bool operator!=(const CoinIndexedVector & rhs) const;
339  int isApproximatelyEqual(const CoinIndexedVector & rhs, double tolerance=1.0e-8) const;
341 
344  int getMaxIndex() const;
347  int getMinIndex() const;
349 
350 
354  void sort()
355  { std::sort(indices_,indices_+nElements_); }
356 
358  { std::sort(indices_,indices_+nElements_); }
359 
360  void sortDecrIndex();
361 
362  void sortIncrElement();
363 
364  void sortDecrElement();
365  void sortPacked();
366 
368 
369  //#############################################################################
370 
384  const CoinIndexedVector& op2);
385 
388  const CoinIndexedVector& op2);
389 
392  const CoinIndexedVector& op2);
393 
396  const CoinIndexedVector& op2);
398 void operator+=(const CoinIndexedVector& op2);
399 
401 void operator-=( const CoinIndexedVector& op2);
402 
404 void operator*=(const CoinIndexedVector& op2);
405 
407 void operator/=(const CoinIndexedVector& op2);
409 
416  void reserve(int n);
420  int capacity() const { return capacity_; }
422  inline void setPackedMode(bool yesNo)
423  { packedMode_=yesNo;}
425  inline bool packedMode() const
426  { return packedMode_;}
428 
434  CoinIndexedVector(int size, const int * inds, const double * elems);
436  CoinIndexedVector(int size, const int * inds, double element);
439  CoinIndexedVector(int size, const double * elements);
441  CoinIndexedVector(int size);
446 #ifndef CLP_NO_VECTOR
447 
449 #endif
450 
453 
454 private:
457  void gutsOfSetVector(int size,
459  const int * inds, const double * elems);
460  void gutsOfSetVector(int size, int numberIndices,
461  const int * inds, const double * elems);
462  void gutsOfSetPackedVector(int size, int numberIndices,
463  const int * inds, const double * elems);
465  void gutsOfSetConstant(int size,
466  const int * inds, double value);
468 
469 protected:
472  int * indices_;
475  double * elements_;
481  int offset_;
485 };
486 
487 //#############################################################################
493 void
512 
513 public:
516  inline int getSize() const
518  { return size_; }
520  inline int rawSize() const
521  { return size_; }
523  inline bool switchedOn() const
524  { return size_!=-1; }
526  inline int capacity() const
527  { return (size_>-2) ? size_ : (-size_)-2; }
529  inline void setCapacity()
530  { if (size_<=-2) size_ = (-size_)-2; }
532  inline const char * array() const
533  { return (size_>-2) ? array_ : NULL; }
535 
538  inline void setSize(int value)
540  { size_ = value; }
542  inline void switchOff()
543  { size_ = -1; }
545  inline void switchOn(int alignment=3)
546  { size_ = -2; alignment_=alignment;}
548  void setPersistence(int flag,int currentLength);
550  void clear();
552  void swap(CoinArrayWithLength & other);
554  void extend(int newSize);
556 
559  char * conditionalNew(long sizeWanted);
562  void conditionalDelete();
564 
569  : array_(NULL),size_(-1),offset_(0),alignment_(0)
570  { }
572  inline CoinArrayWithLength(int size)
573  : size_(-1),offset_(0),alignment_(0)
574  { array_=new char [size];}
581  CoinArrayWithLength(int size, int mode);
589  void copy(const CoinArrayWithLength & rhs, int numberBytes=-1);
591  void allocate(const CoinArrayWithLength & rhs, int numberBytes);
595  void getArray(int size);
597  void reallyFreeArray();
599  void getCapacity(int numberBytes,int numberIfNeeded=-1);
601 
602 protected:
605  char * array_;
610  int offset_;
614 };
616 
618 
619 public:
622  inline int getSize() const
624  { return size_/CoinSizeofAsInt(double); }
626  inline double * array() const
627  { return reinterpret_cast<double *> ((size_>-2) ? array_ : NULL); }
629 
632  inline void setSize(int value)
634  { size_ = value*CoinSizeofAsInt(double); }
636 
639  inline double * conditionalNew(int sizeWanted)
641  { return reinterpret_cast<double *> ( CoinArrayWithLength::conditionalNew(sizeWanted>=0 ? static_cast<long> ((sizeWanted)*CoinSizeofAsInt(double)) : -1)); }
643 
648  { array_=NULL; size_=-1;}
650  inline CoinDoubleArrayWithLength(int size)
651  { array_=new char [size*CoinSizeofAsInt(double)]; size_=-1;}
656  inline CoinDoubleArrayWithLength(int size, int mode)
657  : CoinArrayWithLength(size*CoinSizeofAsInt(double),mode) {}
660  : CoinArrayWithLength(rhs) {}
663  : CoinArrayWithLength(rhs) {}
666  { CoinArrayWithLength::operator=(rhs); return *this;}
668 };
670 
672 
673 public:
676  inline int getSize() const
678  { return size_/CoinSizeofAsInt(CoinFactorizationDouble); }
680  inline CoinFactorizationDouble * array() const
681  { return reinterpret_cast<CoinFactorizationDouble *> ((size_>-2) ? array_ : NULL); }
683 
686  inline void setSize(int value)
688  { size_ = value*CoinSizeofAsInt(CoinFactorizationDouble); }
690 
693  inline CoinFactorizationDouble * conditionalNew(int sizeWanted)
695  { return reinterpret_cast<CoinFactorizationDouble *> (CoinArrayWithLength::conditionalNew(sizeWanted>=0 ? static_cast<long> (( sizeWanted)*CoinSizeofAsInt(CoinFactorizationDouble)) : -1)); }
697 
702  { array_=NULL; size_=-1;}
705  { array_=new char [size*CoinSizeofAsInt(CoinFactorizationDouble)]; size_=-1;}
710  inline CoinFactorizationDoubleArrayWithLength(int size, int mode)
714  : CoinArrayWithLength(rhs) {}
717  : CoinArrayWithLength(rhs) {}
720  { CoinArrayWithLength::operator=(rhs); return *this;}
722 };
724 
726 
727 public:
730  inline int getSize() const
732  { return size_/CoinSizeofAsInt(long double); }
734  inline long double * array() const
735  { return reinterpret_cast<long double *> ((size_>-2) ? array_ : NULL); }
737 
740  inline void setSize(int value)
742  { size_ = value*CoinSizeofAsInt(long double); }
744 
747  inline long double * conditionalNew(int sizeWanted)
749  { return reinterpret_cast<long double *> (CoinArrayWithLength::conditionalNew(sizeWanted>=0 ? static_cast<long> (( sizeWanted)*CoinSizeofAsInt(long double)) : -1)); }
751 
756  { array_=NULL; size_=-1;}
759  { array_=new char [size*CoinSizeofAsInt(long double)]; size_=-1;}
765  : CoinArrayWithLength(size*CoinSizeofAsInt(long double),mode) {}
768  : CoinArrayWithLength(rhs) {}
771  : CoinArrayWithLength(rhs) {}
774  { CoinArrayWithLength::operator=(rhs); return *this;}
776 };
778 
780 
781 public:
784  inline int getSize() const
786  { return size_/CoinSizeofAsInt(int); }
788  inline int * array() const
789  { return reinterpret_cast<int *> ((size_>-2) ? array_ : NULL); }
791 
794  inline void setSize(int value)
796  { size_ = value*CoinSizeofAsInt(int); }
798 
801  inline int * conditionalNew(int sizeWanted)
803  { return reinterpret_cast<int *> (CoinArrayWithLength::conditionalNew(sizeWanted>=0 ? static_cast<long> (( sizeWanted)*CoinSizeofAsInt(int)) : -1)); }
805 
810  { array_=NULL; size_=-1;}
812  inline CoinIntArrayWithLength(int size)
813  { array_=new char [size*CoinSizeofAsInt(int)]; size_=-1;}
818  inline CoinIntArrayWithLength(int size, int mode)
819  : CoinArrayWithLength(size*CoinSizeofAsInt(int),mode) {}
822  : CoinArrayWithLength(rhs) {}
825  : CoinArrayWithLength(rhs) {}
828  { CoinArrayWithLength::operator=(rhs); return *this;}
830 };
832 
834 
835 public:
838  inline int getSize() const
840  { return size_/CoinSizeofAsInt(CoinBigIndex); }
842  inline CoinBigIndex * array() const
843  { return reinterpret_cast<CoinBigIndex *> ((size_>-2) ? array_ : NULL); }
845 
848  inline void setSize(int value)
850  { size_ = value*CoinSizeofAsInt(CoinBigIndex); }
852 
855  inline CoinBigIndex * conditionalNew(int sizeWanted)
857  { return reinterpret_cast<CoinBigIndex *> (CoinArrayWithLength::conditionalNew(sizeWanted>=0 ? static_cast<long> (( sizeWanted)*CoinSizeofAsInt(CoinBigIndex)) : -1)); }
859 
864  { array_=NULL; size_=-1;}
867  { array_=new char [size*CoinSizeofAsInt(CoinBigIndex)]; size_=-1;}
872  inline CoinBigIndexArrayWithLength(int size, int mode)
876  : CoinArrayWithLength(rhs) {}
879  : CoinArrayWithLength(rhs) {}
882  { CoinArrayWithLength::operator=(rhs); return *this;}
884 };
886 
888 
889 public:
892  inline int getSize() const
894  { return size_/CoinSizeofAsInt(unsigned int); }
896  inline unsigned int * array() const
897  { return reinterpret_cast<unsigned int *> ((size_>-2) ? array_ : NULL); }
899 
902  inline void setSize(int value)
904  { size_ = value*CoinSizeofAsInt(unsigned int); }
906 
909  inline unsigned int * conditionalNew(int sizeWanted)
911  { return reinterpret_cast<unsigned int *> (CoinArrayWithLength::conditionalNew(sizeWanted>=0 ? static_cast<long> (( sizeWanted)*CoinSizeofAsInt(unsigned int)) : -1)); }
913 
918  { array_=NULL; size_=-1;}
921  { array_=new char [size*CoinSizeofAsInt(unsigned int)]; size_=-1;}
926  inline CoinUnsignedIntArrayWithLength(int size, int mode)
927  : CoinArrayWithLength(size*CoinSizeofAsInt(unsigned int),mode) {}
930  : CoinArrayWithLength(rhs) {}
933  : CoinArrayWithLength(rhs) {}
936  { CoinArrayWithLength::operator=(rhs); return *this;}
938 };
940 
942 
943 public:
946  inline int getSize() const
948  { return size_/CoinSizeofAsInt(void *); }
950  inline void ** array() const
951  { return reinterpret_cast<void **> ((size_>-2) ? array_ : NULL); }
953 
956  inline void setSize(int value)
958  { size_ = value*CoinSizeofAsInt(void *); }
960 
963  inline void ** conditionalNew(int sizeWanted)
965  { return reinterpret_cast<void **> ( CoinArrayWithLength::conditionalNew(sizeWanted>=0 ? static_cast<long> ((sizeWanted)*CoinSizeofAsInt(void *)) : -1)); }
967 
972  { array_=NULL; size_=-1;}
975  { array_=new char [size*CoinSizeofAsInt(void *)]; size_=-1;}
980  inline CoinVoidStarArrayWithLength(int size, int mode)
981  : CoinArrayWithLength(size*CoinSizeofAsInt(void *),mode) {}
984  : CoinArrayWithLength(rhs) {}
987  : CoinArrayWithLength(rhs) {}
990  { CoinArrayWithLength::operator=(rhs); return *this;}
992 };
994 
996 
997 public:
1000  inline int getSize() const
1002  { return size_/lengthInBytes_; }
1004  inline void ** array() const
1005  { return reinterpret_cast<void **> ((size_>-2) ? array_ : NULL); }
1007 
1010  inline void setSize(int value)
1012  { size_ = value*lengthInBytes_; }
1014 
1017  inline char * conditionalNew(int length, int sizeWanted)
1019  { lengthInBytes_=length;return reinterpret_cast<char *> ( CoinArrayWithLength::conditionalNew(sizeWanted>=0 ? static_cast<long>
1020  ((sizeWanted)*lengthInBytes_) : -1)); }
1022 
1026  inline CoinArbitraryArrayWithLength(int length=1)
1027  { array_=NULL; size_=-1;lengthInBytes_=length;}
1029  inline CoinArbitraryArrayWithLength(int length, int size)
1030  { array_=new char [size*length]; size_=-1; lengthInBytes_=length;}
1035  inline CoinArbitraryArrayWithLength(int length, int size, int mode)
1036  : CoinArrayWithLength(size*length,mode) {lengthInBytes_=length;}
1039  : CoinArrayWithLength(rhs) {}
1042  : CoinArrayWithLength(rhs) {}
1045  { CoinArrayWithLength::operator=(rhs); return *this;}
1047 
1048 protected:
1051  int lengthInBytes_;
1054 };
1056 
1057 public:
1058 #ifndef COIN_PARTITIONS
1059 #define COIN_PARTITIONS 8
1060 #endif
1061 
1063  inline int getNumElements(int partition) const { assert (partition<COIN_PARTITIONS);
1065  return numberElementsPartition_[partition]; }
1067  inline int getNumPartitions() const
1068  { return numberPartitions_; }
1070  inline int getNumElements() const { return nElements_; }
1072  inline int startPartition(int partition) const { assert (partition<=COIN_PARTITIONS);
1073  return startPartition_[partition]; }
1075  inline const int * startPartitions() const
1076  { return startPartition_; }
1078 
1079  //-------------------------------------------------------------------
1080  // Set indices and elements
1081  //-------------------------------------------------------------------
1084  inline void setNumElementsPartition(int partition, int value) { assert (partition<COIN_PARTITIONS);
1086  if (numberPartitions_) numberElementsPartition_[partition]=value; }
1088  inline void setTempNumElementsPartition(int partition, int value) { assert (partition<COIN_PARTITIONS);
1089  numberElementsPartition_[partition]=value; }
1091  void computeNumberElements();
1093  void compact();
1096  void reserve(int n);
1098  void setPartitions(int number,const int * starts);
1100  void clearAndReset();
1102  void clearAndKeep();
1104  void clearPartition(int partition);
1105 #ifndef NDEBUG
1106  void checkClear();
1109  void checkClean();
1110 #else
1111  inline void checkClear() {};
1112  inline void checkClean() {};
1113 #endif
1114  int scan(int partition, double tolerance=0.0);
1119  void print() const;
1122 
1126  void sort();
1128 
1134  CoinPartitionedVector(int size, const int * inds, const double * elems);
1136  CoinPartitionedVector(int size, const int * inds, double element);
1139  CoinPartitionedVector(int size, const double * elements);
1141  CoinPartitionedVector(int size);
1151 protected:
1154  int startPartition_[COIN_PARTITIONS+1];
1157  int numberElementsPartition_[COIN_PARTITIONS];
1161 };
1162 #endif
CoinDoubleArrayWithLength()
Default constructor - NULL.
int capacity() const
capacity returns the size which could be accomodated without having to reallocate storage...
int alignment_
Alignment wanted (power of 2)
CoinFactorizationLongDoubleArrayWithLength(const CoinFactorizationLongDoubleArrayWithLength *rhs)
Copy constructor.2.
CoinArbitraryArrayWithLength(const CoinArbitraryArrayWithLength *rhs)
Copy constructor.2.
int startPartition(int partition) const
Get starts.
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...
CoinIndexedVector operator-(const CoinIndexedVector &op2)
Return the difference of two indexed vectors.
CoinIntArrayWithLength(const CoinIntArrayWithLength &rhs)
Copy constructor.
void reserve(int n)
Reserve space.
const int * startPartitions() const
Get starts.
void setConstant(int size, const int *inds, double elems)
Elements set to have the same scalar value.
double & operator[](int i) const
Access the i&#39;th element of the full storage vector.
void operator+=(double value)
add value to every entry
int * indices_
Vector indices.
int getNumElements() const
Get the size.
int getMaxIndex() const
Get value of maximum index.
CoinFactorizationLongDoubleArrayWithLength(const CoinFactorizationLongDoubleArrayWithLength &rhs)
Copy constructor.
char * conditionalNew(long sizeWanted)
Conditionally gets new array.
bool switchedOn() const
See if persistence already on.
void copy(const CoinIndexedVector &rhs, double multiplier=1.0)
Copy the contents of one vector into another.
CoinUnsignedIntArrayWithLength(const CoinUnsignedIntArrayWithLength &rhs)
Copy constructor.
CoinArbitraryArrayWithLength(int length, int size)
Alternate Constructor - length in bytes - size_ -1.
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 "index" into the elements() a...
int offset_
Offset to get where new allocated array.
CoinFactorizationDouble * array() const
Get Array.
int isApproximatelyEqual(const CoinIndexedVector &rhs, double tolerance=1.0e-8) const
Equal with a tolerance (returns -1 or position of inequality).
CoinFactorizationDoubleArrayWithLength(int size)
Alternate Constructor - length in bytes - size_ -1.
int numberPartitions_
Number of partitions (0 means off)
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...
CoinIndexedVector operator+(const CoinIndexedVector &op2)
Return the sum of two indexed vectors.
void checkClear()
For debug check vector is clear i.e. no elements.
void zero(int index)
Makes nonzero tiny.
CoinArbitraryArrayWithLength & operator=(const CoinArbitraryArrayWithLength &rhs)
Assignment operator.
CoinBigIndexArrayWithLength()
Default constructor - NULL.
long double * array() const
Get Array.
int rawSize() const
Get the size.
void setCapacity()
Set the capacity to >=0 if <=-2.
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.
CoinBigIndex * array() const
Get Array.
double * denseVector() const
Get the vector as a dense vector.
void returnVector()
Return ownership of the arguments to this vector.
CoinFactorizationLongDoubleArrayWithLength()
Default constructor - NULL.
#define COIN_PARTITIONS
CoinBigIndexArrayWithLength(const CoinBigIndexArrayWithLength *rhs)
Copy constructor.2.
void operator*=(double value)
multiply every entry by value
int * array() const
Get Array.
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.
void operator-=(double value)
subtract value from every entry
int cleanAndPack(double tolerance)
Same but packs down.
~CoinIndexedVector()
Destructor.
#define CoinSizeofAsInt(type)
Cube Root.
double CoinFactorizationDouble
Definition: CoinTypes.hpp:54
CoinVoidStarArrayWithLength()
Default constructor - NULL.
CoinBigIndexArrayWithLength(const CoinBigIndexArrayWithLength &rhs)
Copy constructor.
CoinIntArrayWithLength(int size)
Alternate Constructor - length in bytes - size_ -1.
void expand()
This is mainly for testing - goes from packed to indexed.
CoinBigIndex * version.
CoinBigIndexArrayWithLength(int size, int mode)
Alternate Constructor - length in bytes mode - 0 size_ set to size 1 size_ set to size and zeroed...
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(int size)
Alternate Constructor - length in bytes - size_ -1.
CoinArrayWithLength & operator=(const CoinArrayWithLength &rhs)
Assignment operator.
double * array() const
Get Array.
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.
int getNumElements() const
Get the size.
CoinIndexedVector operator/(const CoinIndexedVector &op2)
Return the element-wise ratio of two indexed vectors (0.0/0.0 => 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)
void gutsOfSetPackedVector(int size, int numberIndices, const int *inds, const double *elems)
CoinBigIndex size_
Size of array in bytes.
void append(const CoinPackedVectorBase &caboose)
Append a CoinPackedVector to the end.
CoinVoidStarArrayWithLength(int size)
Alternate Constructor - length in bytes - size_ -1.
void gutsOfSetConstant(int size, const int *inds, double value)
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).
bool operator!=(const CoinPackedVectorBase &rhs) const
Not equal.
CoinFactorizationLongDoubleArrayWithLength(int size, int mode)
Alternate Constructor - length in bytes mode - 0 size_ set to size 1 size_ set to size and zeroed...
void print() const
Print out.
void gutsOfSetVector(int size, const int *inds, const double *elems)
Copy internal data.
CoinVoidStarArrayWithLength(const CoinVoidStarArrayWithLength *rhs)
Copy constructor.2.
CoinArrayWithLength()
Default constructor - NULL.
int offset_
Offset of array.
CoinDoubleArrayWithLength & operator=(const CoinDoubleArrayWithLength &rhs)
Assignment operator.
CoinIntArrayWithLength()
Default constructor - NULL.
const char * array() const
Get Array.
void checkClean()
For debug check vector is clean i.e. elements match indices.
CoinDoubleArrayWithLength(int size)
Alternate Constructor - length in bytes - size_ -1.
void ** array() const
Get Array.
CoinFactorizationDoubleArrayWithLength()
Default constructor - NULL.
CoinUnsignedIntArrayWithLength()
Default constructor - NULL.
unsigned int * array() const
Get Array.
CoinVoidStarArrayWithLength & operator=(const CoinVoidStarArrayWithLength &rhs)
Assignment operator.
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.
bool packedMode() const
Gets packed mode.
int CoinBigIndex
CoinVoidStarArrayWithLength(const CoinVoidStarArrayWithLength &rhs)
Copy constructor.
void setPacked()
Mark as packed.
CoinFactorizationLongDouble * version.
CoinFactorizationLongDoubleArrayWithLength(int size)
Alternate Constructor - length in bytes - size_ -1.
void createPacked(int number, const int *indices, const double *elements)
Create packed array.
int * getIndices()
Get element values.
CoinArbitraryArrayWithLength(const CoinArbitraryArrayWithLength &rhs)
Copy constructor.
CoinIndexedVector()
Default constructor.
CoinFactorizationDoubleArrayWithLength & operator=(const CoinFactorizationDoubleArrayWithLength &rhs)
Assignment operator.
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)
CoinDoubleArrayWithLength(int 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.
CoinIndexedVector operator*(const CoinIndexedVector &op2)
Return the element-wise product of two indexed vectors.
CoinIndexedVector & operator=(const CoinIndexedVector &)
Assignment operator.
int capacity() const
Get the capacity (just read it)
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.
bool operator==(const CoinPackedVectorBase &rhs) const
Equal.
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.
const int * getIndices() const
Get indices of elements.
#define COIN_INDEXED_TINY_ELEMENT
void operator/=(double value)
divide every entry by value (** 0 vanishes)
CoinDoubleArrayWithLength(const CoinDoubleArrayWithLength &rhs)
Copy constructor.
int getNumPartitions() const
Get number of partitions.
friend void CoinIndexedVectorUnitTest()
A function that tests the methods in the CoinIndexedVector class.
void insert(int index, double element)
Insert an element into the vector.
void ** array() const
Get Array.
CoinBigIndexArrayWithLength(int size)
Alternate Constructor - length in bytes - size_ -1.
int scanAndPack()
These are same but pack down.
int getMinIndex() const
Get value of minimum index.
void truncate(int newSize)
Throw away all entries in rows >= newSize.