| 533 | |
| 534 | |
| 535 | static int unbound_search (Table *t, unsigned int j) { |
| 536 | unsigned int i = j; /* i is zero or a present index */ |
| 537 | j++; |
| 538 | /* find `i' and `j' such that i is present and j is not */ |
| 539 | while (!ttisnil(luaH_getint(t, j))) { |
| 540 | i = j; |
| 541 | j *= 2; |
| 542 | if (j > cast(unsigned int, MAX_INT)) { /* overflow? */ |
| 543 | /* table was built with bad purposes: resort to linear search */ |
| 544 | i = 1; |
| 545 | while (!ttisnil(luaH_getint(t, i))) i++; |
| 546 | return i - 1; |
| 547 | } |
| 548 | } |
| 549 | /* now do a binary search between them */ |
| 550 | while (j - i > 1) { |
| 551 | unsigned int m = (i+j)/2; |
| 552 | if (ttisnil(luaH_getint(t, m))) j = m; |
| 553 | else i = m; |
| 554 | } |
| 555 | return i; |
| 556 | } |
| 557 | |
| 558 | |
| 559 | /* |
no test coverage detected