cedccefe92d181825fd4caaf83a775750d4589f3
Added getUnsafe and addUnsafe, two methods that skip checks. The checks are not needed in unionSorted, because we made sure the code works correctly. getUnsafe still has the checks, but as assertions. The speedup is roughly 20%. Here are some results for calling union 2^16 times for two random sorted lists with 16k elements: Duration: 20170 -> 16857 (83.57%) Instructions: 138.277.743.679 -> 108.474.027.213 (78.4%) Instructions per cycle: 2,33 -> 2,18 Branches: 30.248.330.644 -> 19.908.207.057 (65.8%) Branch Misses: 3.012.427 -> 3.477.433 Cycles per list element: 65.93 -> 51.72 (78.4%) Created with (the test program is not committed) on a Core2Duo 8600: perf stat -d -d -d --delay 2000 java -cp bin/test:bin/main org.lucares.collections.Test 16000 16
Java collections for primitives (currently only int) released under MIT license.
IntList and LongList are implementations of lists that store primitive integers/longs. The ints/longs are stored in an int/long array and the class takes care of growing the array as needed. You can trim the list to reduce the memory overhead. No dependencies.
The lists support the following operations:
- add/remove elements via single and bulk operations
- replace elements
- sort and shuffle
- the lists know whether or not they are sorted and can leverage that knowledge for searching (binary search), union and intersection
- search for elements
- union, intersection, retainIf, retainAll removeIf, removeAll
- clear and trim are separate methods, so that the list can be re-used without having to re-allocate memory
- stream support
- the lists are serializable and cloneable
- the lists are not thread-safe
How to use
The library is still considered beta. There no pre-build artifacts on Maven Central or JCenter, but you can download them from repo.lucares.org.
Example for Gradle:
apply plugin: 'maven'
repositories {
maven { url 'https://repo.lucares.org/' }
}
dependencies {
compile 'org.lucares:primitiveCollections:0.1.20181120195412'
}
Examples
import org.lucares.collections.IntList;
public class Example {
public static void main(final String[] args) {
final IntList list = IntList.of(1, 3, 5);
System.out.println(list + " is sorted: " + list.isSorted());
list.insert(2, 7);
System.out.println(list + " is sorted: " + list.isSorted());
list.sort();
System.out.println(list + " is sorted: " + list.isSorted());
}
}
Running this program gives the following output:
[1, 3, 5] is sorted: true
[1, 3, 7, 5] is sorted: false
[1, 3, 5, 7] is sorted: true
Languages
Java
99.9%
Shell
0.1%