Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: "Beck01, Wolfgang" <BeckW@t-systems.com>
To: caml-list@inria.fr
Subject: AW: [Caml-list] paralell assignment problem
Date: Tue, 8 Feb 2005 15:24:50 +0100	[thread overview]
Message-ID: <76C27E1CE3FFC847B4D51C645D6F42AA15FE3B@E9JDF.mgb01.telekom.de> (raw)


> 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



             reply	other threads:[~2005-02-08 14:24 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-02-08 14:24 Beck01, Wolfgang [this message]
2005-02-08 15:30 ` skaller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=76C27E1CE3FFC847B4D51C645D6F42AA15FE3B@E9JDF.mgb01.telekom.de \
    --to=beckw@t-systems.com \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox