6 #ifndef CoinIndexedVector_H
7 #define CoinIndexedVector_H
11 #pragma warning(disable : 4786)
24 #define COIN_INDEXED_TINY_ELEMENT 1.0e-50
25 #define COIN_INDEXED_REALLY_TINY_ELEMENT 1.0e-100
27 #define COIN_INDEXED_TINY_ELEMENT 1.0e-35
28 #define COIN_INDEXED_REALLY_TINY_ELEMENT 1.0e-39
158 #ifndef CLP_NO_VECTOR
170 void borrowVector(
int size,
int numberIndices,
int *inds,
double *elems);
181 void setVector(
int numberIndices,
const int *inds,
const double *elems);
187 void setVector(
int size,
int numberIndices,
const int *inds,
const double *elems);
212 void add(
int index,
double element);
291 int scan(
int start,
int end,
double tolerance);
299 const double *elements);
302 const double *elements);
307 #ifndef CLP_NO_VECTOR
338 #ifndef CLP_NO_VECTOR
469 #ifndef CLP_NO_VECTOR
482 const int *inds,
const double *elems);
484 const int *inds,
const double *elems);
486 const int *inds,
const double *elems);
489 const int *inds,
double value);
580 inline void setSize(
long long value)
606 void extend(
long long newSize);
691 return reinterpret_cast< double *
>((
size_ > -2) ?
array_ : NULL);
845 return reinterpret_cast< long double *
>((
size_ > -2) ?
array_ : NULL);
922 return reinterpret_cast< int *
>((
size_ > -2) ?
array_ : NULL);
1076 return reinterpret_cast< unsigned int *
>((
size_ > -2) ?
array_ : NULL);
1153 return reinterpret_cast< void **
>((
size_ > -2) ?
array_ : NULL);
1230 return reinterpret_cast< void **
>((
size_ > -2) ?
array_ : NULL);
1265 array_ =
new char[size * length];
1306 #ifndef COIN_PARTITIONS
1307 #define COIN_PARTITIONS 8
1380 int scan(
int partition,
double tolerance = 0.0);
1431 int iBottom =
static_cast< int >(xx & 63);
1433 return address + ((64 - iBottom) >> 3);
const double COIN_DBL_MIN
#define CoinSizeofAsInt(type)
Cube Root.
void CoinIndexedVectorUnitTest()
A function that tests the methods in the CoinIndexedVector class.
#define COIN_INDEXED_TINY_ELEMENT
double * roundUpDouble(double *address)
double CoinFactorizationDouble
char * conditionalNew(CoinBigIndex length, CoinBigIndex sizeWanted)
Conditionally gets new array.
void ** array() const
Get Array.
CoinArbitraryArrayWithLength(const CoinArbitraryArrayWithLength *rhs)
Copy constructor.2.
CoinArbitraryArrayWithLength & operator=(const CoinArbitraryArrayWithLength &rhs)
Assignment operator.
CoinArbitraryArrayWithLength(int length=1)
Default constructor - NULL.
CoinBigIndex lengthInBytes_
Length in bytes.
CoinArbitraryArrayWithLength(const CoinArbitraryArrayWithLength &rhs)
Copy constructor.
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.
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.
const char * array() const
Get Array.
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.
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)
char * conditionalNew(CoinBigIndex sizeWanted)
Conditionally gets new array.
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.
CoinArrayWithLength & operator=(const CoinArrayWithLength &rhs)
Assignment operator.
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.
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.
CoinBigIndexArrayWithLength()
Default constructor - NULL.
CoinBigIndexArrayWithLength(const CoinBigIndexArrayWithLength &rhs)
Copy constructor.
void setSize(CoinBigIndex value)
Set the size.
CoinBigIndexArrayWithLength(const CoinBigIndexArrayWithLength *rhs)
Copy constructor.2.
CoinBigIndex * conditionalNew(CoinBigIndex sizeWanted)
Conditionally gets new array.
CoinBigIndexArrayWithLength(CoinBigIndex 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 * array() const
Get Array.
CoinBigIndexArrayWithLength(CoinBigIndex size)
Alternate Constructor - length in bytes - size_ -1.
CoinBigIndexArrayWithLength & operator=(const CoinBigIndexArrayWithLength &rhs)
Assignment operator.
CoinDoubleArrayWithLength()
Default constructor - NULL.
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.
CoinDoubleArrayWithLength(int size)
Alternate Constructor - length in bytes - size_ -1.
CoinDoubleArrayWithLength & operator=(const CoinDoubleArrayWithLength &rhs)
Assignment operator.
CoinDoubleArrayWithLength(const CoinDoubleArrayWithLength &rhs)
Copy constructor.
CoinDoubleArrayWithLength(const CoinDoubleArrayWithLength *rhs)
Copy constructor.2.
double * array() const
Get Array.
CoinFactorizationDouble * version.
CoinBigIndex getSize() const
Get the size.
CoinFactorizationDoubleArrayWithLength()
Default constructor - NULL.
CoinFactorizationDoubleArrayWithLength(const CoinFactorizationDoubleArrayWithLength &rhs)
Copy constructor.
CoinFactorizationDoubleArrayWithLength(int size)
Alternate Constructor - length in bytes - size_ -1.
CoinFactorizationDouble * conditionalNew(CoinBigIndex sizeWanted)
Conditionally gets new array.
CoinFactorizationDoubleArrayWithLength(int size, int mode)
Alternate Constructor - length in bytes mode - 0 size_ set to size 1 size_ set to size and zeroed.
CoinFactorizationDoubleArrayWithLength & operator=(const CoinFactorizationDoubleArrayWithLength &rhs)
Assignment operator.
CoinFactorizationDoubleArrayWithLength(const CoinFactorizationDoubleArrayWithLength *rhs)
Copy constructor.2.
void setSize(int value)
Set the size.
CoinFactorizationDouble * array() const
Get Array.
CoinFactorizationLongDouble * version.
long double * conditionalNew(CoinBigIndex sizeWanted)
Conditionally gets new array.
void setSize(int value)
Set the size.
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 * array() const
Get 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.
const int * getIndices() const
Get indices of elements.
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.
CoinIndexedVector & operator=(const CoinPackedVectorBase &rhs)
Assignment operator from a CoinPackedVectorBase.
friend void CoinIndexedVectorUnitTest()
A function that tests the methods in the CoinIndexedVector class.
void setPackedMode(bool yesNo)
Sets packed mode.
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.
double & operator[](int i) const
Access the i'th element of the full storage vector.
int * getIndices()
Get element values.
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 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)
CoinIndexedVector & operator=(const CoinIndexedVector &)
Assignment operator.
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.
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.
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.
double * denseVector() const
Get the vector as a dense vector.
int scan(double tolerance)
Scan dense region and set up indices (returns number found).
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.
void setSize(int value)
Set the size.
CoinIntArrayWithLength & operator=(const CoinIntArrayWithLength &rhs)
Assignment operator.
CoinIntArrayWithLength(int size, int mode)
Alternate Constructor - length in bytes mode - 0 size_ set to size 1 size_ set to size and zeroed.
int * conditionalNew(CoinBigIndex sizeWanted)
Conditionally gets new array.
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 & operator=(const CoinPartitionedVector &)
Assignment operator.
CoinPartitionedVector(const CoinPartitionedVector &)
Copy constructor.
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.
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.
const int * startPartitions() const
Get starts.
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.
CoinUnsignedIntArrayWithLength(int size)
Alternate Constructor - length in bytes - size_ -1.
void setSize(int value)
Set the size.
unsigned int * conditionalNew(CoinBigIndex sizeWanted)
Conditionally gets new array.
CoinUnsignedIntArrayWithLength & operator=(const CoinUnsignedIntArrayWithLength &rhs)
Assignment operator.
CoinUnsignedIntArrayWithLength()
Default constructor - NULL.
CoinUnsignedIntArrayWithLength(const CoinUnsignedIntArrayWithLength &rhs)
Copy constructor.
unsigned int * array() const
Get Array.
CoinUnsignedIntArrayWithLength(const CoinUnsignedIntArrayWithLength *rhs)
Copy constructor.2.
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.
void ** conditionalNew(CoinBigIndex sizeWanted)
Conditionally gets new array.
void ** array() const
Get Array.
CoinVoidStarArrayWithLength(int size)
Alternate Constructor - length in bytes - size_ -1.
CoinVoidStarArrayWithLength(const CoinVoidStarArrayWithLength *rhs)
Copy constructor.2.
CoinVoidStarArrayWithLength & operator=(const CoinVoidStarArrayWithLength &rhs)
Assignment operator.
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.
CoinVoidStarArrayWithLength()
Default constructor - NULL.