Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are there any implementations of multiset for .Net?

I'm looking for a .Net implementation of a multiset. Can anyone recommend a good one?

(A multiset, or bag, is a set that can have duplicate values, and on which you can do set operations: intersection, difference, etc. A shopping cart for instance could be thought of as a multiset because you can have multiple occurrences of the same product.)

like image 981
dan-gph Avatar asked Apr 08 '10 05:04

dan-gph


People also ask

Where can I use multiset?

The multiset object uses this expression to determine both the order the elements follow in the container and whether two element keys are equivalent (by comparing them reflexively: they are equivalent if ! comp(a,b) && ! comp(b,a)). This can be a function pointer or a function object (see constructor for an example).

How is multiset implemented C++?

Multisets are part of the C++ STL (Standard Template Library). Multisets are the associative containers like Set that stores sorted values (the value is itself the key, of type T), but unlike Set which store only unique keys, multiset can have duplicate keys. By default it uses < operator to compare the keys.

Why do we need multiset?

If you have a structure where you don't need a key/value but you need the search properties of a set with multiple elements per key, you use a multiset.

Is multiset sorted in C++?

In case of Set, data is stored in sorted order. In case of MultiSet also the data is stored in sorted order. In Set duplicate values are not allowed to get stored.


1 Answers

I do not know about one, however you could use a Dictionary for that, in which the value is the quantity of the item. And when the item is added for the second time, you vould increase the value for it in the dictionary.

An other possibility would be to simply use a List of items, in which you could put duplicates. This might be a better approach for a shopping cart.

like image 86
treaschf Avatar answered Oct 10 '22 17:10

treaschf