javachronicle-map

Map entries higher than Integer.MAX_VALUE


I am working with very large collections of small objects. I am using using ChronicleMap which is performing very well.

Is the maximum number of map entries limited to Integer.MAX_VALUE?

If not, how do I get the real size of a map as the map.size() returns Integer.MAX_VALUE if the number of entries is higher than Integer.MAX_VALUE?

Thanks in advance.


Solution

  • You can use ChronicleMap.longSize instead to get the size as a long. ChronicleMap.size will return Integer.MAX_VALUE when the size is greater then Integer.MAX_VALUE per the source: https://github.com/OpenHFT/Chronicle-Map/blob/master/src/main/java/net/openhft/chronicle/hash/impl/VanillaChronicleHash.java#L707

    This is in accordance with the Collection.size interface:

    Returns the number of elements in this collection. If this collection contains more than Integer.MAX_VALUE elements, returns Integer.MAX_VALUE.