void test_auth_log2(void) { int l2; size_t tv; TEST_ASSERT_EQUAL_INT(0, auth_log2(0)); TEST_ASSERT_EQUAL_INT(0, auth_log2(1)); for (l2 = 1; l2 < sizeof(size_t)*CHAR_BIT; ++l2) { tv = (size_t)1 << l2; TEST_ASSERT_EQUAL_INT(l2, auth_log2( tv )); TEST_ASSERT_EQUAL_INT(l2, auth_log2( tv + 1 )); TEST_ASSERT_EQUAL_INT(l2, auth_log2(2*tv - 1)); } }
/* * auth_resize_hashtable * * Size hash table to average 4 or fewer entries per bucket initially, * within the bounds of at least 4 and no more than 15 bits for the hash * table index. Populate the hash table. */ static void auth_resize_hashtable(void) { u_long totalkeys; u_short hashbits; u_short hash; size_t newalloc; symkey * sk; totalkeys = authnumkeys + authnumfreekeys; hashbits = auth_log2(totalkeys / 4.0) + 1; hashbits = max(4, hashbits); hashbits = min(15, hashbits); authhashbuckets = 1 << hashbits; authhashmask = authhashbuckets - 1; newalloc = authhashbuckets * sizeof(key_hash[0]); key_hash = erealloc(key_hash, newalloc); memset(key_hash, '\0', newalloc); ITER_DLIST_BEGIN(key_listhead, sk, llink, symkey) hash = KEYHASH(sk->keyid); LINK_SLIST(key_hash[hash], sk, hlink); ITER_DLIST_END() }