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);
190 void setConstant(
int size,
const int *inds,
double elems);
193 void setFull(
int size,
const double *elems);
201 void insert(
int index,
double element);
212 void add(
int index,
double element);
260 int clean(
double tolerance);
284 int scan(
int start,
int end);
287 int scan(
double tolerance);
291 int scan(
int start,
int end,
double tolerance);
296 int scanAndPack(
int start,
int end,
double tolerance);
299 const double *elements);
302 const double *elements);
307 #ifndef CLP_NO_VECTOR
317 void swap(
int i,
int j);
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);
579 inline void setSize(
long long value)
605 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);
1082 inline void setSize(
int value)
1153 return reinterpret_cast< void **
>((
size_ > -2) ?
array_ : NULL);
1159 inline void setSize(
int value)
1230 return reinterpret_cast< void **
>((
size_ > -2) ?
array_ : NULL);
1236 inline void setSize(
int value)
1265 array_ =
new char[size * length];
1306 #ifndef COIN_PARTITIONS
1307 #define COIN_PARTITIONS 8
1379 int scan(
int partition,
double tolerance = 0.0);
1431 int iBottom =
static_cast< int >(xx & 63);
1433 return address + ((64 - iBottom) >> 3);
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'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 "index" 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 setSize(int value)
Set the size.
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 >=0 if <=-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.
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
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 < 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
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.
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 => 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.
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.
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 >= newSize.
void setSize(int value)
Set the size.