`simple-collections` crate proposal

#1

I happen to need to use some kind of Set or Map to store just a few elements/key-value pairs. Moreover, the keys are basically simple numbers, or analogously simple types.

I did that by using HashSets and HashMaps but I suspect I am incurring in a lot of memory/cpu overhead (because I need many such small sets), and generally over-complicating something very simple. I would probably be fine just using a Vec and its various remove and find methods. Though, this is wrong in principle: I need a set, not a stack (for example, I don’t want repetitions). What could be done is providing a simple wrapper around Vec to turn it into a set or map.

Would it be a good idea to have a crate providing Vec-based SimpleSet and SimpleMap as described above? Is there already such a crate?

0 Likes

#2

I think https://crates.io/crates/linear-map provides what you describe.

2 Likes

#3

Aha, thanks, that’s exactly what I had in mind!

It doesn’t seem to be a hugely popular crate, despite providing something apparently very useful. Are there unexpected cons or side-effects to it?

0 Likes

#4

I just guess that for most people, using HashMap for everything they do is just good enough. You start thinking about how to replace it only after you find out it eats too much resources and most of the uses are probably in performance-insensitive places or it just contains enough elements to be actually better.

So, most people just have something that does the job in std… no reason to go looking for another crate ‒ therefore the other crate is not that popular.

3 Likes