Commit Graph

80 Commits

Author SHA1 Message Date
062d63ca02 add maxCapacity to LongLongHashMap
This allows us to define an upper limit for the memory usage.
2021-04-16 17:52:15 +02:00
9de619d815 accidental linear access times instead of constant
Methods for finding keys in the map would iterate over all keys
when the key did not exist.
Fixed by introducing a new sentinel value (-1) that is used to
mark slots that were previously occupied.
2021-04-04 10:17:30 +02:00
f43cc2eda2 use static version numbers
This makes it easier to pull the artifacts from maven local.
2021-04-02 19:20:16 +02:00
6bd4b9b424 improve performance of LongList.union 2020-11-15 12:39:07 +01:00
54fbebf0b7 cleanup 2020-11-07 17:30:47 +01:00
c6d0182af7 generate random lists for benchmarks
turns out this changes the performance characteristics dramatically
2020-11-07 17:28:30 +01:00
50d2901b72 make local variables first when accessing fields multiple times 2020-11-07 13:13:38 +01:00
88f7abfc91 inline of array in LongQueue by creating a getting a reference to the
array of LongList
2020-11-07 08:45:51 +01:00
c9dcbdbe97 performance improvements
the heap refill code was recursively implemented with two methods.
I merged both methods.

replace recursion in heap refill method with iterative approach

use array for list of LongQueue
This way there is no precondition when accessing the elements
2020-11-07 08:36:07 +01:00
a427df09aa changed the value of UNSET from Long.MIN_VALUE to LONG.MAX_VALUE
That made the code in fillWithMinOfChildren() easier. We lost an early
out, though. But that should be negligible.
2020-11-06 19:41:48 +01:00
8a5309fbe8 multiway merge of multiple sorted lists 2020-11-06 19:22:45 +01:00
5b5e948293 update dependencies 2020-11-05 17:55:55 +01:00
d76551db2c update 3rd party libs 2019-12-27 12:14:09 +01:00
c6f5a3d2fe add Sparse2DLongArray 2019-12-26 15:44:58 +01:00
ec7a03f068 LongLongHashMap.get should no longer throw NoSuchElementException
In many use cases it is more efficient to have a getter that returns
a default value instead of throwing an exception. The exception forces
every consumer to call containsKey() before calling get(). In cases
where the consumer wants to use a default value this is unnecessary.
2019-12-22 19:14:41 +01:00
6421b82ce1 remove benchmark harness
we are using JMH instead
2019-09-07 17:52:14 +02:00
9f60c59aca add JMH tests for union of long list and uniq of lon/int list 2019-09-07 17:49:53 +02:00
452ef2020d fix LongLongHashMap.forEachOrdered for negative values 2019-09-07 16:51:30 +02:00
4d92197423 fix stackoverflow in Int/LongList.intersectionUnsorted 2019-09-07 16:50:40 +02:00
86f12e0af6 Add hash map for long to long mappings. 2019-09-07 14:36:51 +02:00
097b7ab110 add more JMH tests 2019-09-01 15:47:10 +02:00
0311ecd83c recover deleted JMH tests
update gradle and other third-party libs
2019-08-22 19:57:27 +02:00
506fb7b698 add new method 'uniq()' 2019-08-22 19:21:24 +02:00
ed703db277 speed improvement for intersectionSorted()
Using the unsafe versions of add/get to improve performance.

Here are some numbers for 2^15 intersections of two random
sorted lists with 16k elements. The numbers were gathered with
perf stat -d -d -d --delay 2000 java -ea -cp bin/test:bin/main
org.lucares.collections.Test 16000 15 (the test class is not committed)

Duration: 9059ms -> 7293ms (80.5%)
Cycles: 26.084.812.051 -> 21.616.608.207 (82.9%)
Instructions: 68.045.848.666 -> 52.306.000.150 (76.9%)
Instructions per Cycle: 2,61 -> 2.42
Branches: 15.007.093.940 -> 9.839.481.658 (65.6%)
Branch Misses: 2.285.461 -> 1.551.906
Cycles per element: 24.87 -> 20.61 (82.9%)
2019-04-28 12:48:17 +02:00
cedccefe92 20% speedup of unionSorted()
Added getUnsafe and addUnsafe, two methods that skip checks.
The checks are not needed in unionSorted, because we made
sure the code works correctly. getUnsafe still has the checks,
but as assertions.

The speedup is roughly 20%. Here are some results for calling
union 2^16 times for two random sorted lists with 16k
elements:
Duration: 20170 -> 16857 (83.57%)
Instructions: 138.277.743.679 -> 108.474.027.213 (78.4%)
Instructions per cycle: 2,33 -> 2,18
Branches: 30.248.330.644 -> 19.908.207.057 (65.8%)
Branch Misses: 3.012.427 -> 3.477.433
Cycles per list element: 65.93 -> 51.72 (78.4%)

Created with (the test program is not committed) on a Core2Duo 8600:
perf stat -d -d -d --delay 2000 java -cp bin/test:bin/main
org.lucares.collections.Test 16000 16
2019-04-28 11:05:13 +02:00
b31f756500 addAll for a collection of LongLists
The benefit is, that we only need one memory allocation.
2019-02-17 09:11:09 +01:00
ee04f21f29 removeAll is now O(n+m) if both lists are sorted 2018-11-20 19:53:33 +01:00
fef9af51cd add different versions of IntList.insert and LongList.insert
The new methods are more flexible, so that you can insert
parts of an array.
2018-09-23 15:28:37 +02:00
b99021d0f7 extract duplicate code that checks if the list is sorted 2018-09-13 20:02:54 +02:00
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