mirror of
https://github.com/postgres/postgres.git
synced 2025-11-10 17:42:29 +03:00
Modify various power 2 calculations to use new helper functions
First pass of modifying various places that obtain the next power of 2 of a number and make them use the new functions added in pg_bitutils.h instead. This also removes the _hash_log2() function. There are no longer any callers in core. Other users can swap their _hash_log2(n) call to make use of pg_ceil_log2_32(n). Author: David Fetter, with some minor adjustments by me Reviewed-by: John Naylor, Jesse Zhang Discussion: https://postgr.es/m/20200114173553.GE32763%40fetter.org
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
#include "access/hash.h"
|
||||
#include "access/reloptions.h"
|
||||
#include "access/relscan.h"
|
||||
#include "port/pg_bitutils.h"
|
||||
#include "storage/buf_internals.h"
|
||||
#include "utils/lsyscache.h"
|
||||
#include "utils/rel.h"
|
||||
@@ -134,21 +135,6 @@ _hash_hashkey2bucket(uint32 hashkey, uint32 maxbucket,
|
||||
return bucket;
|
||||
}
|
||||
|
||||
/*
|
||||
* _hash_log2 -- returns ceil(lg2(num))
|
||||
*/
|
||||
uint32
|
||||
_hash_log2(uint32 num)
|
||||
{
|
||||
uint32 i,
|
||||
limit;
|
||||
|
||||
limit = 1;
|
||||
for (i = 0; limit < num; limit <<= 1, i++)
|
||||
;
|
||||
return i;
|
||||
}
|
||||
|
||||
/*
|
||||
* _hash_spareindex -- returns spare index / global splitpoint phase of the
|
||||
* bucket
|
||||
@@ -158,8 +144,7 @@ _hash_spareindex(uint32 num_bucket)
|
||||
{
|
||||
uint32 splitpoint_group;
|
||||
uint32 splitpoint_phases;
|
||||
|
||||
splitpoint_group = _hash_log2(num_bucket);
|
||||
splitpoint_group = pg_ceil_log2_32(num_bucket);
|
||||
|
||||
if (splitpoint_group < HASH_SPLITPOINT_GROUPS_WITH_ONE_PHASE)
|
||||
return splitpoint_group;
|
||||
|
||||
Reference in New Issue
Block a user