Is there an alternative to Guava Tables that uses primitives, instead of generic types, as the keys?
I would like to use primitives to avoid the auto-boxing caused by using Java Numbers and the additional entry objects created by Java Maps.
I've rolled my own basic LongLongObjectTable using Trove TLongObjectMap, but would prefer to use a standard library if one is available.
private static class LongLongObjectTable<T> {
private final TLongObjectMap<TLongObjectMap<T>> backingMap = new TLongObjectHashMap<>();
T get(final long rowKey, final long columnKey) {
final TLongObjectMap<T> map = this.backingMap.get(rowKey);
if (map == null) {
return null;
}
return map.get(columnKey);
}
void put(final long rowKey, final long columnKey, final T value) {
TLongObjectMap<T> map = this.backingMap.get(rowKey);
if (map == null) {
map = new TLongObjectHashMap<>();
this.backingMap.put(rowKey, map);
}
map.put(columnKey, value);
}
Collection<T> values() {
final List<T> values = new ArrayList<T>();
for (final TLongObjectMap<T> map : this.backingMap.valueCollection()) {
values.addAll(map.valueCollection());
}
return values;
}
}
>10^n
operations per second, withn
depending on your specific problem, though in generaln>3
. Are you sure this is your case? – KraTable
implementation. – Caudill