cyclic_buffer.contains method
This commit is contained in:
parent
b7917800c8
commit
9ab1fa069f
|
@ -14,6 +14,7 @@
|
|||
#define CYCLIC_BUFFER_H
|
||||
|
||||
#include <string.h>
|
||||
#include "rusefi_true.h"
|
||||
|
||||
static const short CB_MAX_SIZE = 128;
|
||||
|
||||
|
@ -41,6 +42,7 @@ class cyclic_buffer
|
|||
T maxValue(int length);
|
||||
T minValue(int length);
|
||||
void setSize(int size);
|
||||
bool contains(T value);
|
||||
int getSize();
|
||||
int getCount();
|
||||
void clear();
|
||||
|
@ -111,6 +113,16 @@ void cyclic_buffer<T, maxSize>::add(T value) {
|
|||
++count;
|
||||
}
|
||||
|
||||
template<typename T, size_t maxSize>
|
||||
bool cyclic_buffer<T, maxSize>::contains(T value) {
|
||||
for (int i = 0; i < currentIndex ; i++) {
|
||||
if (elements[i] == value) {
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
template<typename T, size_t maxSize>
|
||||
void cyclic_buffer<T, maxSize>::setSize(int size) {
|
||||
clear();
|
||||
|
|
|
@ -51,7 +51,6 @@ TEST(util, crc) {
|
|||
assertEqualsM("crc32 line inc", 0x4775a7b1, c);
|
||||
}
|
||||
|
||||
static cyclic_buffer<int> sb;
|
||||
|
||||
TEST(util, Overflow64Counter) {
|
||||
print("*************************************** testOverflow64Counter\r\n");
|
||||
|
@ -66,7 +65,15 @@ TEST(util, Overflow64Counter) {
|
|||
assertEquals(4294967296, o.update(0));
|
||||
}
|
||||
|
||||
TEST(util, cyclicBufferContains) {
|
||||
cyclic_buffer<int> sb;
|
||||
sb.add(10);
|
||||
ASSERT_EQ(TRUE, sb.contains(10));
|
||||
ASSERT_EQ(FALSE, sb.contains(11));
|
||||
}
|
||||
|
||||
TEST(util, cyclicBuffer) {
|
||||
cyclic_buffer<int> sb;
|
||||
|
||||
print("*************************************** testCyclicBuffer\r\n");
|
||||
|
||||
|
|
Loading…
Reference in New Issue