-
-
Notifications
You must be signed in to change notification settings - Fork 639
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
use a Vector as accumulator of map.traverse (#1633) #1671
use a Vector as accumulator of map.traverse (#1633) #1671
Conversation
Could you make measurements with another implementation of |
Current coverage is 96.45% (diff: 100%)@@ master #1671 diff @@
==========================================
Files 89 89
Lines 11187 11187
Methods 0 0
Messages 0 0
Branches 1881 1881
==========================================
Hits 10790 10790
Misses 243 243
Partials 154 154
|
@ruslansennov you are right it is interesting to also look at these results. With a list and the following traversal I get similar results:
So which way would you recommend @ruslansennov @danieldietrich |
Hi @mduesterhoeft, thank you for the fast impl! If you have room (and appetite) for more, than you could take a look at #1600. Hi @ruslansennov, that's right, List has a smaller mem footprint. In the end it is the decision what should be the default Seq impl for Javaslang - a LinearSeq or an IndexedSeq. Alvin Alexander, the author of Scala Cookbook suggests to use Vector as default Seq (in Scala). We should apply that suggestion to Javaslang. Vector is general purpose. As this 'bug' shows, the time complexity highly depends on the type of the collection. We reduced the complexity from n^2 to n by just switching to Vector. Having a reliable time complexity is more important that saving bytes. I will pull this one now, many thanks! |
@danieldietrich thanks for the suggestion and the help - I would like look at something more complex. So I am definitely eager to help with #1600 |
@danieldietrich this code has complexity O(n) List<U> result = foldLeft(List.empty(), (acc, entry) -> acc.prepend(mapper.apply(entry._1, entry._2)));
return result.reverse(); And @mduesterhoeft shows similar results. But OK |
@ruslansennov yes, that's right. For the user it is better if the returned Seq is eff. O(1) for operations like append. Therefor we should choose Vector as default general purpose impl for Seq return types. (Nevertheless this is no dogma, we have to decide it from case to case.) |
fixes #1633
was it really that easy or did I overlook something?!
The measurement looks a lot better now: