News for hackers. Stuff that matters.
Re:XOR Linked List by codezero on Thursday May 03, 2012 @06:27PM (#3926112)
Just curious, this wouldn't work for a circularly linked list in the case where there is only one element, right?
Re:XOR Linked List by pmjordan on Thursday May 03, 2012 @06:54PM (#3926206)
Generally, it doesn't allow you to walk the list given the pointer to an entry. You always need to know the addresses of two adjacent list entries. And yes, this limits its usefulness in practice. I tend to only need doubly linked lists where I want to be able to remove or insert an arbitrary element without walking the list, and you can't do that with an xor list.
Re:XOR Linked List by tresta on Thursday May 03, 2012 @06:33PM (#3926139)
Why wouldn't it?

A xor A = 0.

A xor 0 = A.

That should work like a regular circularly linked list or am I missing something?

edit

Doh, now I understand. If this was allowed it wouldn't be possible to have a one-node non-circular list.

Re:XOR Linked List by bbrtyth on Thursday May 03, 2012 @08:07PM (#3926407)
It would be the reverse case if it were non-circular, returning 0.
Re:XOR Linked List by ithkuil on Friday May 04, 2012 @03:05AM (#3927417)
You can encode "end of list" with another value like -1 which is usually safe since you can assume that addresses are at word aligned (so odd numbers cannot be addresses)