MCPcopy Create free account
hub / github.com/F-Stack/f-stack / unbound_search

Function unbound_search

freebsd/contrib/openzfs/module/lua/ltable.c:535–556  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

533
534
535static 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/*

Callers 1

luaH_getnFunction · 0.70

Calls 1

luaH_getintFunction · 0.85

Tested by

no test coverage detected