Matthew D Moss wrote:

 >   C. Use some other structure (double-linked list, tree, etc).

> Bennies: Fast and efficient  (Maybe, maybe not?)

> Slaps:   Memory overhead can kill.


It is an amazing fact of computer science that a double-linked list can
be implemented for the same cost in memory as a single-linked list.

The magic trick is to EOR both links together, storing them in the same 
space that a single-link would use. This results in what seems to be 
perfect garbage. But the magic key to decode the link is simply the 
location of where you are coming from while traversing the list. You
EOR where you are coming from with the link value to find the address 
of where you are going to next. So, coming from link A you find that 
A EOR (A EOR B) = B, or coming from the other direction B EOR
(A EOR B) = A!

There is no such thing as a free lunch, so the two downsides are
1) this does take a tiny bit of processor time and 2) you must start at
one end of the list or the other to decode the links. You can't jump 
randomly into the middle of the list, look at the link and see how to
go either way from there.

Bob Spence


-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palm.com/devzone/mailinglists.html

Reply via email to