[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Re: Re: why lua table don't use prime number to hash
- From: Roberto Ierusalimschy <roberto@...>
- Date: Thu, 11 Mar 2021 11:05:34 -0300
> I tried it, and the running time of the test code reduce to zero second.
> I think maybe this is more adaptable to various situations if lua code change like that.
Maybe a slightly better option would be this one:
#define hashint(t,i) \
hashmod(t, cast_uint(l_castS2U(i) & (~0u)) ^ \
cast_uint(l_castS2U(i) >> (sizeof(int) * 8 - 8) >> 8));
It uses an unsigned 32-bit division, which is cheaper than an unsigned
64-bit division. (If lua_Integer == int, the compiler should be able
to optimize this out.)
-- Roberto