** 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. */
| 427 | ** total number of non-nil keys. |
| 428 | */ |
| 429 | static unsigned int numusearray (const Table *t, unsigned int *nums) { |
| 430 | int lg; |
| 431 | unsigned int ttlg; /* 2^lg */ |
| 432 | unsigned int ause = 0; /* summation of 'nums' */ |
| 433 | unsigned int i = 1; /* count to traverse all array keys */ |
| 434 | unsigned int asize = limitasasize(t); /* real array size */ |
| 435 | /* traverse each slice */ |
| 436 | for (lg = 0, ttlg = 1; lg <= MAXABITS; lg++, ttlg *= 2) { |
| 437 | unsigned int lc = 0; /* counter */ |
| 438 | unsigned int lim = ttlg; |
| 439 | if (lim > asize) { |
| 440 | lim = asize; /* adjust upper limit */ |
| 441 | if (i > lim) |
| 442 | break; /* no more elements to count */ |
| 443 | } |
| 444 | /* count elements in range (2^(lg - 1), 2^lg] */ |
| 445 | for (; i <= lim; i++) { |
| 446 | if (!isempty(&t->array[i-1])) |
| 447 | lc++; |
| 448 | } |
| 449 | nums[lg] += lc; |
| 450 | ause += lc; |
| 451 | } |
| 452 | return ause; |
| 453 | } |
| 454 | |
| 455 | |
| 456 | static int numusehash (const Table *t, unsigned int *nums, unsigned int *pna) { |