I need a compact invertable indexing scheme. I have k options and I choose n, yielding $\binom{k}{n}$ combinations. Now I want a function $f(x_1,x_2,...,x_n)$ which yields an index, such that all numbers up to $\binom{k}{n}$ are used. And I want a function that does the inverse $g(y)$, starts with an index and returns $x_1,x_2,...,x_n$
I have already found a scheme for my specific problem (k choose 2), but I was wondering if there is a more general solution.
You can use combinadics.
Assume that we are indexing subsets of $\{0,1,\dots,k-1\}$. As long as the $x_i$'s are in increasing order, i.e. $x_1<x_2<\dots<x_n$, then one indexing function which works is $$ f(x_1,\dots,x_n)=\binom{x_1}1+\binom{x_2}2+\dots+\binom{x_n}{n} $$ (with the convention that $\binom{n}k=0$ when $k>n$).
Let $g_n$ be the inverse index function mapping nonnegative integers to sets of $n$ integers. Then $$ g_n(i)=g_{n-1}\left(i-\binom{r}n\right)\cup \{r\}, $$ where $r$ is the largest integer satisfying $\binom{r}n\le i$. That is, you find $r$, recursively compute the set $g_{n-1}(i-\binom{r}n)$, and then add $r$ to this set.