-
Notifications
You must be signed in to change notification settings - Fork 8
Description
Hello :)
I needed a set implementation for a Discrete Event Simulation and this is an amazing library, thank you for your work :)
In the process I've detected an improvement to the actionUpdate functions, specifically symmetricDifferenceUpdate, intersectionUpdate and differenceUpdate. All of those functions allocate memory for a copy of a given set due to the inability to modify the an element of the set while iterating over it. I rewrote the three functions changing the strategy:
differenceUpdate: Instead of iterating over the original set, by iterating over theotheryou can remove from the original, which eliminates the duplication completely, allowing to not use an allocator!intersectionUpdate: Here the allocator cannot be removed but it can be done slightly more efficient. By using anArrayListwith the elements to remove (not in the intersection) you minimize the memory footprint. Then, you iterate over the arraylist to remove them from the original set, once you've finished iterating over it.symmetricDifferenceUpdate: Same idea fromdifferenceUpdate, iterating over the other set allows to modify the original.
I've tested the implementation performance wise with two sets
Original:
Difference (ms) : 11.0510 +/- 0.037741 (95% CI)
Sym Difference (ms) : 12.2240 +/- 0.045730 (95% CI)
Intersection (ms) : 9.1530 +/- 0.037801 (95% CI)
New
Difference (ms) : 1.0090 +/- 0.005856 (95% CI)
Sym Difference (ms) : 1.0750 +/- 0.017906 (95% CI)
Intersection (ms) : 6.1710 +/- 0.030364 (95% CI)
I would gladly open a pull request to contribute the changes or show the benchmarking code. I forked the repo and changed some things, but I can port this changes to keep them in order :) have a nice day!