Skip to content

Commit

Permalink
add discretizer (utils)
Browse files Browse the repository at this point in the history
  • Loading branch information
edumeneses committed Feb 25, 2025
1 parent 05c7536 commit 3c8e965
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions include/puara/utils/discretizer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#pragma once

template <typename T>
class ValueMonitor {
private:
T latestValue;
bool firstValue; // Flag to track if it's the first value

public:
// Constructor
ValueMonitor() : firstValue(true) {
// Initialize latestValue to a default value. Important to avoid
// undefined behavior on the first comparison. Using the minimum
// value for numeric types is usually a good choice.
latestValue = std::numeric_limits<T>::min();
}

// Method to update the value and check for difference
bool updateAndCheck(const T& newValue) {
if (firstValue) {
latestValue = newValue;
firstValue = false;
return true; // It's the first value, so it's technically "different"
}

if (newValue != latestValue) {
latestValue = newValue;
return true; // Values are different
} else {
return false; // Values are the same
}
}

// Method to get the latest value (const version)
const T& getLatestValue() const {
return latestValue;
}

// Method to get the latest value (non-const version)
T& getLatestValue() {
return latestValue;
}
};

0 comments on commit 3c8e965

Please sign in to comment.