Hacker News new | ask | show | jobs
by joseluis 768 days ago
You can do a handy struct wrapper over a private Nonzero that xors the given value with the prohibited value (max in this case) at the new constructor. And like so for the get method. Xoring is very cheap. That's my favorite way of storing indices/links for nodes, since you can wrap them in Option for free.
1 comments

Addition/subtraction are more likely to optimize well I think, since pointer arithmetic already uses those.
Good point, on x86 at least the mov instruction can add/subtract a constant from the address by itself since that pattern is so common.