2024-03-10 14:05:12 +01:00
2024-03-10 14:05:12 +01:00
2022-08-15 17:43:57 +02:00
2024-03-10 14:05:12 +01:00
2024-03-10 14:05:12 +01:00
2024-03-10 14:05:12 +01:00
2017-02-04 09:10:28 +01:00
2022-08-25 15:12:53 +00:00
2024-03-10 14:05:12 +01:00

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. The feature that separates this implementation from others is that the lists keep track of whether they are sorted. This enables powerfull optimizations for searching, union or retain operations.

LongLongHashMap and LongObjHashMap are maps that use primitive longs as keys.

Sparse2DLongArray is a memory efficient alternative to long[][]. In contrast to long[][] the indices are signed longs, which allows you to have negative keys and keys > 2^31.

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:

repositories {
	maven { url 'https://repo.lucares.de/' }
}
dependencies {
	compile 'org.lucares:primitiveCollections:0.3'
}

Examples

IntList / LongList

An alternative to int[]/long[] that grows dynamically. The list supports a few features that are either not supported by arrays or that would be expensive to implement. The most unique feature is that the list knows if it is sorted.

isSorted()

The lists keep track of whether they are sorted or not. This makes the call to isSorted() very cheap, because we only have to return the value of a field. The drawback is that some operations are much more expensive. This affects shuffle(), as well as remove(int, int), removeIf(), removeAll(IntList) and 'retainAll()' if the list was not sorted before.

The fact that we know if a list is sorted allows us to use more efficient algorithms for union(IntList, IntList), intersection(IntList, IntList), indexOf(int), lastIndexOf() and uniq().

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
Description
No description provided
Readme MIT 667 KiB
Languages
Java 99.9%
Shell 0.1%