Update 'README.md'
This commit is contained in:
34
README.md
34
README.md
@@ -32,21 +32,25 @@ dependencies {
|
|||||||
|
|
||||||
# Examples
|
# 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
|
```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 {
|
list.insert(2, 7);
|
||||||
public static void main(final String[] args) {
|
System.out.println(list + " is sorted: " + list.isSorted());
|
||||||
final IntList list = IntList.of(1, 3, 5);
|
|
||||||
System.out.println(list + " is sorted: " + list.isSorted());
|
|
||||||
|
|
||||||
list.insert(2, 7);
|
list.sort();
|
||||||
System.out.println(list + " is sorted: " + list.isSorted());
|
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:
|
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, 7, 5] is sorted: false
|
||||||
[1, 3, 5, 7] is sorted: true
|
[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