Compare commits

...

7 Commits

Author SHA1 Message Date
68567c1b48 Merge branch 'master' of https://git.lucares.de/andi/primitive-collections 2023-02-08 20:04:21 +01:00
0e98ba493b update 3rd party libs 2023-02-08 19:50:53 +01:00
ee55ed9683 Update 'README.md' 2022-08-25 15:12:53 +00:00
88808edf01 Update 'README.md' 2022-08-22 18:02:18 +00:00
58891020e8 Update 'README.md' 2022-08-15 16:19:49 +00:00
078c0273bf Update 'README.md' 2022-08-15 16:18:50 +00:00
e0a045f1e8 Merge pull request 'update dependencies' (#1) from update-dependencies into master
Reviewed-on: #1
2022-08-15 15:56:22 +00:00
2 changed files with 27 additions and 29 deletions

View File

@@ -1,19 +1,11 @@
Java collections for primitives (currently only int) released under [MIT](https://opensource.org/licenses/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.
*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.
The lists support the following 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.
* 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.
@@ -21,9 +13,8 @@ The library is still considered beta. There no pre-build artifacts on Maven Cent
Example for Gradle:
```groovy
apply plugin: 'maven'
repositories {
maven { url 'https://repo.lucares.org/' }
maven { url 'https://repo.lucares.de/' }
}
dependencies {
compile 'org.lucares:primitiveCollections:0.3'
@@ -32,21 +23,25 @@ dependencies {
# 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()`.
```java
import org.lucares.collections.IntList;
final IntList list = IntList.of(1, 3, 5);
System.out.println(list + " is sorted: " + list.isSorted());
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.insert(2, 7);
System.out.println(list + " is sorted: " + list.isSorted());
list.sort();
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:
@@ -56,3 +51,6 @@ Running this program gives the following output:
[1, 3, 7, 5] is sorted: false
[1, 3, 5, 7] is sorted: true
```

View File

@@ -13,7 +13,7 @@ buildscript {
plugins {
// usage: gradle dependencyUpdates -Drevision=release
id "com.github.ben-manes.versions" version "0.42.0"
id "com.github.ben-manes.versions" version "0.45.0"
}
apply plugin: 'java'
@@ -22,8 +22,8 @@ apply plugin: 'eclipse'
ext {
javaVersion=11
version_junit = '5.9.0'
version_junit_platform = '1.9.0'
version_junit = '5.9.2'
version_junit_platform = '1.9.2'
}