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