| 227 | |
| 228 | |
| 229 | static int numusearray (const Table *t, int *nums) { |
| 230 | int lg; |
| 231 | int ttlg; /* 2^lg */ |
| 232 | int ause = 0; /* summation of `nums' */ |
| 233 | int i = 1; /* count to traverse all array keys */ |
| 234 | for (lg=0, ttlg=1; lg<=MAXBITS; lg++, ttlg*=2) { /* for each slice */ |
| 235 | int lc = 0; /* counter */ |
| 236 | int lim = ttlg; |
| 237 | if (lim > t->sizearray) { |
| 238 | lim = t->sizearray; /* adjust upper limit */ |
| 239 | if (i > lim) |
| 240 | break; /* no more elements to count */ |
| 241 | } |
| 242 | /* count elements in range (2^(lg-1), 2^lg] */ |
| 243 | for (; i <= lim; i++) { |
| 244 | if (!ttisnil(&t->array[i-1])) |
| 245 | lc++; |
| 246 | } |
| 247 | nums[lg] += lc; |
| 248 | ause += lc; |
| 249 | } |
| 250 | return ause; |
| 251 | } |
| 252 | |
| 253 | |
| 254 | static int numusehash (const Table *t, int *nums, int *pnasize) { |