aboutsummaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorCameron Cawley2019-12-14 12:13:09 +0000
committerFilippos Karapetis2019-12-14 17:09:18 +0200
commitc3c3137ab3a3d09c12eaa7140cb7ec760bdfe924 (patch)
treeacb4ba1b30107b2ee3b03094aa8d75b983948cb8 /common
parent97b4ee93f1fad5bcca7cbb5472c0138be9f607db (diff)
downloadscummvm-rg350-c3c3137ab3a3d09c12eaa7140cb7ec760bdfe924.tar.gz
scummvm-rg350-c3c3137ab3a3d09c12eaa7140cb7ec760bdfe924.tar.bz2
scummvm-rg350-c3c3137ab3a3d09c12eaa7140cb7ec760bdfe924.zip
BACKENDS: Move nextHigher2() into common/algorithm.h
Diffstat (limited to 'common')
-rw-r--r--common/algorithm.h16
1 files changed, 16 insertions, 0 deletions
diff --git a/common/algorithm.h b/common/algorithm.h
index 8384eb7089..1aac0376db 100644
--- a/common/algorithm.h
+++ b/common/algorithm.h
@@ -272,6 +272,22 @@ T gcd(T a, T b) {
#endif
/**
+ * Get the next highest power of 2.
+ */
+template<class T>
+T nextHigher2(T v) {
+ if (v == 0)
+ return 1;
+ v--;
+ v |= v >> 1;
+ v |= v >> 2;
+ v |= v >> 4;
+ v |= v >> 8;
+ v |= v >> 16;
+ return ++v;
+}
+
+/**
* Replacement algorithm for iterables.
*
* Replaces all occurrences of "original" in [begin, end) with occurrences of "replaced".