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