Update 'README.md'
This commit is contained in:
22
README.md
22
README.md
@@ -32,11 +32,17 @@ dependencies {
|
||||
|
||||
# Examples
|
||||
|
||||
```java
|
||||
import org.lucares.collections.IntList;
|
||||
## 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.
|
||||
|
||||
public class Example {
|
||||
public static void main(final String[] args) {
|
||||
### 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
|
||||
final IntList list = IntList.of(1, 3, 5);
|
||||
System.out.println(list + " is sorted: " + list.isSorted());
|
||||
|
||||
@@ -45,8 +51,6 @@ public class Example {
|
||||
|
||||
list.sort();
|
||||
System.out.println(list + " is sorted: " + list.isSorted());
|
||||
}
|
||||
}
|
||||
|
||||
```
|
||||
Running this program gives the following output:
|
||||
@@ -56,3 +60,9 @@ Running this program gives the following output:
|
||||
[1, 3, 7, 5] is sorted: false
|
||||
[1, 3, 5, 7] is sorted: true
|
||||
```
|
||||
|
||||
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()`.
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user