MCPcopy Create free account
hub / github.com/EmmyLua/EmmyLuaDebugger / rehash

Function rehash

third-party/lua-5.5.0/src/ltable.c:762–792  ·  view source on GitHub ↗

** Rehash a table. First, count its keys. If there are array indices ** outside the array part, compute the new best size for that part. ** Then, resize the table. */

Source from the content-addressed store, hash-verified

760** Then, resize the table.
761*/
762static void rehash (lua_State *L, Table *t, const TValue *ek) {
763 unsigned asize; /* optimal size for array part */
764 Counters ct;
765 unsigned i;
766 unsigned nsize; /* size for the hash part */
767 /* reset counts */
768 for (i = 0; i <= MAXABITS; i++) ct.nums[i] = 0;
769 ct.na = 0;
770 ct.deleted = 0;
771 ct.total = 1; /* count extra key */
772 if (ttisinteger(ek))
773 countint(ivalue(ek), &ct); /* extra key may go to array */
774 numusehash(t, &ct); /* count keys in hash part */
775 if (ct.na == 0) {
776 /* no new keys to enter array part; keep it with the same size */
777 asize = t->asize;
778 }
779 else { /* compute best size for array part */
780 numusearray(t, &ct); /* count keys in array part */
781 asize = computesizes(&ct); /* compute new size for array part */
782 }
783 /* all keys not in the array part go to the hash part */
784 nsize = ct.total - ct.na;
785 if (ct.deleted) { /* table has deleted entries? */
786 /* insertion-deletion-insertion: give hash some extra size to
787 avoid repeated resizings */
788 nsize += nsize >> 2;
789 }
790 /* resize the table to new computed sizes */
791 luaH_resize(L, t, asize, nsize);
792}
793
794/*
795** }=============================================================

Callers 1

luaH_newkeyFunction · 0.70

Calls 5

countintFunction · 0.70
numusehashFunction · 0.70
numusearrayFunction · 0.70
computesizesFunction · 0.70
luaH_resizeFunction · 0.70

Tested by

no test coverage detected