* AW: [Caml-list] paralell assignment problem
@ 2005-02-08 14:24 Beck01, Wolfgang
2005-02-08 15:30 ` skaller
0 siblings, 1 reply; 2+ messages in thread
From: Beck01, Wolfgang @ 2005-02-08 14:24 UTC (permalink / raw)
To: caml-list
> 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
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: AW: [Caml-list] paralell assignment problem
2005-02-08 14:24 AW: [Caml-list] paralell assignment problem Beck01, Wolfgang
@ 2005-02-08 15:30 ` skaller
0 siblings, 0 replies; 2+ messages in thread
From: skaller @ 2005-02-08 15:30 UTC (permalink / raw)
To: Beck01, Wolfgang; +Cc: caml-list
On Wed, 2005-02-09 at 01:24, Beck01, Wolfgang wrote:
> > I seek a solution which minimises the number of assignments.
[]
> you probably know the 'xor trick' to swap value without a temporary:
I've heard of it :)
> Certainly not what you were looking for, but always nice :-)
You are right, it isn't useful here for three reasons:
(1) the values being assigned aren't necessarily bitwise
copyable, in fact they're (more or less) arbitrary C++ values
(2) The intent is to reduce time not storage
(3) The RHS can be arbitrary expressions. To apply XOR,
we'd first assign each RHS expression to a temporary ..
and having done that we no longer need XOR, we can just
assign variables to those temporaries.
--
John Skaller, mailto:skaller@users.sf.net
voice: 061-2-9660-0850,
snail: PO BOX 401 Glebe NSW 2037 Australia
Checkout the Felix programming language http://felix.sf.net
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2005-02-08 15:30 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-02-08 14:24 AW: [Caml-list] paralell assignment problem Beck01, Wolfgang
2005-02-08 15:30 ` skaller
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox