aboutsummaryrefslogtreecommitdiffstats
path: root/Hilbert/Operations.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'Hilbert/Operations.hpp')
-rw-r--r--Hilbert/Operations.hpp18
1 files changed, 18 insertions, 0 deletions
diff --git a/Hilbert/Operations.hpp b/Hilbert/Operations.hpp
index 1c76dc2..cff38a6 100644
--- a/Hilbert/Operations.hpp
+++ b/Hilbert/Operations.hpp
@@ -67,4 +67,22 @@ setBit(T& field, const BitsetIndex<T> index, const bool value)
field.set(index, value);
}
+/// Return 1 + the index of the least significant 1-bit of `field`, or zero
+template <typename T>
+int ffs(const T field);
+
+template <>
+int
+ffs<unsigned long>(const unsigned long field)
+{
+ return __builtin_ffsl(field);
+}
+
+template <>
+int
+ffs<unsigned long long>(const unsigned long long field)
+{
+ return __builtin_ffsll(field);
+}
+
#endif