What I have is the following:A mapping $f : key \rightarrow set$ that works in constant timeAn inefficient mapping $g : \{key\} \rightarrow \cup_{k \in \{key\}} f(k)$ where this union is slowIs there a data structure that would make things faster?I could precalculate for every possible set of keys the wanted output but for a fairly large number of possible keys this isn't feasible ($O(2^n)$), despite the fact that lookup would be fast enough.Currently I'm using a dictionary to have an efficient mapping $f$. For each value in a set of keys, I get the result by applying $f$, and do a union over the results. This is inefficient.
Efficient data structure for set to union of sets mapping
data structures