MCPcopy Create free account
hub / github.com/bloomberg/comdb2 / computesizes

Function computesizes

lua/ltable.c:223–242  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

221
222
223static int computesizes (int nums[], int *narray) {
224 int i;
225 int twotoi; /* 2^i */
226 int a = 0; /* number of elements smaller than 2^i */
227 int na = 0; /* number of elements to go to array part */
228 int n = 0; /* optimal size for array part */
229 for (i = 0, twotoi = 1; twotoi/2 < *narray; i++, twotoi *= 2) {
230 if (nums[i] > 0) {
231 a += nums[i];
232 if (a > twotoi/2) { /* more than half elements present? */
233 n = twotoi; /* optimal size (till now) */
234 na = a; /* all elements smaller than n will go to array part */
235 }
236 }
237 if (a == *narray) break; /* all elements already counted */
238 }
239 *narray = n;
240 lua_assert(*narray/2 <= na && na <= *narray);
241 return na;
242}
243
244
245static int countint (const TValue *key, int *nums) {

Callers 1

rehashFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected