TroveP5 - a library to support int and float in ArrayLists and HashMaps
in
Library and Tool Development
•
1 year ago
TroveP5 is a wrapper for the java library
Trove, which is much faster, than using
ArrayLists,
HashMaps or
LinkedLists.
For example you may want to store several int values in an ArrayList:
- ArrayList al = new ArrayList();
- al.add(42);
- int a = (int)al.get(0); // ERROR: Cannot cast from Object to int
For this to work, you have to use:
- ArrayList<Integer> al = new ArrayList<Integer>();
- al.add(42);
- int a = al.get(0);
The problem here is, that all values are stored as Integer Objects
(
Integer != int
). If you have a lot of values, this is really slow. Instead you can use the Trove equivalent, which will be much faster! If you want to see how much faster it is, have a look at the
benchmark.
- TIntArrayList al = new TIntArrayList();
- al.add(42);
- int a = al.get(0);
From the origianal website:
The Trove library provides high speed regular and primitive collections for Java.
The GNU Trove library has two objectives:
- Provide "free" (as in "free speech" and "free beer"), fast, lightweight implementations of the java.util Collections API. These implementations are designed to be pluggable replacements for their JDK equivalents.
- Provide primitive collections with similar APIs to the above. This gap in the JDK is often addressed by using the "wrapper" classes (java.lang.Integer, java.lang.Float, etc.) with Object-based collections. For most applications, however, collections which store primitives directly will require less space and yield significant performance gains.
Download latest version here