Example: B+ Trees
Given N tuples in the tree, at most di
children per inner node and at most dl
values per leaf, the minimum height of a B+ Tree would be h = ceil(log_di((N + dl - 1) / dl))
if I am not mistaken.
This is only true if /
denotes the integer division and I could probably replace (N + dl - 1) / dl
with static_cast<double>(N) / dl
.
#include <cmath>
int minHeight(int N)
{
constexpr int di = 256;
constexpr int dl = 255;
return std::lround(std::ceil(log((N + (dl - 1)) / dl) / log(di)));
}
My interest lies in the pattern: (N + d - 1) /d
. This seems to be used when calculating the smallest multiple of the divisor (d) that is greater or equal to the dividend (N).
Questions
- Does this pattern have any name associated with it? How common is it when designing data structures and algorithms?
- Is there another way to write this code in c++ to be easier to understand, if it is uncommon?