I have a sequence of integer tuples $t_1, t_2,..., t_N$ of different sizes in lexicographic order, e.g.:
$(1, 1), (1, 2), (1, 3, 5), (1, 3, 6), (1, 5), (3), (3, 2, 3), (3, 7), (3, 8, 1), ...$
- sequence length is $N \le 10^9 \space (2^{30})$,
- a tuple size bounded by $S, |t| \le S \le 32$,
- $i$-th element of a tuple is bounded: $0 \le x_i \le s_i$, $s_i \le N, \prod{s_i} > 2^{64}$
Currently I use tuple indexes in the sequence as keys in some associative array, I can search the sequence for a tuple index in $O(\log N)$.
I want to create a substitute for tuple indexes,
a function $f(t)$ that maps a tuple into a $64$-bit integer and has following qualities:
- preservation of the order: $i < j \rightarrow f(t_i) < f(t_j)$
- time of calculation of $f(t)$ is better than $O(\log N)$, ideally $O(S)$
- preprocessing time is $O(SN)$, requires $O(N)$ additional memory
- the sequence is the domain of $f$, behavior of $f$ for any other tuple is undefined
- given $f(t)$ value it is possible to find $t$ in $O(\log N)$ time
The motivation/context: I'm trying to improve performance of an in-memory OLAP cube. The tuples are indexes of unique values in data columns.