Previous section To contents Next section

4.2.3 multiset

A multiset is almost the same thing as a mapping. The difference is that there are no values:


fig 4.3

Instead, the index operator will return 1 if the value was found in the multiset and 0 if it was not. When assigning an index to a multiset like this: mset[ ind ] = val the index ind will be added to the multiset mset if val is true. Otherwise ind will be removed from the multiset instead.

Writing a constant multiset is similar to writing an array:

(< >) // Empty multiset
(< 17 >) // Multiset with one index: 17
(< "", 1, 3.0, 1 >) // Multiset with 3 indices
Note that you can actually have more than one of the same index in a multiset. This is normally not used, but can be practical at times.


Previous section To contents Next section