@@ -162,7 +162,7 @@ struct CircularPhasesBuffer {
162
162
* \return reference to the stored data
163
163
*/
164
164
const StoredType& at (const PhaseType phase) const {
165
- vtAssert (contains (phase), " Buffer don't contain requested phase." );
165
+ vtAssert (contains (phase), " Buffer don't contain the requested phase." );
166
166
167
167
return vector_[phaseToPos (phase)].second ;
168
168
}
@@ -175,7 +175,7 @@ struct CircularPhasesBuffer {
175
175
* \return reference to the stored data
176
176
*/
177
177
StoredType& at (const PhaseType phase) {
178
- vtAssert (contains (phase), " Buffer don't contain requested phase." );
178
+ vtAssert (contains (phase), " Buffer don't contain the requested phase." );
179
179
180
180
return vector_[phaseToPos (phase)].second ;
181
181
}
@@ -185,15 +185,15 @@ struct CircularPhasesBuffer {
185
185
*
186
186
* \param[in] new_size the requested new size of the buffer
187
187
*/
188
- void resize (std::size_t new_size) {
189
- if (new_size == 0 ) {
190
- resetIndexes () ;
188
+ void resize (const std::size_t new_size) {
189
+ if (new_size == vector_. size () ) {
190
+ return ;
191
191
}
192
192
193
- if (new_size != vector_.size ()) {
194
- auto new_vec =
195
- std::vector<StoredPair>(new_size, StoredPair{invalid_, StoredType{}});
193
+ auto new_vec =
194
+ std::vector<StoredPair>(new_size, StoredPair{invalid_, StoredType{}});
196
195
196
+ if (new_size > 0 ) {
197
197
if (new_size < size ()) {
198
198
auto tmp_tail = head_ - new_size + 1 ;
199
199
if (tmp_tail < 0 ) {
@@ -217,9 +217,11 @@ struct CircularPhasesBuffer {
217
217
head_ = --i;
218
218
tail_ = 0 ;
219
219
}
220
-
221
- vector_. swap (new_vec );
220
+ } else {
221
+ resetIndexes ( );
222
222
}
223
+
224
+ vector_.swap (new_vec);
223
225
}
224
226
225
227
/* *
@@ -234,7 +236,7 @@ struct CircularPhasesBuffer {
234
236
*
235
237
* \return the number free spaces in the buffer
236
238
*/
237
- int numFree () const {
239
+ std:: size_t numFree () const {
238
240
if (empty ()) {
239
241
return capacity ();
240
242
} else if (head_ == tail_) {
@@ -249,7 +251,7 @@ struct CircularPhasesBuffer {
249
251
/* *
250
252
* \brief Check if the buffer is empty
251
253
*
252
- * \return whetever the buffer is empty or not
254
+ * \return whether the buffer is empty or not
253
255
*/
254
256
bool empty () const {
255
257
return head_ == invalid_index_ && tail_ == invalid_index_;
@@ -265,7 +267,7 @@ struct CircularPhasesBuffer {
265
267
/* *
266
268
* \brief Check if the buffer is initialized
267
269
*
268
- * \return whenever the buffer is initialized or not
270
+ * \return whether the buffer is initialized or not
269
271
*/
270
272
bool isInitialized () const { return capacity () > 0 ; }
271
273
@@ -294,7 +296,7 @@ struct CircularPhasesBuffer {
294
296
*
295
297
* \return the index to the phase data
296
298
*/
297
- inline std::size_t phaseToPos (PhaseType phase) const {
299
+ inline std::size_t phaseToPos (const PhaseType phase) const {
298
300
auto go_back = vector_[head_].first - phase;
299
301
if (go_back > head_) {
300
302
return vector_.size () - (go_back - head_);
@@ -309,7 +311,7 @@ struct CircularPhasesBuffer {
309
311
*
310
312
* \return the incremented index
311
313
*/
312
- inline std::size_t getNextEntry (std::size_t index) const {
314
+ inline std::size_t getNextEntry (const std::size_t index) const {
313
315
auto next_entry = index + 1 ;
314
316
if (next_entry == capacity ()) {
315
317
next_entry = 0 ;
@@ -398,10 +400,10 @@ struct CircularPhasesBuffer {
398
400
if (empty ()) {
399
401
return end ();
400
402
}
401
- return PhaseIterator (&vector_, tail_, head_);
403
+ return PhaseIterator<StoredPair> (&vector_, tail_, head_);
402
404
}
403
405
404
- auto end () { return PhaseIterator (&vector_, vector_.size (), vector_.size ()); }
406
+ auto end () { return PhaseIterator<StoredPair> (&vector_, vector_.size (), vector_.size ()); }
405
407
};
406
408
407
409
}}} /* end namespace vt::util::container */
0 commit comments