1
0
mirror of https://github.com/thooge/esp32-nmea2000-obp60.git synced 2025-12-15 23:13:07 +01:00

Convert invalid marker of ringbuffer to MAX_VAL -> required for unsigned types

This commit is contained in:
Ulrich Meine
2025-08-23 13:43:02 +02:00
parent c6c2ad537a
commit 851149bae6
5 changed files with 67 additions and 67 deletions

View File

@@ -35,7 +35,7 @@ RingBuffer<T>::RingBuffer(size_t size)
, is_Full(false)
{
initCommon();
buffer.resize(size, MIN_VAL);
buffer.resize(size, MAX_VAL); // MAX_VAL indicate invalid values
}
// Specify meta data of buffer content
@@ -101,7 +101,7 @@ void RingBuffer<T>::add(const T& value)
{
GWSYNCHRONIZED(&bufLocker);
if (value < smallest || value > largest) {
buffer[head] = MIN_VAL; // Store MIN_VAL if value is out of range
buffer[head] = MAX_VAL; // Store MAX_VAL if value is out of range
} else {
buffer[head] = value;
}
@@ -125,7 +125,7 @@ T RingBuffer<T>::get(size_t index) const
{
GWSYNCHRONIZED(&bufLocker);
if (isEmpty() || index < 0 || index >= count) {
return MIN_VAL;
return MAX_VAL;
}
size_t realIndex = (first + index) % capacity;
@@ -144,7 +144,7 @@ template <typename T>
T RingBuffer<T>::getFirst() const
{
if (isEmpty()) {
return MIN_VAL;
return MAX_VAL;
}
return get(0);
}
@@ -154,7 +154,7 @@ template <typename T>
T RingBuffer<T>::getLast() const
{
if (isEmpty()) {
return MIN_VAL;
return MAX_VAL;
}
return get(count - 1);
}
@@ -164,14 +164,14 @@ template <typename T>
T RingBuffer<T>::getMin() const
{
if (isEmpty()) {
return MIN_VAL;
return MAX_VAL;
}
T minVal = MAX_VAL;
T value;
for (size_t i = 0; i < count; i++) {
value = get(i);
if (value < minVal && value != MIN_VAL) {
if (value < minVal && value != MAX_VAL) {
minVal = value;
}
}
@@ -183,7 +183,7 @@ template <typename T>
T RingBuffer<T>::getMin(size_t amount) const
{
if (isEmpty() || amount <= 0) {
return MIN_VAL;
return MAX_VAL;
}
if (amount > count)
amount = count;
@@ -192,7 +192,7 @@ T RingBuffer<T>::getMin(size_t amount) const
T value;
for (size_t i = 0; i < amount; i++) {
value = get(count - 1 - i);
if (value < minVal && value != MIN_VAL) {
if (value < minVal && value != MAX_VAL) {
minVal = value;
}
}
@@ -204,14 +204,14 @@ template <typename T>
T RingBuffer<T>::getMax() const
{
if (isEmpty()) {
return MIN_VAL;
return MAX_VAL;
}
T maxVal = MIN_VAL;
T value;
for (size_t i = 0; i < count; i++) {
value = get(i);
if (value > maxVal && value != MIN_VAL) {
if (value > maxVal && value != MAX_VAL) {
maxVal = value;
}
}
@@ -223,7 +223,7 @@ template <typename T>
T RingBuffer<T>::getMax(size_t amount) const
{
if (isEmpty() || amount <= 0) {
return MIN_VAL;
return MAX_VAL;
}
if (amount > count)
amount = count;
@@ -232,7 +232,7 @@ T RingBuffer<T>::getMax(size_t amount) const
T value;
for (size_t i = 0; i < amount; i++) {
value = get(count - 1 - i);
if (value > maxVal && value != MIN_VAL) {
if (value > maxVal && value != MAX_VAL) {
maxVal = value;
}
}
@@ -244,7 +244,7 @@ template <typename T>
T RingBuffer<T>::getMid() const
{
if (isEmpty()) {
return MIN_VAL;
return MAX_VAL;
}
return (getMin() + getMax()) / static_cast<T>(2);
@@ -255,7 +255,7 @@ template <typename T>
T RingBuffer<T>::getMid(size_t amount) const
{
if (isEmpty() || amount <= 0) {
return MIN_VAL;
return MAX_VAL;
}
if (amount > count)
@@ -269,7 +269,7 @@ template <typename T>
T RingBuffer<T>::getMedian() const
{
if (isEmpty()) {
return MIN_VAL;
return MAX_VAL;
}
// Create a temporary vector with current valid elements
@@ -298,7 +298,7 @@ template <typename T>
T RingBuffer<T>::getMedian(size_t amount) const
{
if (isEmpty() || amount <= 0) {
return MIN_VAL;
return MAX_VAL;
}
if (amount > count)
amount = count;
@@ -366,14 +366,14 @@ bool RingBuffer<T>::isFull() const
return is_Full;
}
// Get lowest possible value for buffer; used for non-set buffer data
// Get lowest possible value for buffer
template <typename T>
T RingBuffer<T>::getMinVal() const
{
return MIN_VAL;
}
// Get highest possible value for buffer
// Get highest possible value for buffer; used for unset/invalid buffer data
template <typename T>
T RingBuffer<T>::getMaxVal() const
{
@@ -405,7 +405,7 @@ void RingBuffer<T>::resize(size_t newSize)
is_Full = false;
buffer.clear();
buffer.resize(newSize, MIN_VAL);
buffer.resize(newSize, MAX_VAL);
}
// Get all current values as a vector