Closed svlandeg closed 5 years ago
I guess it's an unideal quirk. The first implementations actually didn't allow 0 keys either, but there's now a mechanism for that: you can specify the value that denotes "empty", so you can set that to something else if you need 0 in the table. We could do something like this to allow 0 as a value.
There does need to be some 64-bit value that denotes empty key, and a 64-bit value that denotes deleted key. We also need a 64-bit value to denote empty.
Unfortunately I think it'll cause some trouble to fix this, as I think a lot of code assumes that 0 is missing from Preshed, as it's pretty much always been like this. Does it inconvenience your code much?
It just took me some time to realise what was going on, as it wasn't clear to me that 0 couldn't be a value. But now I just add a dummy element in the array first, so that the PreshMap never has to point to index 0.
Is it a feature or a bug that a
PreshMap
can not contain0
as value?Consider this code:
which prints
yay
which prints
not so yay