Singleton Collections in Java Trove

360 views Asked by At

Is there anything similar in Trove to Java's Collections.singleton, Collections.singletonList, or singletonMap?

I'm working in a application that uses many of the trove collections to reduce memory foot print. However, I have been unable to find any singleton Trove collections. For example, creating a TLongHashSet with 1 element using the default constructor will result in a TLongHashSet with an underlying array of 23 elements. Even when specifying the initial size and load factor as 1 and 1 will still result in an underlying array of 5 elements (Trove's the lowest prime is 5 based on gnu.trove.impl.PrimeFinder). In additional to the underlying array there are additional class variables that could be removed for a singleton implementation.

1

There are 1 answers

1
leventov On

No, there isn't in the current version of Trove.

You can use Koloboke collections (ex. HFTC) to reduce memory footprint even more, than with Trove, but assign them to variables/fields of parental JCF interface (e. g. java.util.Map), which interoperate well with JCF's Collections.singleton* implementations.