top | item 40300015

(no title)

joseluis | 1 year 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.

discuss

order

o11c|1 year ago

Addition/subtraction are more likely to optimize well I think, since pointer arithmetic already uses those.

jsheard|1 year ago

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.