MCPcopy Create free account
hub / github.com/ObEngine/ObEngine / numusearray

Function numusearray

extlibs/lua/src/ltable.c:385–409  ·  view source on GitHub ↗

** Count keys in array part of table 't': Fill 'nums[i]' with ** number of keys that will go into corresponding slice and return ** total number of non-nil keys. */

Source from the content-addressed store, hash-verified

383** total number of non-nil keys.
384*/
385static unsigned int numusearray (const Table *t, unsigned int *nums) {
386 int lg;
387 unsigned int ttlg; /* 2^lg */
388 unsigned int ause = 0; /* summation of 'nums' */
389 unsigned int i = 1; /* count to traverse all array keys */
390 unsigned int asize = limitasasize(t); /* real array size */
391 /* traverse each slice */
392 for (lg = 0, ttlg = 1; lg <= MAXABITS; lg++, ttlg *= 2) {
393 unsigned int lc = 0; /* counter */
394 unsigned int lim = ttlg;
395 if (lim > asize) {
396 lim = asize; /* adjust upper limit */
397 if (i > lim)
398 break; /* no more elements to count */
399 }
400 /* count elements in range (2^(lg - 1), 2^lg] */
401 for (; i <= lim; i++) {
402 if (!isempty(&t->array[i-1]))
403 lc++;
404 }
405 nums[lg] += lc;
406 ause += lc;
407 }
408 return ause;
409}
410
411
412static int numusehash (const Table *t, unsigned int *nums, unsigned int *pna) {

Callers 1

rehashFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected