[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: question on string hashing and interning in Lua
- From: Javier Guerra Giraldez <javier@...>
- Date: Wed, 13 May 2020 19:01:15 -0500
On Wed, 13 May 2020 at 18:11, Andrea <andrea.l.vitali@gmail.com> wrote:
> - is there a limit on the max length for strings to be interned? (it seems that LuaJIT applies interning only on short strings)
LuaJIT hashes and interns all strings, but uses only 12 bytes of each
(first 4, last 4 and 4 at the middle. these might overlap on short
strings, of course), so the hash time is O(1), but trivial to get a
collision, even by accident.
> - it seems the hash function does not look at all characters in the string, or does it? (not looking at all characters increase speed but also collisions)
Lua interns only "short" strings, (40 bytes by default, IIRC), other
strings are only interned when used as table keys (and when comparing?
not sure). at that point, i think it uses all bytes (could be wrong),
but it won't "deduplicate" it, so "long" strings are never "fully
interned"
in short, you have it almost right, just reversed between Lua and LuaJIT
--
Javier
_______________________________________________
lua-l mailing list -- lua-l@lists.lua.org
To unsubscribe send an email to lua-l-leave@lists.lua.org