For a project I'm working on, I try to create a multi-dimensional pivot on large data sets. I have all the keys I want to use as int
s, so basically, I want to return a set of
( int1, int2, int3, .. intN ) -> (Aggregate1, Aggregate2, ... , AggregateM)
I cannot use a N-dimensional array, as it might get huge and probably will be sparse. I've looked a Trove, but they do not have a Multi-key map. Apache commons has a multi-key map, but that is for Objects
; that would probably work, but seems less interesting as the int
s will get auto-boxed to Integers
and vice versa.
Does anyone know of a primitive multi-key map implementation? (That maps to objects?)
Or, does anyone have great hints, maybe there is a better approach to my problem?
[edit] Insertion time is less interesting, I need the performance on the lookup, as the map will be heavily used to lookup values.
[edit2]
Thanks for all the answers. My implemenation choice is a custom class containing an int[], immutable so the hashcode
can be calculated on construction time.
private static class MultiIntKey
{
int[] ints;
private int hashCode;
MultiIntKey( int[] ints )
{
this.ints = ints;
this.hashCode = Arrays.hashCode( this.ints );
}
@Override
public int hashCode()
{
return this.hashCode;
}
@Override
public boolean equals( Object obj )
{
if ( this == obj )
{
return true;
}
if ( obj == null )
{
return false;
}
if ( this.getClass() != obj.getClass() )
{
return false;
}
MultiIntKey other = (MultiIntKey) obj;
if ( this.hashCode != other.hashCode )
{
return false;
}
if ( !Arrays.equals( this.ints, other.ints ) )
{
return false;
}
return true;
}
}