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

Implement Insertion Ordered Set implementing MutableSet API. #339

Open
donraab opened this issue Sep 2, 2017 · 8 comments
Open

Implement Insertion Ordered Set implementing MutableSet API. #339

donraab opened this issue Sep 2, 2017 · 8 comments

Comments

@donraab
Copy link
Contributor

donraab commented Sep 2, 2017

Today a LinkedHashSet can be used by wrapping a JDK LinkedHashSet with a SetAdapter as follows.

Sets.adapt(new LinkedHashSet());

This works fine for most cases but it would be nicer if we provided an Ordered Set implementation that returned more specific values out of certain methods.

@oehme
Copy link
Member

oehme commented Dec 9, 2017

I think the title should be "implement insertion ordered set". Using a linked structure is the reason for the huge memory overhead of LinkedHashSet. Using a long[] to maintain the iteration order would be much more efficient. But maybe I'm missing a different reason why a linked structure might be useful?

@donraab donraab changed the title Implement LinkedHashSet implementing MutableSet API. Implement Insertion Ordered Set implementing MutableSet API. Dec 9, 2017
@donraab
Copy link
Contributor Author

donraab commented Dec 9, 2017

Makes sense. Updated. I'll leave implementation detail up to the developer who contributes.

@motlin
Copy link
Contributor

motlin commented Dec 11, 2017 via email

@oehme
Copy link
Member

oehme commented Dec 11, 2017

I corrected my comment above - I meant keeping the links in a long[], storing the previous pointer in the lower half and the next pointer in the upper half of each long and indexing it with the same indexes as the main table. That gives you a compact link representation and constant time removals.

@arvidvillen
Copy link

Any updates in this?
Surely ImmutableOrderedSet would be one of the most used collections in a regular project as the ordering should/could be done in DB query.

@nikhilnanivadekar
Copy link
Contributor

@arvidvillen what updates would you like? If you need this functionality, please feel free to contribute.

@mohrezaei
Copy link
Member

@arvidvillen The most used collection for representing results coming from a database is a simple list. It's naturally ordered, random access and has a superior interface compared to a set.

@arvidvillen
Copy link

arvidvillen commented Sep 12, 2022

Thanks for super fast replies.
Interesting, I guess I'm not really thinking of it from a performance point of view, but rather the semantic meaning (what the interface tells the user about the collection). ImmutableOrderedSet would tell me more as a consumer of an API than ImmutableSet or ImmutableList.

But I understand not many people see it that way as there are very few collection libraries that support OrderedSet or UniqueList.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants