robison@uiucdcsb.CS.UIUC.EDU (06/08/86)
I once saw an article on the virtues of the ``pointer rotation'' operation.
I can't remember where I saw it, and would appreciate if someone would
mail me a reference to it. The general idea is described below.
robison@uiucdcs
Arch D. Robison
University of Illinois at Urbana-Champaign
----------------------------------------------------------------------
Given a set of pointers, say P,Q, and R, the operation would rotate their
values, i.e.:
procedure Rot (var P,Q,R: pointer);
var T:pointer;
begin
T:=P; P:=Q; Q:=R; R:=T;
end;
The operation is a structured assignment statement. By using the rotations
instead of assignment, one could guarantee certain properties of a program.
E.g. that reference counts did not change. The rotation operation also
makes many common algorithms more succinct, for example we can reverse a list
pointed to by R with:
Q := nil;
while R<>nil do Rot (R,R^.Next,Q);
Swap (R,Q);
(Swap is a two-way rotate.) Since Q is initially nil, and nil after
the code finishs, we are guaranteed that we neither lost nor gained references.
I used rotates throughout a project of mine, and they greatly reduced
problems with maintaining reference counts. Some 5-way rotations were
even useful.