9 ms·
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
by joseluis 2y 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.
- o11c 2y agoAddition/subtraction are more likely to optimize well I think, since pointer arithmetic already uses those.
- deleted 2y ago[deleted]
- deleted 2y ago[deleted]
- jsheard 2y agoGood point, on x86 at least the mov instruction can add/subtract a constant from the address by itself since that pattern is so common.