MCPcopy Create free account
hub / github.com/BZFlag-Dev/bzflag / unbound_search

Function unbound_search

other_src/lua/src/ltable.cpp:569–590  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

567
568
569static int unbound_search (Table *t, unsigned int j) {
570 unsigned int i = j; /* i is zero or a present index */
571 j++;
572 /* find `i' and `j' such that i is present and j is not */
573 while (!ttisnil(luaH_getnum(t, j))) {
574 i = j;
575 j *= 2;
576 if (j > cast(unsigned int, MAX_INT)) { /* overflow? */
577 /* table was built with bad purposes: resort to linear search */
578 i = 1;
579 while (!ttisnil(luaH_getnum(t, i))) i++;
580 return i - 1;
581 }
582 }
583 /* now do a binary search between them */
584 while (j - i > 1) {
585 unsigned int m = (i+j)/2;
586 if (ttisnil(luaH_getnum(t, m))) j = m;
587 else i = m;
588 }
589 return i;
590}
591
592
593/*

Callers 1

luaH_getnFunction · 0.70

Calls 1

luaH_getnumFunction · 0.70

Tested by

no test coverage detected