I stumbled on a Wikipedia article about the Xor linked list, and it's an interesting bit of trivia, but the article seems to imply that it occasionally gets used in real code. I'm curious what it's good for, since I don't see why it makes sense even in severely memory/cache constrained systems:
Given the above, what's the point? Are there any weird corner cases where an xor linked list is actually worthwhile?
Apart from saving memory, it allows for O(1) reversal, while still supporting all the other destructive update operations efficienctly, like
concat
ing two lists destructively in O(1)insertAfter
/insertBefore
in O(1), when you only have a reference to the node and its successor/predecessor (which differs slightly from standard doubly linked lists)remove
in O(1), also with a reference to either the successor or predecessor.I don't think the memory aspect is really important, since for most scenarios where you might use a XOR list, you can use a singly-linked list instead.