Path: utzoo!mnetor!uunet!lll-winken!lll-lcc!ames!mailrus!rutgers!iuvax!pur-ee!uiucdcs!uiucdcsb!kenny From: kenny@uiucdcsb.cs.uiuc.edu Newsgroups: comp.lang.c Subject: Re: Put your code... (was Re: gotos Message-ID: <165600041@uiucdcsb> Date: 26 Apr 88 00:07:00 GMT References: <2597@ttrdc.UUCP> Lines: 52 Nf-ID: #R:ttrdc.UUCP:2597:uiucdcsb:165600041:000:1391 Nf-From: uiucdcsb.cs.uiuc.edu!kenny Apr 25 19:07:00 1988 [Part 3: Operations on parallel data structures] EXAMPLE 5 looks like: search: if (A[i] < x) { if (L[i] != 0) { i = L[i]; goto search; } else { L[i] = j; goto insert; } } else if (R[i] != 0) { i = R[i]; goto search; } else { R[i] = j; goto insert; } } insert: A[j] = x; L[j] = 0; R[j] = 0; Knuth claims that the _goto_ structure brings out the nature of the parallel operations on the L and R links. If this be true, why not collapse the code for these parallel operations? I would much rather see: for (;;) { register int *ptr; if (A[i] < x) ptr = & L [i]; else ptr = & R [i]; if (!*ptr) { *ptr = j; break; } i = *ptr; } A [j] = x; L [j] = 0; R [j] = 0; We have handled this by generating one reference to the member of the L or R array in question, and then using this reference, rather than duplicating the code. The argument about performance is difficult to address in this case, since it is heavily dependent on the machine architecture. Anyone who is worried about performance for code like this, though, will use pointers rather than array indices and make the L and R structure components rather than arrays, so the question is moot. Moral: If you're doing the same thing to parallel data structures, run the same code on the two structures rather than complicating your control flow by duplicating the code. [End of part 3.]