Give me a practical use-case of Multi-set

后端 未结 4 1696
庸人自扰
庸人自扰 2020-12-16 14:38

I would like to know a few practical use-cases (if they are not related/tied to any programming language it will be better).I can associate Sets, Lists and Maps to practical

相关标签:
4条回答
  • 2020-12-16 15:01

    A multiset is useful in many situations in which you'd otherwise have a Map. Here are three examples.

    Suppose you have a class Foo with an accessor getType(), and you want to know, for a collection of Foo instances, how many have each type.

    Similarly, a system could perform various actions, and you could use a Multiset to keep track of how many times each action occurred.

    Finally, to determine whether two collections contain the same elements, ignoring order but paying attention to how often instances are repeated, simply call

    HashMultiset.create(collection1).equals(HashMultiset.create(collection2))
    
    0 讨论(0)
  • 2020-12-16 15:01

    A Shopping Cart is a MultiSet. You can put several instances of the same item in a Shopping Cart when you want to buy more than one.

    0 讨论(0)
  • 2020-12-16 15:07

    Lots of applications. For example, imagine a shopping cart. That can contain more than one instance of an item - i.e. 2 cpu's, 3 graphics boards, etc. So it is a Multi-set. One simple implementation is to also keep track of the number of items of each - i.e. keep around the info 2 cpu's, 3 graphics boards, etc.

    I'm sure you can think of lots of other applications.

    0 讨论(0)
  • 2020-12-16 15:17

    In some fields of Math, a set is treated as a multiset for all purposes. For example, in Linear Algebra, a set of vectors is teated as a multiset when testing for linear dependancy. Thus, implementations of these fields should benefit from the usage of multisets.

    You may say linear algebra isn't practical, but that is a whole different debate...

    0 讨论(0)
提交回复
热议问题