getting unique identifier out of two variables

J

JArgyle

Hi,

given a set of pairs

P = {(x1,y1), (x2,y2), ... (xn,yn)}

where each pair is unique, is there a way to get

Q = {z1, z2, ..., zn}

that is to map each pair of values to another unique one? Is hashing the
only way to achieve this?

Regards

Josè
 
S

Stefan Ram

JArgyle said:
given a set of pairs
P = {(x1,y1), (x2,y2), ... (xn,yn)}
where each pair is unique, is there a way to get
Q = {z1, z2, ..., zn}
that is to map each pair of values to another unique one?

»That is« is used to join two wordings with the same meaning.
This is not the case here. Moreover, your question only
mentions mathematical concepts, but shows no relation to C++.

Yes, for every set P of pairs, there exists a set Q, so that
there exists a mapping f: P -> Q, so that f is injective and
f(x) != x. Proof: Map each x to the set {x}.
 
J

JArgyle

Stefan said:
»That is« is used to join two wordings with the same meaning.
This is not the case here. Moreover, your question only
mentions mathematical concepts, but shows no relation to C++.

Yes, for every set P of pairs, there exists a set Q, so that
there exists a mapping f: P -> Q, so that f is injective and
f(x) != x. Proof: Map each x to the set {x}.

You must have had a very difficult childhood.

Kind Regards
 
J

JArgyle

Alf said:
Or for example, if they're unsigned char and sizeof(unsigned int)>=2,
then let z = (unsigned(x)<<CHAR_BIT) | unsigned(y).

Hi Alf, thanks. In my case they are two unsigned int (I'm evaluating if
two size_t are better though). I was indeed considering to gather them
into a struct and overloading the < operator (as you also suggest), but
I was interested in a more low-level approach, such as the one you
describe over here. Could you expand a bit on this? Supposing I have two
uint32_t would it still possible to do something like this?

Regards

J.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top