MCPcopy Create free account
hub / github.com/ArduPilot/ardupilot / computesizes

Function computesizes

libraries/AP_Scripting/lua/src/ltable.c:226–247  ·  view source on GitHub ↗

** Compute the optimal size for the array part of table 't'. 'nums' is a ** "count array" where 'nums[i]' is the number of integers in the table ** between 2^(i - 1) + 1 and 2^i. 'pna' enters with the total number of ** integer keys in the table and leaves with the number of keys that ** will go to the array part; return the optimal size. */

Source from the content-addressed store, hash-verified

224** will go to the array part; return the optimal size.
225*/
226static unsigned int computesizes (unsigned int nums[], unsigned int *pna) {
227 int i;
228 unsigned int twotoi; /* 2^i (candidate for optimal size) */
229 unsigned int a = 0; /* number of elements smaller than 2^i */
230 unsigned int na = 0; /* number of elements to go to array part */
231 unsigned int optimal = 0; /* optimal size for array part */
232 /* loop while keys can fill more than half of total size */
233 for (i = 0, twotoi = 1;
234 twotoi > 0 && *pna > twotoi / 2;
235 i++, twotoi *= 2) {
236 if (nums[i] > 0) {
237 a += nums[i];
238 if (a > twotoi/2) { /* more than half elements present? */
239 optimal = twotoi; /* optimal size (till now) */
240 na = a; /* all elements up to 'optimal' will go to array part */
241 }
242 }
243 }
244 lua_assert((optimal == 0 || optimal / 2 < na) && na <= optimal);
245 *pna = na;
246 return optimal;
247}
248
249
250static int countint (const TValue *key, unsigned int *nums) {

Callers 1

rehashFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected