-
Notifications
You must be signed in to change notification settings - Fork 21
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
optimize Vector concatenation (Vector ++ Vector) #4442
Comments
Imported From: https://issues.scala-lang.org/browse/SI-4442?orig=1 |
@TiarkRompf said: |
@SethTisue said: |
@TiarkRompf said (edited on Mar 2, 2012 9:10:30 PM UTC): Still need to resolve integration with the current Vector implementation. Maybe it's better to have a separate CatenableVector as a first step. |
@pchiusano said: |
@SethTisue said: |
@adriaanm said: |
@Ichoran said: |
@SethTisue said: |
@Blaisorblade said: https://github.com/nicolasstucki/scala-rrb-vector |
These are very relevant! |
Is this addressed by any chance in the new collections in 2.13? 🙂 |
@V-Lamp the Vectors in 2.13 will not be the new data structure (RRB Vectors), but their concatenation may be improved enormously by scala/scala#7588 which ensures that during concatenation of vectors, the structure of the left Vector is used rather than copying it into a new Vector. This essentially means that Vector concatenation will be constant-time on the size of the left vector (but still O(n) where n = size of right vector). |
scala/scala#7588 was reverted due to #11636 but the new Vector implementation that I am working on for 2.14 also has this optimization (appending n elements to a Vector of size m is O(n + log(m+n))). I don't know if I'll find the time to implement it but the same is possible for prepending. The combination of the two would allow concatenation depending on the size of the shorter slice. |
Note that Has anyone studied what the current situation is w/r/t to this ticket? |
I see that on scala/scala#8534 @szeiger wrote,
So that sounds like we're still where we before: doing concatenation as efficiently as possible remains future work. |
For the record: I've implemented concatenation in O(min(n, m) + log(n+m)) time. |
currently scala.collection.immutable.Vector.++ simply inherits its implementation from a supertrait (through the stubs added in r24227), so if you concatenate two vectors, it doesn't take advantage that that both are the same structure, but just treats the second vector like any traversable.
in theory this could be O(log n), not O(n), yes? Tiark seems to confirm it in this comment on #3724: "Unfortunately, for implementing a fast concat operation (we hope to do that for 2.8.1 or 2.9) heterogenous Arrays seem to be necessary (we'll be storing Int arrays next to the sub nodes). We might rethink this however, and try to stick to homogeneous Arrays."
I just thought there should be enhancement ticket on this as it would still be nice to have someday.
The text was updated successfully, but these errors were encountered: