| 631 | |
| 632 | |
| 633 | static int unbound_search (Table *t, unsigned int j) { |
| 634 | unsigned int i = j; /* i is zero or a present index */ |
| 635 | j++; |
| 636 | /* find `i' and `j' such that i is present and j is not */ |
| 637 | while (!ttisnil(luaH_getnum(t, j))) { |
| 638 | i = j; |
| 639 | j *= 2; |
| 640 | if (j > cast(unsigned int, MAX_INT)) { /* overflow? */ |
| 641 | /* table was built with bad purposes: resort to linear search */ |
| 642 | i = 1; |
| 643 | while (!ttisnil(luaH_getnum(t, i))) i++; |
| 644 | return i - 1; |
| 645 | } |
| 646 | } |
| 647 | /* now do a binary search between them */ |
| 648 | while (j - i > 1) { |
| 649 | unsigned int m = (i+j)/2; |
| 650 | if (ttisnil(luaH_getnum(t, m))) j = m; |
| 651 | else i = m; |
| 652 | } |
| 653 | return i; |
| 654 | } |
| 655 | |
| 656 | |
| 657 | /* |
no test coverage detected