MCPcopy Create free account
hub / github.com/bloomberg/comdb2 / unbound_search

Function unbound_search

lua/ltable.c:633–654  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

631
632
633static 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/*

Callers 1

luaH_getnFunction · 0.85

Calls 1

luaH_getnumFunction · 0.85

Tested by

no test coverage detected