MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / unbound_search

Function unbound_search

deps/lua/src/ltable.c:532–553  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

530
531
532static 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/*

Callers 1

luaH_getnFunction · 0.85

Calls 1

luaH_getnumFunction · 0.85

Tested by

no test coverage detected