Improve CircularBuffer documentation (#180)

This commit is contained in:
Tyler Veness
2016-07-16 20:50:19 -07:00
committed by Peter Johnson
parent 57efd13f7f
commit f7c3f13a7f
4 changed files with 24 additions and 10 deletions

View File

@@ -79,6 +79,9 @@ T CircularBuffer<T>::PopBack() {
return m_data[(m_front + m_length) % m_data.size()];
}
/**
* Sets internal buffer contents to zero.
*/
template <class T>
void CircularBuffer<T>::Reset() {
std::fill(m_data.begin(), m_data.end(), 0);
@@ -87,7 +90,7 @@ void CircularBuffer<T>::Reset() {
}
/**
* Returns element at index starting from front of buffer.
* @return Element at index starting from front of buffer.
*/
template <class T>
T& CircularBuffer<T>::operator[](size_t index) {
@@ -95,7 +98,7 @@ T& CircularBuffer<T>::operator[](size_t index) {
}
/**
* Returns element at index starting from front of buffer.
* @return Element at index starting from front of buffer.
*/
template <class T>
const T& CircularBuffer<T>::operator[](size_t index) const {
@@ -103,7 +106,9 @@ const T& CircularBuffer<T>::operator[](size_t index) const {
}
/**
* Increment an index modulo the length of the m_data buffer
* Increment an index modulo the length of the buffer.
*
* @return The result of the modulo operation.
*/
template <class T>
size_t CircularBuffer<T>::ModuloInc(size_t index) {
@@ -111,7 +116,9 @@ size_t CircularBuffer<T>::ModuloInc(size_t index) {
}
/**
* Decrement an index modulo the length of the m_data buffer
* Decrement an index modulo the length of the buffer.
*
* @return The result of the modulo operation.
*/
template <class T>
size_t CircularBuffer<T>::ModuloDec(size_t index) {

View File

@@ -28,7 +28,7 @@ TEST(CircularBufferTest, PushFrontTest) {
queue.PushFront(value);
}
for (unsigned int i = 0; i < pushFrontOut.size(); i++) {
for (size_t i = 0; i < pushFrontOut.size(); i++) {
EXPECT_EQ(pushFrontOut[i], queue[i]);
}
}
@@ -40,7 +40,7 @@ TEST(CircularBufferTest, PushBackTest) {
queue.PushBack(value);
}
for (unsigned int i = 0; i < pushBackOut.size(); i++) {
for (size_t i = 0; i < pushBackOut.size(); i++) {
EXPECT_EQ(pushBackOut[i], queue[i]);
}
}

View File

@@ -12,10 +12,16 @@ package edu.wpi.first.wpilibj;
*/
public class CircularBuffer {
private double[] m_data;
// Index of element at front of buffer
private int m_front = 0;
// Number of elements used in buffer
private int m_length = 0;
@SuppressWarnings("JavadocMethod")
/**
* @param size The size of the circular buffer.
*/
public CircularBuffer(int size) {
m_data = new double[size];
for (int i = 0; i < m_data.length; i++) {
@@ -91,7 +97,9 @@ public class CircularBuffer {
return m_data[(m_front + m_length) % m_data.length];
}
@SuppressWarnings("JavadocMethod")
/**
* Sets internal buffer contents to zero.
*/
public void reset() {
for (double i : m_data) {
i = 0.0;
@@ -101,7 +109,7 @@ public class CircularBuffer {
}
/**
* @return element at index starting from front of buffer.
* @return Element at index starting from front of buffer.
*/
public double get(int index) {
return m_data[(m_front + index) % m_data.length];

View File

@@ -94,5 +94,4 @@ public class CircularBufferTest {
// Leaving only one element with value == 4
assertEquals(4.0, queue.get(0), 0.00005);
}
}