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