COPASI API  4.16.103
CZeroSet.h
Go to the documentation of this file.
1 // Begin CVS Header
2 // $Source: /Volumes/Home/Users/shoops/cvs/copasi_dev/copasi/elementaryFluxModes/CZeroSet.h,v $
3 // $Revision: 1.10 $
4 // $Name: $
5 // $Author: shoops $
6 // $Date: 2011/03/07 19:27:35 $
7 // End CVS Header
8 
9 // Copyright (C) 2011 - 2010 by Pedro Mendes, Virginia Tech Intellectual
10 // Properties, Inc., University of Heidelberg, and The University
11 // of Manchester.
12 // All rights reserved.
13 
14 // Copyright (C) 2008 by Pedro Mendes, Virginia Tech Intellectual
15 // Properties, Inc., EML Research, gGmbH, University of Heidelberg,
16 // and The University of Manchester.
17 // All rights reserved.
18 
19 #ifndef COPASI_CZeroSet
20 #define COPASI_CZeroSet
21 
22 #include <limits.h> // needed for CHAR_BIT, <limits.h> is not the same as <limits>
23 
24 #include <vector>
25 
27 
28 class CStepMatrixColumn;
29 
30 class CZeroSet
31 {
32 public:
33  class CIndex
34  {
35  friend class CZeroSet;
36 
37  // Operations
38  public:
39  CIndex(const size_t & index = 0);
40 
41  CIndex(const CIndex & src);
42 
43  ~CIndex();
44 
45  CIndex & operator ++ ();
46 
47  CIndex & operator = (const CIndex & rhs);
48 
49  CIndex & operator = (const size_t & index);
50 
51  bool operator < (const CIndex & rhs) const;
52 
53  // Attributes
54  private:
55  size_t mIndex;
56  size_t mBit;
57  size_t mNotBit;
58  };
59 
60  friend std::ostream & operator << (std::ostream &, const CZeroSet &);
61 
62  CZeroSet(const size_t & index = 0);
63 
64  CZeroSet(const CZeroSet & src);
65 
66  ~CZeroSet();
67 
68  inline void setBit(const CIndex & index)
69  {
70  mBitSet[index.mIndex] |= index.mBit;
72  }
73 
74  inline void unsetBit(const CIndex & index)
75  {
76  mBitSet[index.mIndex] &= index.mNotBit;
78  }
79 
80  inline bool isSet(const CIndex & index) const
81  {
82  return (mBitSet[index.mIndex] & index.mBit) > 0;
83  }
84 
85  inline const size_t & getNumberOfSetBits() const
86  {
87  return mNumberSetBits;
88  }
89 
90  inline size_t getNumberOfUnsetBits() const
91  {
92  return mBitSet.size() * CHAR_BIT * sizeof(size_t) - mIgnoredBits - mNumberSetBits;
93  }
94 
95  inline size_t getNumberOfBits() const
96  {
97  return mBitSet.size() * CHAR_BIT * sizeof(size_t) - mIgnoredBits;
98  }
99 
100  inline CZeroSet & operator |= (const CZeroSet & rhs)
101  {
102  size_t * pIt = mBitSet.array();
103  size_t * pEnd = pIt + mBitSet.size();
104  const size_t * pRhs = rhs.mBitSet.array();
105  mNumberSetBits = 0;
106 
107  for (; pIt != pEnd; ++pIt, ++pRhs)
108  {
109  *pIt |= *pRhs;
110  mNumberSetBits += countSetBits(*pIt);
111  }
112 
114 
115  return *this;
116  }
117 
118  inline CZeroSet & operator &= (const CZeroSet & rhs)
119  {
120  size_t * pIt = mBitSet.array();
121  size_t * pEnd = pIt + mBitSet.size();
122  const size_t * pRhs = rhs.mBitSet.array();
123  mNumberSetBits = 0;
124 
125  for (; pIt != pEnd; ++pIt, ++pRhs)
126  {
127  *pIt &= *pRhs;
128  mNumberSetBits += countSetBits(*pIt);
129  }
130 
132 
133  return *this;
134  }
135 
136  static inline
137  CZeroSet intersection(const CZeroSet & set1, const CZeroSet & set2)
138  {
139  CZeroSet Intersection(set1);
140  return Intersection &= set2;
141  }
142 
143  // Superset
144  inline bool operator >= (const CZeroSet & rhs) const
145  {
146  const size_t * pIt = mBitSet.array();
147  const size_t * pEnd = pIt + mBitSet.size();
148  const size_t * pRhs = rhs.mBitSet.array();
149 
150  for (; pIt != pEnd; ++pIt, ++pRhs)
151  {
152  if (*pIt != (*pIt | *pRhs))
153  return false;
154  }
155 
156  return true;
157  }
158 
159  inline bool operator == (const CZeroSet & rhs) const
160  {
161  if (mNumberSetBits != rhs.mNumberSetBits)
162  return false;
163 
164  return memcmp(mBitSet.array(), rhs.mBitSet.array(),
165  mBitSet.size() * sizeof(size_t)) == 0;
166  }
167 
168  bool isExtremeRay(const std::vector< CStepMatrixColumn * > & columns) const;
169 
170  // Attributes
171 private:
173 
174  size_t mIgnoredBits;
175 
177 
178  inline size_t countSetBits(size_t bits)
179  {
180  size_t numberOfBits = 0;
181 
182  for (size_t i = 0; i < CHAR_BIT * sizeof(size_t); ++i)
183  {
184  if ((bits >> i) & 1)
185  {
186  numberOfBits++;
187  }
188  }
189 
190  return numberOfBits;
191  }
192 };
193 
194 #endif // COPASI_CZeroSet
size_t mIndex
Definition: CZeroSet.h:55
CZeroSet(const size_t &index=0)
Definition: CZeroSet.cpp:80
size_t countSetBits(size_t bits)
Definition: CZeroSet.h:178
CZeroSet & operator&=(const CZeroSet &rhs)
Definition: CZeroSet.h:118
CIndex & operator=(const CIndex &rhs)
Definition: CZeroSet.cpp:54
size_t getNumberOfBits() const
Definition: CZeroSet.h:95
~CZeroSet()
Definition: CZeroSet.cpp:94
bool operator<(const CIndex &rhs) const
Definition: CZeroSet.cpp:72
size_t getNumberOfUnsetBits() const
Definition: CZeroSet.h:90
CIndex(const size_t &index=0)
Definition: CZeroSet.cpp:24
size_t mIgnoredBits
Definition: CZeroSet.h:174
size_t mNotBit
Definition: CZeroSet.h:57
CIndex & operator++()
Definition: CZeroSet.cpp:39
void setBit(const CIndex &index)
Definition: CZeroSet.h:68
const size_t & getNumberOfSetBits() const
Definition: CZeroSet.h:85
friend std::ostream & operator<<(std::ostream &, const CZeroSet &)
Definition: CZeroSet.cpp:114
CZeroSet & operator|=(const CZeroSet &rhs)
Definition: CZeroSet.h:100
size_t mNumberSetBits
Definition: CZeroSet.h:176
void unsetBit(const CIndex &index)
Definition: CZeroSet.h:74
bool isSet(const CIndex &index) const
Definition: CZeroSet.h:80
size_t size() const
Definition: CVector.h:100
bool isExtremeRay(const std::vector< CStepMatrixColumn * > &columns) const
Definition: CZeroSet.cpp:97
CType * array()
Definition: CVector.h:139
static CZeroSet intersection(const CZeroSet &set1, const CZeroSet &set2)
Definition: CZeroSet.h:137
CVector< size_t > mBitSet
Definition: CZeroSet.h:172
bool operator==(const CZeroSet &rhs) const
Definition: CZeroSet.h:159
bool operator>=(const CZeroSet &rhs) const
Definition: CZeroSet.h:144