Commit Graph

51 Commits

Author SHA1 Message Date
1d0d3e6d2b add *List.range() and *List.rangeClosed() 2018-09-08 08:48:47 +02:00
336905fafe clear() not longer frees memory it just empties the list
Use case: The list is used as a buffer, that is re-used and in
each iteration the list is cleared.

Now that clear() does not replace the data array there is no
garbage collection and we do not have to allocated one or
several new arrays in the next iteration.
You can still free the associated memory by calling clear() + trim().
2018-08-17 19:38:30 +02:00
19886eff89 update to Junit 5 2018-08-17 18:44:38 +02:00
fa0c7136a4 add LongList
It is an exact copy of IntList.
2018-01-24 19:15:19 +01:00
bd6c595856 extract inline definitions of generators, add loop for different sizes 2018-01-22 18:51:40 +01:00
bfbddf3fb1 cleanup
- Remove TODO in unionUnsorted, because I don't think there is a much
  better solution.
- Remove TODO for lastIndexOf, because it has been implemented.
- Use local variables for size in unionSorted.
2018-01-22 18:50:53 +01:00
7edd2adad8 cleanup
remove obsolete jmh test
2018-01-22 18:23:18 +01:00
7de2ac1fd3 add test for hashcode/equals with sorted and unsorted lists 2018-01-22 18:22:14 +01:00
8ee6118854 make unionUnsorted 5-10% faster for lists with 100k elements 2018-01-21 19:55:25 +01:00
5515523100 add simple benchmarking helper 2018-01-21 19:53:15 +01:00
ec32e3f566 unsorted lists can become sorted after removal
The old code only set the list to sorted when the lists size was <= 1
after the removal.
2017-12-20 18:59:24 +01:00
c73d43c214 replace removeAll/retainAll implementation with one a removeIf based
The algorithms for removeAll, retainAll and removeIf were almost
identical. The main difference was, that removeIf calls a lambda,
whereas removeAll and retainAll executed the check directly. Both
methods call indexOf on an IntList, which easily outweighs the extra
cost of the lambda.
It makes sense to consolidate and remove the duplicated code.

I ran a few benchmarks with different list sizes before the replacement.
The results are not as clear as I would have liked. In some cases,
especially for short lists, the special implementations of
removeAll/retainAll were up to 10% faster. In other situations I saw
50% difference the one day, but could not reproduce those results a 
day later. This leads me to believe, that my test setup is not
trustworthy.
That means I stay with what I now. The code is identical with one tiny
difference. And that difference shouldn't matter, because indexOf is 
much more expensive.
2017-12-20 18:45:42 +01:00
1681183474 add JMH
Add benchmark for a comparison of the custom made removeAll
method vs an implementation that uses removeIf
2017-12-20 17:51:15 +01:00
45dd73d8f3 update isSorted after shuffling
A list can be sorted after shuffling. The trivial cases are
the empty list and a list with only one element or lists 
with only identical elements. Lists with only a few elements 
have a non-negligible chance to be sorted after shuffling.
2017-12-18 20:10:27 +01:00
297ab6fd40 only trim if size != capacity 2017-12-18 19:50:45 +01:00
5006581cf0 allocate only as much as is needed
ensureCapacity would allocate up to 50% too much memory
2017-12-16 14:49:20 +01:00
f3cbdda121 early exit it toString was only used if data array was empty 2017-12-16 14:34:36 +01:00
25650b9638 add lastIndexOf 2017-12-13 20:39:54 +01:00
76e5dc403c add union(IntList,IntList) and addAll(IntList)
IntPredicate gets the current value and the index.
This was handy while removing duplicate values.
2017-12-12 18:45:11 +01:00
3dd1955749 indexOf on sorted lists should return the first match 2017-12-09 15:50:55 +01:00
14181822c9 add intersection for unsorted lists
Changed the way the intersection is computed. An intersection does
not return duplicate values. So the result is like a set.
2017-12-09 15:40:22 +01:00
b56f1e6688 use sorted flag in hashcode/equals 2017-12-08 18:35:49 +01:00
29d4e49298 add shuffle method 2017-12-08 18:27:55 +01:00
c41e52f8b3 add static intersection method for sorted lists 2017-12-03 09:59:58 +01:00
ba51b62a53 use Arrays.copy or Arrays.copyOfRange where applicable
Arrays.copy is easier to use than System.arrayCopy.
2017-12-03 09:26:52 +01:00
ef5d7817b2 add clear() method 2017-12-03 09:19:13 +01:00
b7ef9d2e6f apidoc: indexOf uses binary search if list is sorted 2017-12-03 09:13:02 +01:00
63c7740fd6 rename field 'index' to 'size'
The field 'index' describes two things:
1. the index the next element will be added to
2. the size of the list

Most methods use the second meaning.
2017-12-03 09:10:03 +01:00
477820050b use 'sorted' flag in indexOf 2017-12-03 09:04:17 +01:00
c7cacf1ad4 add 'sorted' flag that keeps track whether the list is sorted
The flag can be used in indexOf or for a better retainAll
implementation.
2017-12-02 20:24:32 +01:00
7f3d4872ae add API doc for NullPointerExceptions 2017-11-27 20:20:42 +01:00
994ce6842a documentation states that remove* methods do not release any memory 2017-11-27 20:04:39 +01:00
ecf1a62c95 do not copy array twice when inserting 2017-11-10 10:42:47 +01:00
88e0179dd5 add method removeIf 2017-11-10 10:35:51 +01:00
a59db6cfe8 add method retainAll 2017-11-10 10:03:10 +01:00
81e1d1f131 add method removeAll 2017-11-09 14:32:15 +01:00
db6ca1387d add replaceAll 2017-11-09 09:33:19 +01:00
6df2553fae add indexOf(value) and indexOf(value, offset) 2017-10-13 17:02:01 +02:00
cbe468cae8 add toArray(int[]) 2017-10-07 10:01:38 +02:00
56779368b8 make class final
We haven't designed the class for extension.
2017-09-29 18:59:02 +02:00
e7d88babb4 add stream() and parallelStream()
Both methods return an IntStream.
2017-09-29 18:57:43 +02:00
fc1ca26d52 use fromIndex and toIndex for remove instead of from and length
The new API is consistent with the internal API of ArrayList.
2017-09-29 18:12:58 +02:00
5112fcdfa0 do not create empty array in clone 2017-09-29 17:46:00 +02:00
235565bfe4 make IntList cloneable 2017-09-28 20:25:56 +02:00
a178086dfa make IntList serializable 2017-09-28 19:02:43 +02:00
4a762f39b9 add special implementation for add
The special implementation does not need to allocate an array for the
varargs of addAll
2017-09-28 18:22:16 +02:00
4da0726185 added todos with features that could be added 2017-09-26 20:22:52 +02:00
d00ab6533d use a static final empty array if list is empty 2017-09-26 20:10:54 +02:00
ab7d554d52 grow the array only by 50%
The old implementation grew the array by 100% with each resize.
The new implementation reduces the memory usage for, especially
for large lists.
The new algorithm is overflow-concious.
2017-09-26 19:59:50 +02:00
f7870a15a7 add sort (ascending) method 2017-02-05 14:18:47 +01:00