| 9460 | |
| 9461 | |
| 9462 | static int numusearray (const Table *t, int *nums) { |
| 9463 | int lg; |
| 9464 | int ttlg; /* 2^lg */ |
| 9465 | int ause = 0; /* summation of `nums' */ |
| 9466 | int i = 1; /* count to traverse all array keys */ |
| 9467 | for (lg=0, ttlg=1; lg<=MAXBITS; lg++, ttlg*=2) { /* for each slice */ |
| 9468 | int lc = 0; /* counter */ |
| 9469 | int lim = ttlg; |
| 9470 | if (lim > t->sizearray) { |
| 9471 | lim = t->sizearray; /* adjust upper limit */ |
| 9472 | if (i > lim) |
| 9473 | break; /* no more elements to count */ |
| 9474 | } |
| 9475 | /* count elements in range (2^(lg-1), 2^lg] */ |
| 9476 | for (; i <= lim; i++) { |
| 9477 | if (!ttisnil(&t->array[i-1])) |
| 9478 | lc++; |
| 9479 | } |
| 9480 | nums[lg] += lc; |
| 9481 | ause += lc; |
| 9482 | } |
| 9483 | return ause; |
| 9484 | } |
| 9485 | |
| 9486 | |
| 9487 | static int numusehash (const Table *t, int *nums, int *pnasize) { |