Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Feature request: into_group_btreemap #520

Open
HollayHorvath opened this issue Jan 25, 2021 · 8 comments
Open

Feature request: into_group_btreemap #520

HollayHorvath opened this issue Jan 25, 2021 · 8 comments
Labels
generic-container Generic vector/hasher/map

Comments

@HollayHorvath
Copy link

A BTreeMap version of the into_group* function group would be a nice addition.

The idea is that sometimes working with Hash is not feasible or even impossible, e.g. when you have to work with float-based datatypes as key or you would like to group your data by some custom criteria without wrapping the type and implementing custom Hash.

The into_group_btreemap() and into_group_btreemap_by() functions should work similarly how into_group_map() and into_group_btreemap_by() work, but would require K: Ord + Eq instead of K: Hash + Eq and would return BTreeMap<K, Vec<V>> instead of HashMap<K, Vec<V>>.

I have the code patched into my codebase, so I can also start a PR is this feature is required.

@phimuemue
Copy link
Member

phimuemue commented Jan 25, 2021

Hi, nice idea. It appears there is a certain need for this, as the request for other containers comes up (in different flavors) from time to time:

I'd like to put on the record (see #462 (comment)) that imho in an ideal world we would solve this problem by abstracting over the kind of the container -- leading to uniform support for HashMaps, BTreeMaps, sorted Vecs, EnumMap<Enum, Option<_>>, and possibly more, instead of having sporadic support for some of them.

It might not be easily doable, but I am unsure if duplicating functions here and there is better than exploring the possibilities of the aforementioned abstraction.

@Philippe-Cholet Philippe-Cholet added the generic-container Generic vector/hasher/map label Jan 25, 2024
@loarca
Copy link

loarca commented Feb 9, 2024

Hey 👋🏻

Any updates on this?

@Philippe-Cholet
Copy link
Member

I did not see any update related to it. The only recent thing is me adding the label "generic-container".
Personally, I tried some approaches to have more generic containers but nothing satisfying yet (by far).

@Kinrany
Copy link

Kinrany commented Oct 8, 2024

While duplicating methods isn't great, they could later be changed to aliases of the generic method. Having a second implementation should also serve as a good example use case for actually writing the generic.

Are there other containers that would benefit from the same? indexmap::IndexMap?

@barower
Copy link

barower commented Oct 16, 2024

I've just found myself looking for this, would be a nice addition

@ks
Copy link

ks commented Nov 19, 2024

This is sorely missing feature. Default rust HashMap is rarely what's wanted as a result due to slow default hash function...

@phimuemue
Copy link
Member

@Philippe-Cholet Should we, as a first step, tackle this by offering _with_hasher alternatives? And if so, should we just label the issue "help wanted"?

@jswrenn
Copy link
Member

jswrenn commented Nov 19, 2024

@phimuemue I think that's a great idea. I've created a tracking issue: #998

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
generic-container Generic vector/hasher/map
Projects
None yet
Development

No branches or pull requests

8 participants