wren icon indicating copy to clipboard operation
wren copied to clipboard

Fix hash mask

Open billyquith opened this issue 5 years ago • 5 comments

The hashing function which uses Thomas Wang's algorithm masks off the top bit, which isn't in Wang's algorithm. Masking the bit off effectively halves the hash space, which is already masked from 64 to 32 bits. Having a larger hash just reduces the chance of collisions.

It is used in the hash table and the modulo used, so will have little effect, but it could be used for other things, which may benefit from this in the future.

Also fixed the hyperlink to the article as site link disappeared.

billyquith avatar Nov 25 '20 20:11 billyquith

Why would V8 do this? Do you know?

joshgoebel avatar Apr 27 '21 02:04 joshgoebel

Why would V8 do this? Do you know?

I don't know. I think the source is available but I haven't checked for comments. At a wild guess I'd say they cast it to an int a lot and didn't want a negative number. What other reasons are there?

billyquith avatar May 02 '21 10:05 billyquith

Where did you get this information about V8 masking the top bit - just from our own line 361? I can't seem to confirm...

  • Deno: https://denolib.github.io/v8-docs/functional_8cc_source.html
  • Chromium: https://source.chromium.org/chromium/chromium/src/+/master:v8/src/base/functional.cc;drc=e51dd5c377fd47393a171f6bdcd7c1a6a9a609c5;l=97
  • GitHub V8 mirror: https://github.com/v8/v8/blob/master/src/base/functional.cc

joshgoebel avatar May 02 '21 12:05 joshgoebel

Where did you get this information about V8 masking the top bit - just from our own line 361? I can't seem to confirm...

I'm sorry Josh, I can't remember. I did some searching at the time. It may be from the Wren comments. I guess if V8 does not mask, all the more reason to not mask.

billyquith avatar May 02 '21 18:05 billyquith

https://github.com/wren-lang/wren/commit/2a1499b04bc65853fdf71db2126e716168d4c5ae

Look's like Bob's work in 2019. Any idea/memory on why we're masking that high bit in the first place?

CC @munificent

joshgoebel avatar May 02 '21 18:05 joshgoebel