Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

It's pretty well-known but my favourite XOR trick is XOR linked lists. [1]

It's possible to store a doubly-linked list using only a single pointer per node. For entry B, &B = &A ^ &C. You can walk the list in either direction as long as you have pointers to two neighbouring nodes in the list. Half as much memory overhead compared to an implementation where each node stores two pointers.

[1] https://en.wikipedia.org/wiki/XOR_linked_list



Consider applying for YC's Winter 2026 batch! Applications are open till Nov 10

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: