70 static const int MAX_INTEGER = 2147483647;
72 using IndexListContainerIterator = std::list<std::pair<int, int>>::iterator;
76 indexContainer_.push_back(std::make_pair(minIndex, maxIndex));
80 if (indexContainer_.empty()) { std::cerr <<
"" << std::endl; }
84 result = indexContainer_.front().first;
86 if (indexContainer_.front().first == indexContainer_.front().second) {
87 indexContainer_.pop_front();
88 }
else if (indexContainer_.front().first <
89 indexContainer_.front().second) {
90 ++indexContainer_.front().first;
92 std::cerr <<
"" << std::endl;
101 void insert(
int index) {
102 IndexListContainerIterator insertPos = internalInsert(index, index);
111 void insert(
int beginIndex,
int endIndex) {
112 IndexListContainerIterator insertPos =
113 internalInsert(beginIndex, endIndex);
122 if (indices.empty()) {
return; }
124 std::sort(indices.begin(), indices.end());
125 auto last = std::unique(indices.begin(), indices.end());
126 indices.erase(last, indices.end());
128 std::vector<int>::iterator i;
131 beginIndex = indices[0];
133 for (i = indices.begin() + 1; i != indices.end(); ++i) {
134 if (*i != *(i - 1) + 1) {
135 insert(beginIndex, *(i - 1));
141 std::vector<int> getIndicesBefore(
int index) {
142 std::vector<int> result;
143 IndexListContainerIterator i;
145 for (i = indexContainer_.begin(); i != indexContainer_.end(); ++i) {
146 if ((*i).first > index) {
148 indexContainer_.erase(indexContainer_.begin(), i);
150 }
else if ((*i).second < index) {
152 for (
int j = (*i).first; j <= (*i).second; ++j) {
156 }
else if ((*i).first == (*i).second) {
158 result.push_back((*i).first);
159 indexContainer_.erase(indexContainer_.begin(), i);
162 for (
int j = (*i).first; j < index; ++j) {
166 indexContainer_.erase(indexContainer_.begin(), i);
173 int getMaxIndex() {
return maxIndex_; }
176 IndexListContainerIterator internalInsert(
int beginIndex,
int endIndex) {
177 if (beginIndex > endIndex) {
178 std::swap(beginIndex, endIndex);
179 std::cerr <<
"" << std::endl;
182 if (endIndex > maxIndex_) { std::cerr <<
"" << std::endl; }
184 IndexListContainerIterator i = indexContainer_.begin();
185 for (; i != indexContainer_.end(); ++i) {
186 if ((*i).first > endIndex) {
187 indexContainer_.insert(i, std::make_pair(beginIndex, endIndex));
189 }
else if ((*i).second < beginIndex) {
192 std::cerr <<
"" << std::endl;
196 indexContainer_.push_back(std::make_pair(beginIndex, endIndex));
197 return --indexContainer_.end();
200 void merge(IndexListContainerIterator i) {
201 IndexListContainerIterator j;
204 if (i != indexContainer_.begin()) {
207 if (j != indexContainer_.begin() && (*j).second + 1 == (*i).first) {
208 (*i).first = (*j).first;
209 indexContainer_.erase(j);
214 if (i != indexContainer_.end()) {
218 if (j != indexContainer_.end() && (*i).second + 1 == (*j).first) {
219 (*i).second = (*j).second;
220 indexContainer_.erase(j);
226 std::list<std::pair<int, int>> indexContainer_;
236 int getNextAtomIndex() {
return atomIndexContainer_.pop(); }
238 std::vector<int> getAtomIndicesBefore(
int index) {
239 return atomIndexContainer_.getIndicesBefore(index);
242 void releaseAtomIndex(
int index) { atomIndexContainer_.insert(index); }
244 void releaseAtomIndex(
int beginIndex,
int endIndex) {
245 atomIndexContainer_.insert(beginIndex, endIndex);
248 void releaseAtomIndex(std::vector<int> indices) {
249 atomIndexContainer_.insert(indices);
252 int getNextRigidBodyIndex() {
return rigidBodyIndexContainer_.pop(); }
254 std::vector<int> getRigidBodyIndicesBefore(
int index) {
255 return rigidBodyIndexContainer_.getIndicesBefore(index);
258 void releaseRigidBodyIndex(
int index) {
259 rigidBodyIndexContainer_.insert(index);
262 void releaseRigidBodyIndex(
int beginIndex,
int endIndex) {
263 rigidBodyIndexContainer_.insert(beginIndex, endIndex);
266 void releaseRigidBodyIndex(std::vector<int> indices) {
267 rigidBodyIndexContainer_.insert(indices);
270 int getNextCutoffGroupIndex() {
return cutoffGroupIndexContainer_.pop(); }
272 std::vector<int> getCutoffGroupIndicesBefore(
int index) {
273 return cutoffGroupIndexContainer_.getIndicesBefore(index);
276 void releaseCutoffGroupIndex(
int index) {
277 cutoffGroupIndexContainer_.insert(index);
280 void releaseCutoffGroupIndex(
int beginIndex,
int endIndex) {
281 cutoffGroupIndexContainer_.insert(beginIndex, endIndex);
284 void releaseCutoffGroupIndex(std::vector<int> indices) {
285 cutoffGroupIndexContainer_.insert(indices);
288 int getNextBondIndex() {
return bondIndexContainer_.pop(); }
290 std::vector<int> getBondIndicesBefore(
int index) {
291 return bondIndexContainer_.getIndicesBefore(index);
294 void releaseBondIndex(
int index) { bondIndexContainer_.insert(index); }
296 void releaseBondIndex(
int beginIndex,
int endIndex) {
297 bondIndexContainer_.insert(beginIndex, endIndex);
300 void releaseBondIndex(std::vector<int> indices) {
301 bondIndexContainer_.insert(indices);
304 int getNextBendIndex() {
return bendIndexContainer_.pop(); }
306 std::vector<int> getBendIndicesBefore(
int index) {
307 return bendIndexContainer_.getIndicesBefore(index);
310 void releaseBendIndex(
int index) { bendIndexContainer_.insert(index); }
312 void releaseBendIndex(
int beginIndex,
int endIndex) {
313 bendIndexContainer_.insert(beginIndex, endIndex);
316 void releaseBendIndex(std::vector<int> indices) {
317 bendIndexContainer_.insert(indices);
320 int getNextTorsionIndex() {
return torsionIndexContainer_.pop(); }
322 std::vector<int> getTorsionIndicesBefore(
int index) {
323 return torsionIndexContainer_.getIndicesBefore(index);
326 void releaseTorsionIndex(
int index) {
327 torsionIndexContainer_.insert(index);
330 void releaseTorsionIndex(
int beginIndex,
int endIndex) {
331 torsionIndexContainer_.insert(beginIndex, endIndex);
334 void releaseTorsionIndex(std::vector<int> indices) {
335 torsionIndexContainer_.insert(indices);
338 int getNextInversionIndex() {
return inversionIndexContainer_.pop(); }
340 std::vector<int> getInversionIndicesBefore(
int index) {
341 return inversionIndexContainer_.getIndicesBefore(index);
344 void releaseInversionIndex(
int index) {
345 inversionIndexContainer_.insert(index);
348 void releaseInversionIndex(
int beginIndex,
int endIndex) {
349 inversionIndexContainer_.insert(beginIndex, endIndex);
352 void releaseInversionIndex(std::vector<int> indices) {
353 inversionIndexContainer_.insert(indices);