8312395: Improve assertions in growableArray
Reviewed-by: dholmes, stuefe
This commit is contained in:
parent
9fa944e63f
commit
b772e67e29
@ -142,17 +142,17 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
E& at(int i) {
|
E& at(int i) {
|
||||||
assert(0 <= i && i < _len, "illegal index");
|
assert(0 <= i && i < _len, "illegal index %d for length %d", i, _len);
|
||||||
return _data[i];
|
return _data[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
E const& at(int i) const {
|
E const& at(int i) const {
|
||||||
assert(0 <= i && i < _len, "illegal index");
|
assert(0 <= i && i < _len, "illegal index %d for length %d", i, _len);
|
||||||
return _data[i];
|
return _data[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
E* adr_at(int i) const {
|
E* adr_at(int i) const {
|
||||||
assert(0 <= i && i < _len, "illegal index");
|
assert(0 <= i && i < _len, "illegal index %d for length %d", i, _len);
|
||||||
return &_data[i];
|
return &_data[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -184,7 +184,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
void at_put(int i, const E& elem) {
|
void at_put(int i, const E& elem) {
|
||||||
assert(0 <= i && i < _len, "illegal index");
|
assert(0 <= i && i < _len, "illegal index %d for length %d", i, _len);
|
||||||
_data[i] = elem;
|
_data[i] = elem;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -245,7 +245,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
void remove_at(int index) {
|
void remove_at(int index) {
|
||||||
assert(0 <= index && index < _len, "illegal index");
|
assert(0 <= index && index < _len, "illegal index %d for length %d", index, _len);
|
||||||
for (int j = index + 1; j < _len; j++) {
|
for (int j = index + 1; j < _len; j++) {
|
||||||
_data[j-1] = _data[j];
|
_data[j-1] = _data[j];
|
||||||
}
|
}
|
||||||
@ -259,8 +259,8 @@ public:
|
|||||||
|
|
||||||
// Remove all elements in the range [start - end). The order is preserved.
|
// Remove all elements in the range [start - end). The order is preserved.
|
||||||
void remove_range(int start, int end) {
|
void remove_range(int start, int end) {
|
||||||
assert(0 <= start, "illegal index");
|
assert(0 <= start, "illegal start index %d", start);
|
||||||
assert(start < end && end <= _len, "erase called with invalid range");
|
assert(start < end && end <= _len, "erase called with invalid range (%d, %d) for length %d", start, end, _len);
|
||||||
|
|
||||||
for (int i = start, j = end; j < length(); i++, j++) {
|
for (int i = start, j = end; j < length(); i++, j++) {
|
||||||
at_put(i, at(j));
|
at_put(i, at(j));
|
||||||
@ -270,7 +270,7 @@ public:
|
|||||||
|
|
||||||
// The order is changed.
|
// The order is changed.
|
||||||
void delete_at(int index) {
|
void delete_at(int index) {
|
||||||
assert(0 <= index && index < _len, "illegal index");
|
assert(0 <= index && index < _len, "illegal index %d for length %d", index, _len);
|
||||||
if (index < --_len) {
|
if (index < --_len) {
|
||||||
// Replace removed element with last one.
|
// Replace removed element with last one.
|
||||||
_data[index] = _data[_len];
|
_data[index] = _data[_len];
|
||||||
@ -403,7 +403,7 @@ public:
|
|||||||
void push(const E& elem) { append(elem); }
|
void push(const E& elem) { append(elem); }
|
||||||
|
|
||||||
E at_grow(int i, const E& fill = E()) {
|
E at_grow(int i, const E& fill = E()) {
|
||||||
assert(0 <= i, "negative index");
|
assert(0 <= i, "negative index %d", i);
|
||||||
if (i >= this->_len) {
|
if (i >= this->_len) {
|
||||||
if (i >= this->_capacity) grow(i);
|
if (i >= this->_capacity) grow(i);
|
||||||
for (int j = this->_len; j <= i; j++)
|
for (int j = this->_len; j <= i; j++)
|
||||||
@ -414,7 +414,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
void at_put_grow(int i, const E& elem, const E& fill = E()) {
|
void at_put_grow(int i, const E& elem, const E& fill = E()) {
|
||||||
assert(0 <= i, "negative index");
|
assert(0 <= i, "negative index %d", i);
|
||||||
if (i >= this->_len) {
|
if (i >= this->_len) {
|
||||||
if (i >= this->_capacity) grow(i);
|
if (i >= this->_capacity) grow(i);
|
||||||
for (int j = this->_len; j < i; j++)
|
for (int j = this->_len; j < i; j++)
|
||||||
@ -426,7 +426,7 @@ public:
|
|||||||
|
|
||||||
// inserts the given element before the element at index i
|
// inserts the given element before the element at index i
|
||||||
void insert_before(const int idx, const E& elem) {
|
void insert_before(const int idx, const E& elem) {
|
||||||
assert(0 <= idx && idx <= this->_len, "illegal index");
|
assert(0 <= idx && idx <= this->_len, "illegal index %d for length %d", idx, this->_len);
|
||||||
if (this->_len == this->_capacity) grow(this->_len);
|
if (this->_len == this->_capacity) grow(this->_len);
|
||||||
for (int j = this->_len - 1; j >= idx; j--) {
|
for (int j = this->_len - 1; j >= idx; j--) {
|
||||||
this->_data[j + 1] = this->_data[j];
|
this->_data[j + 1] = this->_data[j];
|
||||||
@ -436,7 +436,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
void insert_before(const int idx, const GrowableArrayView<E>* array) {
|
void insert_before(const int idx, const GrowableArrayView<E>* array) {
|
||||||
assert(0 <= idx && idx <= this->_len, "illegal index");
|
assert(0 <= idx && idx <= this->_len, "illegal index %d for length %d", idx, this->_len);
|
||||||
int array_len = array->length();
|
int array_len = array->length();
|
||||||
int new_len = this->_len + array_len;
|
int new_len = this->_len + array_len;
|
||||||
if (new_len >= this->_capacity) grow(new_len);
|
if (new_len >= this->_capacity) grow(new_len);
|
||||||
|
Loading…
Reference in New Issue
Block a user