aboutsummaryrefslogtreecommitdiff
path: root/common/algorithm.h
diff options
context:
space:
mode:
Diffstat (limited to 'common/algorithm.h')
-rw-r--r--common/algorithm.h13
1 files changed, 13 insertions, 0 deletions
diff --git a/common/algorithm.h b/common/algorithm.h
index 3a66efedba..06f2a279af 100644
--- a/common/algorithm.h
+++ b/common/algorithm.h
@@ -222,6 +222,19 @@ void sort(T first, T last) {
sort(first, last, Common::Less<typename T::ValueType>());
}
+/**
+ * Euclid's algorithm to compute the greatest common divisor.
+ */
+template<class T>
+T gcd(T a, T b) {
+ while (a > 0) {
+ T tmp = a;
+ a = b % a;
+ b = tmp;
+ }
+ return b;
+}
+
} // End of namespace Common
#endif