MCPcopy Create free account
hub / github.com/F-Stack/f-stack / computesizes

Function computesizes

freebsd/contrib/openzfs/module/lua/ltable.c:196–215  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

194
195
196static int computesizes (int nums[], int *narray) {
197 int i;
198 int twotoi; /* 2^i */
199 int a = 0; /* number of elements smaller than 2^i */
200 int na = 0; /* number of elements to go to array part */
201 int n = 0; /* optimal size for array part */
202 for (i = 0, twotoi = 1; twotoi/2 < *narray; i++, twotoi *= 2) {
203 if (nums[i] > 0) {
204 a += nums[i];
205 if (a > twotoi/2) { /* more than half elements present? */
206 n = twotoi; /* optimal size (till now) */
207 na = a; /* all elements smaller than n will go to array part */
208 }
209 }
210 if (a == *narray) break; /* all elements already counted */
211 }
212 *narray = n;
213 lua_assert(*narray/2 <= na && na <= *narray);
214 return na;
215}
216
217
218static int countint (const TValue *key, int *nums) {

Callers 1

rehashFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected