MCPcopy Create free account
hub / github.com/CppCXY/EmmyLuaCodeStyle / numusearray

Function numusearray

3rd/lua-5.4.3/src/ltable.c:418–442  ·  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

416** total number of non-nil keys.
417*/
418static unsigned int numusearray (const Table *t, unsigned int *nums) {
419 int lg;
420 unsigned int ttlg; /* 2^lg */
421 unsigned int ause = 0; /* summation of 'nums' */
422 unsigned int i = 1; /* count to traverse all array keys */
423 unsigned int asize = limitasasize(t); /* real array size */
424 /* traverse each slice */
425 for (lg = 0, ttlg = 1; lg <= MAXABITS; lg++, ttlg *= 2) {
426 unsigned int lc = 0; /* counter */
427 unsigned int lim = ttlg;
428 if (lim > asize) {
429 lim = asize; /* adjust upper limit */
430 if (i > lim)
431 break; /* no more elements to count */
432 }
433 /* count elements in range (2^(lg - 1), 2^lg] */
434 for (; i <= lim; i++) {
435 if (!isempty(&t->array[i-1]))
436 lc++;
437 }
438 nums[lg] += lc;
439 ause += lc;
440 }
441 return ause;
442}
443
444
445static 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