vavr-io / vavr

vʌvr (formerly called Javaslang) is a non-commercial, non-profit object-functional library that runs with Java 8+. It aims to reduce the lines of code and increase code quality.
https://vavr.io
Other
5.59k stars 620 forks source link

#2417 Explore reimplementing HashMap as CHAMP (Compressed Hash-Array Mapped Prefix-tree) #2745

Open wrandelshofer opened 1 year ago

wrandelshofer commented 1 year ago

This is a draft intended for discussion.

This merge requests explores how a migration of the HAMT trie to a CHAMP trie could look like:

The changes are somewhat sub-optimal and somewhat over-complicated, because I strived to not break any of the unit tests. (I believe that I should change a number of unit tests, because some rely on the iteration sequence of the HAMT implementation. However, the vavr API specifies that the iteration sequence is unspecified.)

The code is a port from the JHotDraw 8 collections module. https://github.com/wrandelshofer/jhotdraw8/tree/main/org.jhotdraw8.collection The JHotDraw 8 collections are in turn a port of the 'capsule' collection library https://github.com/usethesource/capsule, and of vavr.

I do not expect that this draft can be merged in the current form. In JHotDraw 8 we have a mutable 'partner' collection for every immutable collection. This allows to test all immutable collections with the 'guava-testlib' library. Which provides very through tests. I did not want to change the API of vavr - so I have downgraded the mutable collections to transient collections. But I have not written new tests yet. So code coverage by unit tests is currently lower than I want it to be.