I am working with a flattened 2D array $C$ of size $A = n \times m$ and trying to create another array $D$ of size $k$, which contains unique products of the indices from $C$, i.e., $C[i \times j]$, where $0 \leq i < n$ and $0 \leq j < m$. Note that $i \times j$ is the same as $j \times i$, hence some products overlap. The output array $D$ contains unique values of $C[i \times j]$ such that $D[u] = C[i \times j]$, where $u$ is a unique index for each unique product, and $k$ is the total number of these unique products.
Based on my observations for large sizes, $k \approx 0.25 \times A$. Currently, I'm using a map $h$ to store the relationship $h[i \times j] = u$ so that $D[u] = C[i \times j]$. However, the map becomes quite substantial in size for very large arrays (e.g., $2^{28}$).
Is there a known mathematical function or method to create an index for these unique products by a formula, instead of using a map? Specifically, I'm looking for a function that would take $i$ and $j$ as input and output $u$, such that $0 \leq u < k$.
Update:
A sample:
For $C$ = $[0, 1, 2, 3, 4, 5, 6, 7]$ and $n$ = 2 and $m$ = 4 the combination of unique values would be $D$ = $[0, 1, 2, 3]$ and the $h$ map would be equal to $D$.
For $C$ = $[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]$ and $n$ = 3 and $m$ = 4, $D$ = [0, 1, 2, 3, 4, 6] and so on.
indexes are $0$ based