Scippy

SoPlex

Sequential object-oriented simPlex

didxset.h
Go to the documentation of this file.
1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2 /* */
3 /* This file is part of the class library */
4 /* SoPlex --- the Sequential object-oriented simPlex. */
5 /* */
6 /* Copyright (C) 1996-2015 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 "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  IdxSet::add(n);
55  }
56 
57  /// adds all indices from \p sv.
58  void add(const IdxSet& sv)
59  {
60  int n = sv.size();
61  if (max() - size() < n)
62  setMax(size() + n);
63  IdxSet::add(sv);
64  }
65 
66  /// adds \p n indices from \p i.
67  void add(int n, const int *i)
68  {
69  if (max() - size() < n)
70  setMax(size() + n);
71  IdxSet::add(n, i);
72  }
73 
74  /// adds index \p i to the index set
75  void addIdx(int i)
76  {
77  if (max() <= size())
78  setMax(size() + 1);
79  IdxSet::addIdx(i);
80  }
81 
82  /// sets the maximum number of indices.
83  /** This methods resets the memory consumption of the DIdxSet to
84  * \p newmax. However, if \p newmax < size(), it is reset to size()
85  * only.
86  */
87  void setMax(int newmax = 1);
88  //@}
89 
90  //-----------------------------------
91  /**@name Construction / destruction */
92  //@{
93  /// default constructor. \p n gives the initial size of the index space.
94  explicit DIdxSet(int n = 8);
95 
96  /// copy constructor from IdxSet.
97  explicit DIdxSet(const IdxSet& old);
98 
99  /// copy constructor from DIdxSet.
100  DIdxSet(const DIdxSet& old);
101 
102  /// assignment operator from IdxSet
104  {
105  if (this != &sv)
106  {
107  setMax( sv.size() );
108  IdxSet::operator=(sv);
109  }
110  return *this;
111  }
112  /// assignment operator from DIdxSet
114  {
115  if (this != &sv)
116  {
117  setMax( sv.size() );
118  IdxSet::operator=(sv);
119  }
120  return *this;
121  }
122  /// destructor.
123  virtual ~DIdxSet();
124  //@}
125 };
126 
127 } // namespace soplex
128 #endif // _DIDXSET_H_