Personally, I don't quite understood why we have multisets at all. In principle, a multiset is the same thing as a mixed:int(0,...) mapping.
/ Niels Möller ()
Previous text:
2003-02-06 10:12: Subject: Xor
I have been wondering why the index operations on multisets work like they do:
| > multiset v=(<1,1,1>); | > v[1]; | Result: 1 | > v[1]=0; | Result: 0 | > v; | Result: (<1,1>)
This could of course be used to do a `- that removes one for one:
multiset res=copy_value(v); foreach (v;mixed elem;) res[elem]=0; // remove one
But why doesn't v[1] return 3 above, and remove all the elements with v[1]=0?
It would also be much more useful to do v[1]=17 to get 17 of element 1. You can't, however, even add elements using that method now:
| > v[1]=17; | Result: 17 | > v; | Result: (<1,1>) | > v[1]=1; | Result: 1 | > v; | Result: (<1,1>)
How much would break if we fixed this behaviour, so that
multiset v=(<1,1,1>); v[1] == 3 v[1]=0 => v==(<>) v[1]=17 => v==(<1,1,1,1...1,1>) /* 17 elements */
Sidenote: This code works for the above `- for both the current and my suggestion:
multiset res=copy_value(v); foreach (v;mixed elem;int n) res[elem]-=n; // remove n
/ Mirar