Skip to content

Commit 0022c5b

Browse files
committed
#1934: Fix compilation issue on Apple Clang
1 parent 3a05bb3 commit 0022c5b

File tree

2 files changed

+21
-18
lines changed

2 files changed

+21
-18
lines changed

src/vt/utils/container/circular_phases_buffer.h

+19-17
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ struct CircularPhasesBuffer {
162162
* \return reference to the stored data
163163
*/
164164
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.");
166166

167167
return vector_[phaseToPos(phase)].second;
168168
}
@@ -175,7 +175,7 @@ struct CircularPhasesBuffer {
175175
* \return reference to the stored data
176176
*/
177177
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.");
179179

180180
return vector_[phaseToPos(phase)].second;
181181
}
@@ -185,15 +185,15 @@ struct CircularPhasesBuffer {
185185
*
186186
* \param[in] new_size the requested new size of the buffer
187187
*/
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;
191191
}
192192

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{}});
196195

196+
if (new_size > 0) {
197197
if (new_size < size()) {
198198
auto tmp_tail = head_ - new_size + 1;
199199
if (tmp_tail < 0) {
@@ -217,9 +217,11 @@ struct CircularPhasesBuffer {
217217
head_ = --i;
218218
tail_ = 0;
219219
}
220-
221-
vector_.swap(new_vec);
220+
} else {
221+
resetIndexes();
222222
}
223+
224+
vector_.swap(new_vec);
223225
}
224226

225227
/**
@@ -234,7 +236,7 @@ struct CircularPhasesBuffer {
234236
*
235237
* \return the number free spaces in the buffer
236238
*/
237-
int numFree() const {
239+
std::size_t numFree() const {
238240
if (empty()) {
239241
return capacity();
240242
} else if (head_ == tail_) {
@@ -249,7 +251,7 @@ struct CircularPhasesBuffer {
249251
/**
250252
* \brief Check if the buffer is empty
251253
*
252-
* \return whetever the buffer is empty or not
254+
* \return whether the buffer is empty or not
253255
*/
254256
bool empty() const {
255257
return head_ == invalid_index_ && tail_ == invalid_index_;
@@ -265,7 +267,7 @@ struct CircularPhasesBuffer {
265267
/**
266268
* \brief Check if the buffer is initialized
267269
*
268-
* \return whenever the buffer is initialized or not
270+
* \return whether the buffer is initialized or not
269271
*/
270272
bool isInitialized() const { return capacity() > 0; }
271273

@@ -294,7 +296,7 @@ struct CircularPhasesBuffer {
294296
*
295297
* \return the index to the phase data
296298
*/
297-
inline std::size_t phaseToPos(PhaseType phase) const {
299+
inline std::size_t phaseToPos(const PhaseType phase) const {
298300
auto go_back = vector_[head_].first - phase;
299301
if (go_back > head_) {
300302
return vector_.size() - (go_back - head_);
@@ -309,7 +311,7 @@ struct CircularPhasesBuffer {
309311
*
310312
* \return the incremented index
311313
*/
312-
inline std::size_t getNextEntry(std::size_t index) const {
314+
inline std::size_t getNextEntry(const std::size_t index) const {
313315
auto next_entry = index + 1;
314316
if (next_entry == capacity()) {
315317
next_entry = 0;
@@ -398,10 +400,10 @@ struct CircularPhasesBuffer {
398400
if (empty()) {
399401
return end();
400402
}
401-
return PhaseIterator(&vector_, tail_, head_);
403+
return PhaseIterator<StoredPair>(&vector_, tail_, head_);
402404
}
403405

404-
auto end() { return PhaseIterator(&vector_, vector_.size(), vector_.size()); }
406+
auto end() { return PhaseIterator<StoredPair>(&vector_, vector_.size(), vector_.size()); }
405407
};
406408

407409
}}} /* end namespace vt::util::container */

tests/unit/utils/test_circular_phases_buffer.nompi.cc

+2-1
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,10 @@ TEST_F(TestCircularPhasesBuffer, test_circular_phases_buffer_store) {
138138

139139
buffer.store(2, {2 * 2});
140140
validatePresentPhases(buffer, {2});
141+
validateMissingPhases(buffer, {0, 1});
141142

142143
// store series of elements
143-
for (int i = 0; i < 15; i++) {
144+
for (int i = 3; i < 15; i++) {
144145
buffer.store(i, {i * i});
145146
}
146147
std::vector<PhaseType> finalOutput = {5, 6, 7, 8, 9, 10, 11, 12, 13, 14};

0 commit comments

Comments
 (0)