** 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. */
| 257 | ** total number of non-nil keys. |
| 258 | */ |
| 259 | static unsigned int numusearray (const Table *t, unsigned int *nums) { |
| 260 | int lg; |
| 261 | unsigned int ttlg; /* 2^lg */ |
| 262 | unsigned int ause = 0; /* summation of 'nums' */ |
| 263 | unsigned int i = 1; /* count to traverse all array keys */ |
| 264 | /* traverse each slice */ |
| 265 | for (lg = 0, ttlg = 1; lg <= MAXABITS; lg++, ttlg *= 2) { |
| 266 | unsigned int lc = 0; /* counter */ |
| 267 | unsigned int lim = ttlg; |
| 268 | if (lim > t->sizearray) { |
| 269 | lim = t->sizearray; /* adjust upper limit */ |
| 270 | if (i > lim) |
| 271 | break; /* no more elements to count */ |
| 272 | } |
| 273 | /* count elements in range (2^(lg - 1), 2^lg] */ |
| 274 | for (; i <= lim; i++) { |
| 275 | if (!ttisnil(&t->array[i-1])) |
| 276 | lc++; |
| 277 | } |
| 278 | nums[lg] += lc; |
| 279 | ause += lc; |
| 280 | } |
| 281 | return ause; |
| 282 | } |
| 283 | |
| 284 | |
| 285 | static int numusehash (const Table *t, unsigned int *nums, unsigned int *pna) { |