BACKENDS: Move nextHigher2() into common/algorithm.h
This commit is contained in:
parent
97b4ee93f1
commit
c3c3137ab3
3 changed files with 22 additions and 29 deletions
|
@ -271,6 +271,22 @@ T gcd(T a, T b) {
|
|||
#pragma warning(pop)
|
||||
#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.
|
||||
*
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue