Hacker News new | past | comments | ask | show | jobs | submit login

The Bag. Also known as a Multiset. I can't believe it took me so many years to learn the name of the most basic data structure imaginable - it basically makes no promises whatsoever about the structure. Think of it like a Set that allows duplicates - you can put stuff in and take stuff out, just like a bag - what more could you want?



I love the Bag! It's so simple I use it constantly


How is that any different from a list?


Two lists are equal only if they have the same contents and in the same order. Bags don’t have an order, they’re more like sets, so bags are equal so long as they have the same contents.


Hopefully this java can illustrate the point if you're not a Java lover

The bag essentially works like this Map<K, Collection<V>>

But looks like this Bag<K, V>

I use my own simple "BagSet" which works like this Map<K, Set<V>>




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: