[map] Move prime_for to hb-static

This commit is contained in:
Behdad Esfahbod 2018-06-01 17:28:47 -07:00
parent 33d6f46bbb
commit 4f76f956bb
3 changed files with 54 additions and 52 deletions

View File

@ -39,49 +39,6 @@ inline uint32_t Hash (const T &v)
}
/* Following comment and table copied from glib. */
/* Each table size has an associated prime modulo (the first prime
* lower than the table size) used to find the initial bucket. Probing
* then works modulo 2^n. The prime modulo is necessary to get a
* good distribution with poor hash functions.
*/
static const unsigned int prime_mod [] =
{
1, /* For 1 << 0 */
2,
3,
7,
13,
31,
61,
127,
251,
509,
1021,
2039,
4093,
8191,
16381,
32749,
65521, /* For 1 << 16 */
131071,
262139,
524287,
1048573,
2097143,
4194301,
8388593,
16777213,
33554393,
67108859,
134217689,
268435399,
536870909,
1073741789,
2147483647 /* For 1 << 31 */
};
/*
* hb_map_t
*/
@ -148,7 +105,7 @@ struct hb_map_t
/* Switch to new, empty, array. */
population = occupancy = 0;
mask = new_size - 1;
prime = prime_for (power);
prime = _hb_prime_for (power);
items = new_items;
/* Insert back old items. */
@ -226,14 +183,6 @@ struct hb_map_t
protected:
static inline unsigned int prime_for (unsigned int shift)
{
if (unlikely (shift >= ARRAY_LENGTH (prime_mod)))
return prime_mod[ARRAY_LENGTH (prime_mod) - 1];
return prime_mod[shift];
}
inline unsigned int bucket_for (hb_codepoint_t key) const
{
unsigned int i = Hash (key) % prime;

View File

@ -1231,5 +1231,7 @@ round (double x)
#endif
HB_INTERNAL unsigned int _hb_prime_for (unsigned int shift);
#endif /* HB_PRIVATE_HH */

View File

@ -30,3 +30,54 @@
void * const _hb_NullPool[HB_NULL_POOL_SIZE / sizeof (void *)] = {};
/*thread_local*/ void * _hb_CrapPool[HB_NULL_POOL_SIZE / sizeof (void *)] = {};
#endif
/* Following comment and table copied from glib. */
/* Each table size has an associated prime modulo (the first prime
* lower than the table size) used to find the initial bucket. Probing
* then works modulo 2^n. The prime modulo is necessary to get a
* good distribution with poor hash functions.
*/
static const unsigned int prime_mod [] =
{
1, /* For 1 << 0 */
2,
3,
7,
13,
31,
61,
127,
251,
509,
1021,
2039,
4093,
8191,
16381,
32749,
65521, /* For 1 << 16 */
131071,
262139,
524287,
1048573,
2097143,
4194301,
8388593,
16777213,
33554393,
67108859,
134217689,
268435399,
536870909,
1073741789,
2147483647 /* For 1 << 31 */
};
unsigned int _hb_prime_for (unsigned int shift)
{
if (unlikely (shift >= ARRAY_LENGTH (prime_mod)))
return prime_mod[ARRAY_LENGTH (prime_mod) - 1];
return prime_mod[shift];
}