aboutsummaryrefslogtreecommitdiff
path: root/src/common/powerof.h
diff options
context:
space:
mode:
authorSChernykh <sergey.v.chernykh@gmail.com>2020-10-20 14:16:09 +0200
committerSChernykh <sergey.v.chernykh@gmail.com>2020-10-20 14:16:09 +0200
commita25bc71f3faf3f7ca4de9eda6342503768bf28ad (patch)
tree9493846d8297b373769161737fac91f17bb5dcbc /src/common/powerof.h
parentMerge pull request #6891 (diff)
downloadmonero-a25bc71f3faf3f7ca4de9eda6342503768bf28ad.tar.xz
Make Blockchain::get_fee_quantization_mask() compile time
This also removes potential thread safety bug in that function.
Diffstat (limited to '')
-rw-r--r--src/common/powerof.h26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/common/powerof.h b/src/common/powerof.h
new file mode 100644
index 000000000..0f6c6254a
--- /dev/null
+++ b/src/common/powerof.h
@@ -0,0 +1,26 @@
+#pragma once
+
+#include <stdint.h>
+
+namespace tools
+{
+ template<uint64_t a, uint64_t b>
+ struct PowerOf
+ {
+ enum Data : uint64_t
+ {
+ // a^b = a * a^(b-1)
+ Value = a * PowerOf<a, b - 1>::Value,
+ };
+ };
+
+ template<uint64_t a>
+ struct PowerOf<a, 0>
+ {
+ enum Data : uint64_t
+ {
+ // a^0 = 1
+ Value = 1,
+ };
+ };
+}