I need to perform a check if the combination of a long value and an integer value were already seen before in a very performance-critical part of an application. Both values can become quite large, at least the long will use more than MAX_INT values in some cases.
Currently I have a very simple implementation using a Set<Pair<Integer, Long>>
, however this will require too many allocations, because even when the object is already in the set, something like seen.add(Pair.of(i, l))
to add/check existence would allocate the Pair for each call.
Is there a better way in Java (without libraries like Guava, Trove or Apache Commons), to do this check with minimal allocations and in good O(?)
?
Two ints would be easy because I could combine them into one long in the Set, but the long cannot be avoided here.
Any suggestions?