Path: utzoo!mnetor!uunet!husc6!bbn!rochester!cornell!oravax!clay From: clay@oravax.UUCP (McFarland) Newsgroups: comp.lang.c Subject: Re: XOR-trick and PUZZLE (was comma-operator) Message-ID: <181@oravax.UUCP> Date: 29 Jan 88 19:39:22 GMT References: Reply-To: clay@oravax.odyssey.UUCP (Clay Brooke-McFarland) Organization: Odyssey Research Associates, Ithaca, New York Lines: 23 In article bader+@andrew.cmu.edu (Miles Bader) writes: >> How can you use the XOR trick to keep a doubly linked list, using only >> one field for in each record, to code for finding both the following and >> the previous record? > >To make it a bit clearer, you have to be able to find the NEXT record >given the current and previous records, and find the PREVIOUS record >given the current and the next record. To make it a bit clearer all you have to do is XOR it with itself :-} Of more interest, since you can store n things in a register and get any of them back given the other n-1 you can store NEXT ^ PREVIOUS ^ KEY and keep the KGB from deciphering your linked lists (Now where did I put that key...). Clay Brooke-McFarland Odyssey Research Associates --------------------------------------------------------------| "Wait! There's something we're all overlooking!" Chorus: "What| is it, Doctor?" "I don't know. I'm overlooking it myself." | --------------------------------------------------------------|