Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(175)

Unified Diff: webrtc/base/mod_ops.h

Issue 1814753002: Moved sequence number specific operations from mod_ops.h (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Feedback fixes. Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | webrtc/base/mod_ops_unittest.cc » ('j') | webrtc/modules/video_coding/sequence_number_util.h » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webrtc/base/mod_ops.h
diff --git a/webrtc/base/mod_ops.h b/webrtc/base/mod_ops.h
index cf65fdd4df828e193694aeb0f42143e8e339db6e..b6cf41e0261944ffd55f7e0d5535a59ca85a1d42 100644
--- a/webrtc/base/mod_ops.h
+++ b/webrtc/base/mod_ops.h
@@ -113,28 +113,25 @@ inline T ReverseDiff(T a, T b) {
return a - b;
}
-// Test if the sequence number a is ahead or at sequence number b.
-// If the two sequence numbers are at max distance from each other
-// then the sequence number with highest value is considered to
-// be ahead.
-template <typename T>
-inline bool AheadOrAt(T a, T b) {
+// Calculates the minimum distance between to wrapping numbers.
+//
+// The minimum distance is defined as min(ForwardDiff(a, b), ReverseDiff(a, b))
+template <typename T, T M>
+inline T MinDiff(T a, T b) {
static_assert(std::is_unsigned<T>::value,
"Type must be an unsigned integer.");
- const T maxDist = std::numeric_limits<T>::max() / 2 + T(1);
- if (a - b == maxDist)
- return b < a;
- return ForwardDiff(b, a) < maxDist;
+ return std::min(ForwardDiff<T, M>(a, b), ReverseDiff<T, M>(a, b));
}
-// Test if sequence number a is ahead of sequence number b.
template <typename T>
-inline bool AheadOf(T a, T b) {
+inline T MinDiff(T a, T b) {
static_assert(std::is_unsigned<T>::value,
"Type must be an unsigned integer.");
- return a != b && AheadOrAt(a, b);
+ return std::min(ForwardDiff(a, b), ReverseDiff(a, b));
}
+
+
} // namespace webrtc
#endif // WEBRTC_BASE_MOD_OPS_H_
« no previous file with comments | « no previous file | webrtc/base/mod_ops_unittest.cc » ('j') | webrtc/modules/video_coding/sequence_number_util.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698