tags:

views:

96

answers:

2

I have a set of flags which are part of a huge text data file as single characters. Before processing the file I map each flag to the id of a property it represents. While processing the file I need to look up these mappings as fast as possible (I do it a lot).

Currently I store these in a HashMap. And the code looks like this:

    private HashMap<Integer, Integer> _propertyKeys;

    private int _getKeyedProperty(char key) {
      return (_propertyKeys.get((int) key));
    }

Is there any way I could be doing this faster, using a better implementation of Map than HashMap or even using arrays to prevent boxing/unboxing?

+2  A: 

You could use TIntIntHashMap from GNU Trove. It uses primitives for the keys and values.

I have used the GNU Trove primitive list classes and found that they give a noticeable performance improvement when compared to the standard list classes using autoboxing for primitives.

Mark
Thanks, I love the fact that c# supports primitives as types for all the generic stuff. Pity Java doesn't. By the way your link is to a local JavaDoc :) Sure Google can help me find it though.
Adrian Hope-Bailie
Oops.... Fixed.
Mark
A: 

If you know the full set of flags that will be used, you can create an Enum of them and use java.util.EnumMap.

Chris Kessel