Skip to content
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

Collections should override spliterator() #2029

Closed
cowwoc opened this issue Apr 11, 2015 · 6 comments
Closed

Collections should override spliterator() #2029

cowwoc opened this issue Apr 11, 2015 · 6 comments
Labels
package=collect type=enhancement Make an existing feature better

Comments

@cowwoc
Copy link

cowwoc commented Apr 11, 2015

Because Guava's collection classes (e.g. ImmutableList) do not override spliterator() they inherit the default implementation which has a characteristics of SIZED and SUBSIZED. This means that they cannot be used for parallel processing with ForkJoin.

Expected behavior: Immutable* should provide a more efficient spliterator() implementation.

@lowasser
Copy link
Contributor

This will absolutely be part of Guava as soon as we support Java 8, but I'm not sure there is much we can do until then?

@cowwoc
Copy link
Author

cowwoc commented Apr 11, 2015

I found posts going back 1-2 years talking about adding Java8 support in the near future: http://www.reddit.com/r/java/comments/1y9e6t/ama_were_the_google_team_behind_guava_dagger/cfjd2qi and https://groups.google.com/forum/#!topic/guava-discuss/fEdrMyNa8tA

Is there an open issue tracking this work?

Is there a short-term workaround I can use in the meantime?

@lowasser
Copy link
Contributor

I don't think so - the primary issue is Google internal?

As it stands, for essentially all immutable collections, a good implementation is

IntStream.range(0, collection.size()).mapToObj(collection.asList()::get)

@cowwoc
Copy link
Author

cowwoc commented Apr 11, 2015

The primary issue is Google internal?

I don't understand the question.

As it stands, for essentially all immutable collections, a good implementation is

IntStream.range(0, collection.size()).mapToObj(collection.asList()::get)

This won't do because spliterator().characteristics() will return ORDERED | SIZED | SUBSIZED. It is missing IMMUTABLE.

@lowasser
Copy link
Contributor

The Google internal Comment was a statement, not a question.

I'm not certain the IMMUTABLE characteristic is actually used for anything? That should still be an adequate substitute for most use cases I can think of...

@cowwoc
Copy link
Author

cowwoc commented Apr 11, 2015

The Google internal Comment was a statement, not a question.

It had a question mark after it... :)

I'm not certain the IMMUTABLE characteristic is actually used for anything?

Agreed. I thought that this was being used for parallelization but it looks like it is not. So for now I don't have a concrete use-case for this characteristic.

That should still be an adequate substitute for most use cases I can think of...

Okay, but it is worth noting that the only characteristic it adds over the default is ORDERED. That said, it is useful for clients that wishs to jump to the end of a list: http://stackoverflow.com/a/29553490/14731.

@cgdecker cgdecker added type=enhancement Make an existing feature better package=collect labels May 20, 2015
cgdecker added a commit that referenced this issue Nov 3, 2016
(Note: This will break the public Guava GWT tests. We'll come back to fix them.)

Fixes #2585, #2479, #2029, and probably various other issues :)

Also relevant: #2591

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=138100073
@cpovirk cpovirk closed this as completed Nov 3, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
package=collect type=enhancement Make an existing feature better
Projects
None yet
Development

No branches or pull requests

4 participants