- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

# /home/coin/svn-release/Alps-1.5.2/CoinUtils/src/CoinIndexedVector.hpp

Go to the documentation of this file.

    00001 /* $Id: CoinIndexedVector.hpp 1767 2015-01-05 12:36:13Z forrest $ */
    00002 // Copyright (C) 2000, International Business Machines
    00003 // Corporation and others.  All Rights Reserved.
    00004 // This code is licensed under the terms of the Eclipse Public License (EPL).
    00005
    00006 #ifndef CoinIndexedVector_H
    00007 #define CoinIndexedVector_H
    00008
    00009 #if defined(_MSC_VER)
    00010 // Turn off compiler warning about long names
    00011 #  pragma warning(disable:4786)
    00012 #endif
    00013
    00014 #include <map>
    00015 #include "CoinFinite.hpp"
    00016 #ifndef CLP_NO_VECTOR
    00017 #include "CoinPackedVectorBase.hpp"
    00018 #endif
    00019 #include "CoinSort.hpp"
    00020 #include "CoinHelperFunctions.hpp"
    00021 #include <cassert>
    00022
    00023 #ifndef COIN_FLOAT
    00024 #define COIN_INDEXED_TINY_ELEMENT 1.0e-50
    00025 #define COIN_INDEXED_REALLY_TINY_ELEMENT 1.0e-100
    00026 #else
    00027 #define COIN_INDEXED_TINY_ELEMENT 1.0e-35
    00028 #define COIN_INDEXED_REALLY_TINY_ELEMENT 1.0e-39
    00029 #endif
    00030
    00104 class CoinIndexedVector {
    00105    friend void CoinIndexedVectorUnitTest();
    00106
    00107 public:
    00110
    00111    inline int getNumElements() const { return nElements_; }
    00113    inline const int * getIndices() const { return indices_; }
    00115    // ** No longer supported virtual const double * getElements() const ;
    00117    inline int * getIndices() { return indices_; }
    00121    inline double * denseVector() const { return elements_; }
    00123   inline void setDenseVector(double * array)
    00124   { elements_ = array;}
    00126   inline void setIndexVector(int * array)
    00127   { indices_ = array;}
    00130    double & operator[](int i) const;
    00131
    00133
    00134    //-------------------------------------------------------------------
    00135    // Set indices and elements
    00136    //-------------------------------------------------------------------
    00139
    00140    inline void setNumElements(int value) { nElements_ = value;
    00141    if (!nElements_) packedMode_=false;}
    00143    void clear();
    00145    void empty();
    00147    CoinIndexedVector & operator=(const CoinIndexedVector &);
    00148 #ifndef CLP_NO_VECTOR
    00149
    00151    CoinIndexedVector & operator=(const CoinPackedVectorBase & rhs);
    00152 #endif
    00153
    00156    void copy(const CoinIndexedVector & rhs, double multiplier=1.0);
    00157
    00160   void borrowVector(int size, int numberIndices, int* inds, double* elems);
    00161
    00165    void returnVector();
    00166
    00171   void setVector(int numberIndices, const int * inds, const double * elems);
    00172
    00177    void setVector(int size, int numberIndices, const int * inds, const double * elems);
    00178
    00180   void setConstant(int size, const int * inds, double elems);
    00181
    00183   void setFull(int size, const double * elems);
    00184
    00188    void setElement(int index, double element);
    00189
    00191    void insert(int index, double element);
    00193    inline void quickInsert(int index, double element)
    00194                {
    00195                  assert (!elements_[index]);
    00196                  indices_[nElements_++] = index;
    00197                  assert (nElements_<=capacity_);
    00198                  elements_[index] = element;
    00199                }
    00202    void add(int index, double element);
    00206    inline void quickAdd(int index, double element)
    00207                {
    00208                  if (elements_[index]) {
    00209                    element += elements_[index];
    00210                    if ((element > 0 ? element : -element) >= COIN_INDEXED_TINY_ELEMENT) {
    00211                      elements_[index] = element;
    00212                    } else {
    00213                      elements_[index] = 1.0e-100;
    00214                    }
    00215                  } else if ((element > 0 ? element : -element) >= COIN_INDEXED_TINY_ELEMENT) {
    00216                    indices_[nElements_++] = index;
    00217                    assert (nElements_<=capacity_);
    00218                    elements_[index] = element;
    00219                  }
    00220                }
    00225    inline void quickAddNonZero(int index, double element)
    00226                {
    00227                  assert (element);
    00228                  if (elements_[index]) {
    00229                    element += elements_[index];
    00230                    if ((element > 0 ? element : -element) >= COIN_INDEXED_TINY_ELEMENT) {
    00231                      elements_[index] = element;
    00232                    } else {
    00233                      elements_[index] = COIN_DBL_MIN;
    00234                    }
    00235                  } else {
    00236                    indices_[nElements_++] = index;
    00237                    assert (nElements_<=capacity_);
    00238                    elements_[index] = element;
    00239                  }
    00240                }
    00243    inline void zero(int index)
    00244                {
    00245                  if (elements_[index])
    00246                    elements_[index] = COIN_DBL_MIN;
    00247                }
    00250    int clean(double tolerance);
    00252    int cleanAndPack(double tolerance);
    00254    int cleanAndPackSafe(double tolerance);
    00256   inline void setPacked()
    00257   { packedMode_ = true;}
    00258 #ifndef NDEBUG
    00260    void checkClear();
    00262    void checkClean();
    00263 #else
    00264   inline void checkClear() {};
    00265   inline void checkClean() {};
    00266 #endif
    00268    int scan();
    00269
    00272    int scan(int start, int end);
    00275    int scan(double tolerance);
    00279    int scan(int start, int end, double tolerance);
    00281    int scanAndPack();
    00282    int scanAndPack(int start, int end);
    00283    int scanAndPack(double tolerance);
    00284    int scanAndPack(int start, int end, double tolerance);
    00286    void createPacked(int number, const int * indices,
    00287                     const double * elements);
    00289    void createUnpacked(int number, const int * indices,
    00290                     const double * elements);
    00292    void createOneUnpackedElement(int index, double element);
    00294    void expand();
    00295 #ifndef CLP_NO_VECTOR
    00297    void append(const CoinPackedVectorBase & caboose);
    00298 #endif
    00300    void append(const CoinIndexedVector & caboose);
    00302   void append(CoinIndexedVector & other,int adjustIndex,bool zapElements=false);
    00303
    00305    void swap(int i, int j);
    00306
    00308    void truncate(int newSize);
    00310    void print() const;
    00312
    00314
    00315    void operator+=(double value);
    00317    void operator-=(double value);
    00319    void operator*=(double value);
    00321    void operator/=(double value);
    00323
    00326 #ifndef CLP_NO_VECTOR
    00327
    00329    bool operator==(const CoinPackedVectorBase & rhs) const;
    00331    bool operator!=(const CoinPackedVectorBase & rhs) const;
    00332 #endif
    00333
    00335    bool operator==(const CoinIndexedVector & rhs) const;
    00337    bool operator!=(const CoinIndexedVector & rhs) const;
    00339    int isApproximatelyEqual(const CoinIndexedVector & rhs, double tolerance=1.0e-8) const;
    00341
    00344
    00345    int getMaxIndex() const;
    00347    int getMinIndex() const;
    00349
    00350
    00354    void sort()
    00355    { std::sort(indices_,indices_+nElements_); }
    00356
    00357    void sortIncrIndex()
    00358    { std::sort(indices_,indices_+nElements_); }
    00359
    00360    void sortDecrIndex();
    00361
    00362    void sortIncrElement();
    00363
    00364    void sortDecrElement();
    00365    void sortPacked();
    00366
    00368
    00369   //#############################################################################
    00370
    00382
    00383 CoinIndexedVector operator+(
    00384                            const CoinIndexedVector& op2);
    00385
    00387 CoinIndexedVector operator-(
    00388                            const CoinIndexedVector& op2);
    00389
    00391 CoinIndexedVector operator*(
    00392                            const CoinIndexedVector& op2);
    00393
    00395 CoinIndexedVector operator/(
    00396                            const CoinIndexedVector& op2);
    00398 void operator+=(const CoinIndexedVector& op2);
    00399
    00401 void operator-=( const CoinIndexedVector& op2);
    00402
    00404 void operator*=(const CoinIndexedVector& op2);
    00405
    00407 void operator/=(const CoinIndexedVector& op2);
    00409
    00416    void reserve(int n);
    00420    inline int capacity() const { return capacity_; }
    00421    inline void setCapacity(int value)
    00422    { capacity_ = value; }
    00424    inline void setPackedMode(bool yesNo)
    00425    { packedMode_=yesNo;}
    00427    inline bool packedMode() const
    00428    { return packedMode_;}
    00430
    00434    CoinIndexedVector();
    00436   CoinIndexedVector(int size, const int * inds, const double * elems);
    00438   CoinIndexedVector(int size, const int * inds, double element);
    00441   CoinIndexedVector(int size, const double * elements);
    00443   CoinIndexedVector(int size);
    00445    CoinIndexedVector(const CoinIndexedVector &);
    00447    CoinIndexedVector(const CoinIndexedVector *);
    00448 #ifndef CLP_NO_VECTOR
    00449
    00450    CoinIndexedVector(const CoinPackedVectorBase & rhs);
    00451 #endif
    00452
    00453    ~CoinIndexedVector ();
    00455
    00456 private:
    00459
    00460    void gutsOfSetVector(int size,
    00461                         const int * inds, const double * elems);
    00462    void gutsOfSetVector(int size, int numberIndices,
    00463                         const int * inds, const double * elems);
    00464    void gutsOfSetPackedVector(int size, int numberIndices,
    00465                         const int * inds, const double * elems);
    00467    void gutsOfSetConstant(int size,
    00468                           const int * inds, double value);
    00470
    00471 protected:
    00474
    00475    int * indices_;
    00477    double * elements_;
    00479    int nElements_;
    00481    int capacity_;
    00483    int offset_;
    00485    bool packedMode_;
    00487 };
    00488
    00489 //#############################################################################
    00495 void
    00496 CoinIndexedVectorUnitTest();
    00513 class CoinArrayWithLength {
    00514
    00515 public:
    00518
    00519   inline int getSize() const
    00520   { return size_; }
    00522   inline int rawSize() const
    00523   { return size_; }
    00525   inline bool switchedOn() const
    00526   { return size_!=-1; }
    00528   inline int capacity() const
    00529   { return (size_>-2) ? size_ : (-size_)-2; }
    00531   inline void setCapacity()
    00532   { if (size_<=-2) size_ = (-size_)-2; }
    00534   inline const char * array() const
    00535   { return (size_>-2) ? array_ : NULL; }
    00537
    00540
    00541   inline void setSize(int value)
    00542   { size_ = value; }
    00544   inline void switchOff()
    00545   { size_ = -1; }
    00547   inline void switchOn(int alignment=3)
    00548   { size_ = -2; alignment_=alignment;}
    00550   void setPersistence(int flag,int currentLength);
    00552   void clear();
    00554   void swap(CoinArrayWithLength & other);
    00556   void extend(int newSize);
    00558
    00561
    00562   char * conditionalNew(long sizeWanted);
    00564   void conditionalDelete();
    00566
    00570   inline CoinArrayWithLength()
    00571     : array_(NULL),size_(-1),offset_(0),alignment_(0)
    00572   { }
    00574   inline CoinArrayWithLength(int size)
    00575     : size_(-1),offset_(0),alignment_(0)
    00576   { array_=new char [size];}
    00583   CoinArrayWithLength(int size, int mode);
    00585   CoinArrayWithLength(const CoinArrayWithLength & rhs);
    00587   CoinArrayWithLength(const CoinArrayWithLength * rhs);
    00589   CoinArrayWithLength& operator=(const CoinArrayWithLength & rhs);
    00591   void copy(const CoinArrayWithLength & rhs, int numberBytes=-1);
    00593   void allocate(const CoinArrayWithLength & rhs, int numberBytes);
    00595   ~CoinArrayWithLength ();
    00597   void getArray(int size);
    00599   void reallyFreeArray();
    00601   void getCapacity(int numberBytes,int numberIfNeeded=-1);
    00603
    00604 protected:
    00607
    00608   char * array_;
    00610   CoinBigIndex size_;
    00612   int offset_;
    00614   int alignment_;
    00616 };
    00618
    00619 class CoinDoubleArrayWithLength : public CoinArrayWithLength {
    00620
    00621 public:
    00624
    00625   inline int getSize() const
    00626   { return size_/CoinSizeofAsInt(double); }
    00628   inline double * array() const
    00629   { return reinterpret_cast<double *> ((size_>-2) ? array_ : NULL); }
    00631
    00634
    00635   inline void setSize(int value)
    00636   { size_ = value*CoinSizeofAsInt(double); }
    00638
    00641
    00642   inline double * conditionalNew(int sizeWanted)
    00643   { return reinterpret_cast<double *> ( CoinArrayWithLength::conditionalNew(sizeWanted>=0 ? static_cast<long> ((sizeWanted)*CoinSizeofAsInt(double)) : -1)); }
    00645
    00649   inline CoinDoubleArrayWithLength()
    00650   { array_=NULL; size_=-1;}
    00652   inline CoinDoubleArrayWithLength(int size)
    00653   { array_=new char [size*CoinSizeofAsInt(double)]; size_=-1;}
    00658   inline CoinDoubleArrayWithLength(int size, int mode)
    00659     : CoinArrayWithLength(size*CoinSizeofAsInt(double),mode) {}
    00661   inline CoinDoubleArrayWithLength(const CoinDoubleArrayWithLength & rhs)
    00662     : CoinArrayWithLength(rhs) {}
    00664   inline CoinDoubleArrayWithLength(const CoinDoubleArrayWithLength * rhs)
    00665     : CoinArrayWithLength(rhs) {}
    00667   inline CoinDoubleArrayWithLength& operator=(const CoinDoubleArrayWithLength & rhs)
    00668   { CoinArrayWithLength::operator=(rhs);  return *this;}
    00670 };
    00672
    00673 class CoinFactorizationDoubleArrayWithLength : public CoinArrayWithLength {
    00674
    00675 public:
    00678
    00679   inline int getSize() const
    00680   { return size_/CoinSizeofAsInt(CoinFactorizationDouble); }
    00682   inline CoinFactorizationDouble * array() const
    00683   { return reinterpret_cast<CoinFactorizationDouble *> ((size_>-2) ? array_ : NULL); }
    00685
    00688
    00689   inline void setSize(int value)
    00690   { size_ = value*CoinSizeofAsInt(CoinFactorizationDouble); }
    00692
    00695
    00696   inline CoinFactorizationDouble * conditionalNew(int sizeWanted)
    00697   { return reinterpret_cast<CoinFactorizationDouble *> (CoinArrayWithLength::conditionalNew(sizeWanted>=0 ? static_cast<long> (( sizeWanted)*CoinSizeofAsInt(CoinFactorizationDouble)) : -1)); }
    00699
    00703   inline CoinFactorizationDoubleArrayWithLength()
    00704   { array_=NULL; size_=-1;}
    00706   inline CoinFactorizationDoubleArrayWithLength(int size)
    00707   { array_=new char [size*CoinSizeofAsInt(CoinFactorizationDouble)]; size_=-1;}
    00712   inline CoinFactorizationDoubleArrayWithLength(int size, int mode)
    00713     : CoinArrayWithLength(size*CoinSizeofAsInt(CoinFactorizationDouble),mode) {}
    00715   inline CoinFactorizationDoubleArrayWithLength(const CoinFactorizationDoubleArrayWithLength & rhs)
    00716     : CoinArrayWithLength(rhs) {}
    00718   inline CoinFactorizationDoubleArrayWithLength(const CoinFactorizationDoubleArrayWithLength * rhs)
    00719     : CoinArrayWithLength(rhs) {}
    00721   inline CoinFactorizationDoubleArrayWithLength& operator=(const CoinFactorizationDoubleArrayWithLength & rhs)
    00722   { CoinArrayWithLength::operator=(rhs);  return *this;}
    00724 };
    00726
    00727 class CoinFactorizationLongDoubleArrayWithLength : public CoinArrayWithLength {
    00728
    00729 public:
    00732
    00733   inline int getSize() const
    00734   { return size_/CoinSizeofAsInt(long double); }
    00736   inline long double * array() const
    00737   { return reinterpret_cast<long double *> ((size_>-2) ? array_ : NULL); }
    00739
    00742
    00743   inline void setSize(int value)
    00744   { size_ = value*CoinSizeofAsInt(long double); }
    00746
    00749
    00750   inline long double * conditionalNew(int sizeWanted)
    00751   { return reinterpret_cast<long double *> (CoinArrayWithLength::conditionalNew(sizeWanted>=0 ? static_cast<long> (( sizeWanted)*CoinSizeofAsInt(long double)) : -1)); }
    00753
    00757   inline CoinFactorizationLongDoubleArrayWithLength()
    00758   { array_=NULL; size_=-1;}
    00760   inline CoinFactorizationLongDoubleArrayWithLength(int size)
    00761   { array_=new char [size*CoinSizeofAsInt(long double)]; size_=-1;}
    00766   inline CoinFactorizationLongDoubleArrayWithLength(int size, int mode)
    00767     : CoinArrayWithLength(size*CoinSizeofAsInt(long double),mode) {}
    00769   inline CoinFactorizationLongDoubleArrayWithLength(const CoinFactorizationLongDoubleArrayWithLength & rhs)
    00770     : CoinArrayWithLength(rhs) {}
    00772   inline CoinFactorizationLongDoubleArrayWithLength(const CoinFactorizationLongDoubleArrayWithLength * rhs)
    00773     : CoinArrayWithLength(rhs) {}
    00775   inline CoinFactorizationLongDoubleArrayWithLength& operator=(const CoinFactorizationLongDoubleArrayWithLength & rhs)
    00776   { CoinArrayWithLength::operator=(rhs);  return *this;}
    00778 };
    00780
    00781 class CoinIntArrayWithLength : public CoinArrayWithLength {
    00782
    00783 public:
    00786
    00787   inline int getSize() const
    00788   { return size_/CoinSizeofAsInt(int); }
    00790   inline int * array() const
    00791   { return reinterpret_cast<int *> ((size_>-2) ? array_ : NULL); }
    00793
    00796
    00797   inline void setSize(int value)
    00798   { size_ = value*CoinSizeofAsInt(int); }
    00800
    00803
    00804   inline int * conditionalNew(int sizeWanted)
    00805   { return reinterpret_cast<int *> (CoinArrayWithLength::conditionalNew(sizeWanted>=0 ? static_cast<long> (( sizeWanted)*CoinSizeofAsInt(int)) : -1)); }
    00807
    00811   inline CoinIntArrayWithLength()
    00812   { array_=NULL; size_=-1;}
    00814   inline CoinIntArrayWithLength(int size)
    00815   { array_=new char [size*CoinSizeofAsInt(int)]; size_=-1;}
    00820   inline CoinIntArrayWithLength(int size, int mode)
    00821     : CoinArrayWithLength(size*CoinSizeofAsInt(int),mode) {}
    00823   inline CoinIntArrayWithLength(const CoinIntArrayWithLength & rhs)
    00824     : CoinArrayWithLength(rhs) {}
    00826   inline CoinIntArrayWithLength(const CoinIntArrayWithLength * rhs)
    00827     : CoinArrayWithLength(rhs) {}
    00829   inline CoinIntArrayWithLength& operator=(const CoinIntArrayWithLength & rhs)
    00830   { CoinArrayWithLength::operator=(rhs);  return *this;}
    00832 };
    00834
    00835 class CoinBigIndexArrayWithLength : public CoinArrayWithLength {
    00836
    00837 public:
    00840
    00841   inline int getSize() const
    00842   { return size_/CoinSizeofAsInt(CoinBigIndex); }
    00844   inline CoinBigIndex * array() const
    00845   { return reinterpret_cast<CoinBigIndex *> ((size_>-2) ? array_ : NULL); }
    00847
    00850
    00851   inline void setSize(int value)
    00852   { size_ = value*CoinSizeofAsInt(CoinBigIndex); }
    00854
    00857
    00858   inline CoinBigIndex * conditionalNew(int sizeWanted)
    00859   { return reinterpret_cast<CoinBigIndex *> (CoinArrayWithLength::conditionalNew(sizeWanted>=0 ? static_cast<long> (( sizeWanted)*CoinSizeofAsInt(CoinBigIndex)) : -1)); }
    00861
    00865   inline CoinBigIndexArrayWithLength()
    00866   { array_=NULL; size_=-1;}
    00868   inline CoinBigIndexArrayWithLength(int size)
    00869   { array_=new char [size*CoinSizeofAsInt(CoinBigIndex)]; size_=-1;}
    00874   inline CoinBigIndexArrayWithLength(int size, int mode)
    00875     : CoinArrayWithLength(size*CoinSizeofAsInt(CoinBigIndex),mode) {}
    00877   inline CoinBigIndexArrayWithLength(const CoinBigIndexArrayWithLength & rhs)
    00878     : CoinArrayWithLength(rhs) {}
    00880   inline CoinBigIndexArrayWithLength(const CoinBigIndexArrayWithLength * rhs)
    00881     : CoinArrayWithLength(rhs) {}
    00883   inline CoinBigIndexArrayWithLength& operator=(const CoinBigIndexArrayWithLength & rhs)
    00884   { CoinArrayWithLength::operator=(rhs);  return *this;}
    00886 };
    00888
    00889 class CoinUnsignedIntArrayWithLength : public CoinArrayWithLength {
    00890
    00891 public:
    00894
    00895   inline int getSize() const
    00896   { return size_/CoinSizeofAsInt(unsigned int); }
    00898   inline unsigned int * array() const
    00899   { return reinterpret_cast<unsigned int *> ((size_>-2) ? array_ : NULL); }
    00901
    00904
    00905   inline void setSize(int value)
    00906   { size_ = value*CoinSizeofAsInt(unsigned int); }
    00908
    00911
    00912   inline unsigned int * conditionalNew(int sizeWanted)
    00913   { return reinterpret_cast<unsigned int *> (CoinArrayWithLength::conditionalNew(sizeWanted>=0 ? static_cast<long> (( sizeWanted)*CoinSizeofAsInt(unsigned int)) : -1)); }
    00915
    00919   inline CoinUnsignedIntArrayWithLength()
    00920   { array_=NULL; size_=-1;}
    00922   inline CoinUnsignedIntArrayWithLength(int size)
    00923   { array_=new char [size*CoinSizeofAsInt(unsigned int)]; size_=-1;}
    00928   inline CoinUnsignedIntArrayWithLength(int size, int mode)
    00929     : CoinArrayWithLength(size*CoinSizeofAsInt(unsigned int),mode) {}
    00931   inline CoinUnsignedIntArrayWithLength(const CoinUnsignedIntArrayWithLength & rhs)
    00932     : CoinArrayWithLength(rhs) {}
    00934   inline CoinUnsignedIntArrayWithLength(const CoinUnsignedIntArrayWithLength * rhs)
    00935     : CoinArrayWithLength(rhs) {}
    00937   inline CoinUnsignedIntArrayWithLength& operator=(const CoinUnsignedIntArrayWithLength & rhs)
    00938   { CoinArrayWithLength::operator=(rhs);  return *this;}
    00940 };
    00942
    00943 class CoinVoidStarArrayWithLength : public CoinArrayWithLength {
    00944
    00945 public:
    00948
    00949   inline int getSize() const
    00950   { return size_/CoinSizeofAsInt(void *); }
    00952   inline void ** array() const
    00953   { return reinterpret_cast<void **> ((size_>-2) ? array_ : NULL); }
    00955
    00958
    00959   inline void setSize(int value)
    00960   { size_ = value*CoinSizeofAsInt(void *); }
    00962
    00965
    00966   inline void ** conditionalNew(int sizeWanted)
    00967   { return reinterpret_cast<void **> ( CoinArrayWithLength::conditionalNew(sizeWanted>=0 ? static_cast<long> ((sizeWanted)*CoinSizeofAsInt(void *)) : -1)); }
    00969
    00973   inline CoinVoidStarArrayWithLength()
    00974   { array_=NULL; size_=-1;}
    00976   inline CoinVoidStarArrayWithLength(int size)
    00977   { array_=new char [size*CoinSizeofAsInt(void *)]; size_=-1;}
    00982   inline CoinVoidStarArrayWithLength(int size, int mode)
    00983     : CoinArrayWithLength(size*CoinSizeofAsInt(void *),mode) {}
    00985   inline CoinVoidStarArrayWithLength(const CoinVoidStarArrayWithLength & rhs)
    00986     : CoinArrayWithLength(rhs) {}
    00988   inline CoinVoidStarArrayWithLength(const CoinVoidStarArrayWithLength * rhs)
    00989     : CoinArrayWithLength(rhs) {}
    00991   inline CoinVoidStarArrayWithLength& operator=(const CoinVoidStarArrayWithLength & rhs)
    00992   { CoinArrayWithLength::operator=(rhs);  return *this;}
    00994 };
    00996
    00997 class CoinArbitraryArrayWithLength : public CoinArrayWithLength {
    00998
    00999 public:
    01002
    01003   inline int getSize() const
    01004   { return size_/lengthInBytes_; }
    01006   inline void ** array() const
    01007   { return reinterpret_cast<void **> ((size_>-2) ? array_ : NULL); }
    01009
    01012
    01013   inline void setSize(int value)
    01014   { size_ = value*lengthInBytes_; }
    01016
    01019
    01020   inline char * conditionalNew(int length, int sizeWanted)
    01021   { lengthInBytes_=length;return reinterpret_cast<char *> ( CoinArrayWithLength::conditionalNew(sizeWanted>=0 ? static_cast<long>
    01022                                                                           ((sizeWanted)*lengthInBytes_) : -1)); }
    01024
    01028   inline CoinArbitraryArrayWithLength(int length=1)
    01029   { array_=NULL; size_=-1;lengthInBytes_=length;}
    01031   inline CoinArbitraryArrayWithLength(int length, int size)
    01032   { array_=new char [size*length]; size_=-1; lengthInBytes_=length;}
    01037   inline CoinArbitraryArrayWithLength(int length, int size, int mode)
    01038     : CoinArrayWithLength(size*length,mode) {lengthInBytes_=length;}
    01040   inline CoinArbitraryArrayWithLength(const CoinArbitraryArrayWithLength & rhs)
    01041     : CoinArrayWithLength(rhs) {}
    01043   inline CoinArbitraryArrayWithLength(const CoinArbitraryArrayWithLength * rhs)
    01044     : CoinArrayWithLength(rhs) {}
    01046   inline CoinArbitraryArrayWithLength& operator=(const CoinArbitraryArrayWithLength & rhs)
    01047   { CoinArrayWithLength::operator=(rhs);  return *this;}
    01049
    01050 protected:
    01053
    01054   int lengthInBytes_;
    01056 };
    01057 class CoinPartitionedVector : public CoinIndexedVector {
    01058
    01059 public:
    01060 #ifndef COIN_PARTITIONS
    01061 #define COIN_PARTITIONS 8
    01062 #endif
    01063
    01065
    01066    inline int getNumElements(int partition) const { assert (partition<COIN_PARTITIONS);
    01067      return numberElementsPartition_[partition]; }
    01069    inline int getNumPartitions() const
    01070   { return numberPartitions_; }
    01072    inline int getNumElements() const { return nElements_; }
    01074   inline int startPartition(int partition) const  { assert (partition<=COIN_PARTITIONS);
    01075     return startPartition_[partition]; }
    01077   inline const int * startPartitions() const
    01078   { return startPartition_; }
    01080
    01081    //-------------------------------------------------------------------
    01082    // Set indices and elements
    01083    //-------------------------------------------------------------------
    01086
    01087   inline void setNumElementsPartition(int partition, int value) { assert (partition<COIN_PARTITIONS);
    01088     if (numberPartitions_) numberElementsPartition_[partition]=value; }
    01090   inline void setTempNumElementsPartition(int partition, int value) { assert (partition<COIN_PARTITIONS);
    01091     numberElementsPartition_[partition]=value; }
    01093   void computeNumberElements();
    01095   void compact();
    01098    void reserve(int n);
    01100   void setPartitions(int number,const int * starts);
    01102    void clearAndReset();
    01104    void clearAndKeep();
    01106    void clearPartition(int partition);
    01107 #ifndef NDEBUG
    01109    void checkClear();
    01111    void checkClean();
    01112 #else
    01113   inline void checkClear() {};
    01114   inline void checkClean() {};
    01115 #endif
    01117   int scan(int partition, double tolerance=0.0);
    01118
    01121
    01122    void print() const;
    01124
    01128   void sort();
    01130
    01134    CoinPartitionedVector();
    01136   CoinPartitionedVector(int size, const int * inds, const double * elems);
    01138   CoinPartitionedVector(int size, const int * inds, double element);
    01141   CoinPartitionedVector(int size, const double * elements);
    01143   CoinPartitionedVector(int size);
    01145    CoinPartitionedVector(const CoinPartitionedVector &);
    01147    CoinPartitionedVector(const CoinPartitionedVector *);
    01149    CoinPartitionedVector & operator=(const CoinPartitionedVector &);
    01151    ~CoinPartitionedVector ();
    01153 protected:
    01156
    01157    int startPartition_[COIN_PARTITIONS+1];
    01159    int numberElementsPartition_[COIN_PARTITIONS];
    01161   int numberPartitions_;
    01163 };
    01164 #endif