Version française
Home     About     Download     Resources     Contact us    
Browse thread
AW: [Caml-list] paralell assignment problem
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Beck01, Wolfgang <BeckW@t...>
Subject: AW: [Caml-list] paralell assignment problem

> The solution is a sequence of assignments involving
> only xi, ei, and ti, where ti are temporaries introduced
> to save the values of the expressions. For example,
> a solution to
> 
> 	x,y = y,x
> 
> is
> 
> 	t = x; x = y; y = t
> 
> I seek a solution which minimises the number of assignments. 
> Note that the relation 
you probably know the 'xor trick' to swap value without a temporary:
// x = A; y = B
x = x lxor y;
// x = A XOR B; y = B
y = x lxor y;
// x = A XOR B; y = A XOR B XOR B
// x = A XOR B; y = A
x = x lxor y;
// x = A XOR B XOR A; y = A
// x = B; y = A

Certainly not what you were looking for, but always nice :-)


Wolfgang