New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Interface refactor #16

Merged
merged 12 commits into from Aug 18, 2016

Add resize method to CircleBuffer

  • Loading branch information...
ReeceStevens committed Aug 9, 2016
commit e9f4489d0a6ffa0429929b6e04a7421374b4b71d
View
@@ -33,6 +33,17 @@ class CircleBuffer {
end = 1;
};
void resize(int new_len) {
if (new_len <= this->length) { return; }
T* new_data = new T[new_len];
for (int i = 0; i < length; i ++) {
new_data[i] = data[i];
}
length = new_len;
delete [] data;
data = new_data;
};
void add(const T& payload) {
data[next] = payload;
next = end;
@@ -42,7 +53,7 @@ class CircleBuffer {
T& operator[](const int k) {
if (length <= k) {
__attribute__((unused)) int* p = 0;
p = (int*) 1; // Intentionally crash.
p = (int*) 1; // TODO: more graceful way to handle this case?
}
return data[mod(next-k-1, length)];
};
ProTip! Use n and p to navigate between commits in a pull request.