Cantor pairing function is really one of the better ones out there considering its simple, fast and space efficient, but there is something even better published at Wolfram by Matthew Szudzik, here.
The problem with both functions is that they are highly inefficient when you use their recursive property and try to find a unique image of the tripple or any k
-tuple for k > 3
.
My problem: having a short list L
of say 1000
pairwise-distinct (unique) natural numbers, I want to build a function f1: L*L -> N
with the following properties:
- it does not need to be reversible, but injective (different pairs map to different integers): there is no need to compute the pair back.
- it must be efficiently computable even if it is reversible
and to build functions f2: L*L*L -> N, ..., fk: L*...*L -> N, k > 2
which can be based on f1
since it is recursive, but the range(fk), k > 1
should be reasonable and not go out of MAX int
in C++
so that it will be applicable. I understand this is hard to achieve for any k
, so we can limit k
by some value, say 5
or 10
and the bigger this limitation, the better the function.
I've been thinking about mapping k
-tuples into a real-valued sets like [0;1]
. This would allow to set off the limitation on k
. But have no idea how to get the function.