OpenHFT/HugeCollections — pull request #7 by jaromirs (2014-02-12 16:02:40+00:00)
Title: HugeHashMap: recyclable vs immutable key

Current implementation of HugeHashMap handles CharSequence type specifically. It converts it into a string whenever it needs to use CharSequence as a key for standard java.util.HashMap (this is correct because for instance StringBuilder does not override equals and hashCode methods and needs to be converted into a string). Consequently the HugeHashMap creates a new string with every put (line 252, current version of HugeHashMap).

The proposed modification introduces a concept of reusable vs immutable key. For all operations on java.util.HashMap except put, we use reusable key, for put we MUST create an immutable copy of the reusable key.

3 additional comments:
1. The API is not as nice as in the original solution but it helps to avoid creating unnecessary objects on the heap and makes sure that reusable key objects are not used as keys for java.util.HashMap.put operation.
2. The proposed modifiation requires that the Key type implements BytesMarshallable interface. This might be too restrictive in some cases (?).
3. I am not sure that all the changes will be accepted but in general I think it is a step in the right direction.