1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 2 /* */ 3 /* This file is part of the class library */ 4 /* SoPlex --- the Sequential object-oriented simPlex. */ 5 /* */ 6 /* Copyright (C) 1996-2022 Konrad-Zuse-Zentrum */ 7 /* fuer Informationstechnik Berlin */ 8 /* */ 9 /* SoPlex is distributed under the terms of the ZIB Academic Licence. */ 10 /* */ 11 /* You should have received a copy of the ZIB Academic License */ 12 /* along with SoPlex; see the file COPYING. If not email to soplex@zib.de. */ 13 /* */ 14 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 15 16 /**@file didxset.h 17 * @brief Dymnamic index set. 18 */ 19 #ifndef _DIDXSET_H_ 20 #define _DIDXSET_H_ 21 22 #include <assert.h> 23 24 #include "soplex/idxset.h" 25 26 namespace soplex 27 { 28 29 /**@brief Dynamic index set. 30 @ingroup Elementary 31 32 Class DIdxSet provides dynamic IdxSet in the sense, that no 33 restrictions are posed on the use of methods add(). However, method 34 indexMem() has been moved to the private members. This is because 35 DIdxSet adds its own memory management to class IdxSet and the user must 36 not interfere with it. 37 38 Upon construction of an DIdxSet, memory is allocated automatically. The 39 memory consumption can be controlled with methods max() and setMax(). 40 Finally, the destructor will release all allocated memory. 41 */ 42 class DIdxSet : public IdxSet 43 { 44 public: 45 46 //----------------------------------- 47 /**@name Adding */ 48 ///@{ 49 /// adds \p n uninitialized indices. 50 void add(int n) 51 { 52 if(max() - size() < n) 53 setMax(size() + n); 54 55 IdxSet::add(n); 56 } 57 58 /// adds all indices from \p sv. 59 void add(const IdxSet& sv) 60 { 61 int n = sv.size(); 62 63 if(max() - size() < n) 64 setMax(size() + n); 65 66 IdxSet::add(sv); 67 } 68 69 /// adds \p n indices from \p i. 70 void add(int n, const int* i) 71 { 72 if(max() - size() < n) 73 setMax(size() + n); 74 75 IdxSet::add(n, i); 76 } 77 78 /// adds index \p i to the index set 79 void addIdx(int i) 80 { 81 if(max() <= size()) 82 setMax(size() + 1); 83 84 IdxSet::addIdx(i); 85 } 86 87 /// sets the maximum number of indices. 88 /** This methods resets the memory consumption of the DIdxSet to 89 * \p newmax. However, if \p newmax < size(), it is reset to size() 90 * only. 91 */ 92 void setMax(int newmax = 1); 93 ///@} 94 95 //----------------------------------- 96 /**@name Construction / destruction */ 97 ///@{ 98 /// default constructor. \p n gives the initial size of the index space. 99 explicit DIdxSet(int n = 8); 100 101 /// copy constructor from IdxSet. 102 explicit DIdxSet(const IdxSet& old); 103 104 /// copy constructor from DIdxSet. 105 DIdxSet(const DIdxSet& old); 106 107 /// assignment operator from IdxSet 108 DIdxSet& operator=(const IdxSet& sv) 109 { 110 if(this != &sv) 111 { 112 setMax(sv.size()); 113 IdxSet::operator=(sv); 114 } 115 116 return *this; 117 } 118 /// assignment operator from DIdxSet 119 DIdxSet& operator=(const DIdxSet& sv) 120 { 121 if(this != &sv) 122 { 123 setMax(sv.size()); 124 IdxSet::operator=(sv); 125 } 126 127 return *this; 128 } 129 /// destructor. 130 virtual ~DIdxSet(); 131 ///@} 132 }; 133 134 } // namespace soplex 135 #endif // _DIDXSET_H_ 136