| 254 | |
| 255 | |
| 256 | static int numusearray (const Table *t, int *nums) { |
| 257 | int lg; |
| 258 | int ttlg; /* 2^lg */ |
| 259 | int ause = 0; /* summation of `nums' */ |
| 260 | int i = 1; /* count to traverse all array keys */ |
| 261 | for (lg=0, ttlg=1; lg<=MAXBITS; lg++, ttlg*=2) { /* for each slice */ |
| 262 | int lc = 0; /* counter */ |
| 263 | int lim = ttlg; |
| 264 | if (lim > t->sizearray) { |
| 265 | lim = t->sizearray; /* adjust upper limit */ |
| 266 | if (i > lim) |
| 267 | break; /* no more elements to count */ |
| 268 | } |
| 269 | /* count elements in range (2^(lg-1), 2^lg] */ |
| 270 | for (; i <= lim; i++) { |
| 271 | if (!ttisnil(&t->array[i-1])) |
| 272 | lc++; |
| 273 | } |
| 274 | nums[lg] += lc; |
| 275 | ause += lc; |
| 276 | } |
| 277 | return ause; |
| 278 | } |
| 279 | |
| 280 | |
| 281 | static int numusehash (const Table *t, int *nums, int *pnasize) { |