Open tysonzero opened 2 years ago
I am not sure about elemAt
and deleteAt
, since they would have linear complexity, which users probably wouldn't expect. At that point you should probably use a different data structure. Adding that bookkeeping to MultiSet is not worth the cost for other use-cases.
For weighted random sampling there are specific data structures that can give you a sample in O(1), although I don't know if there are Haskell implementations.
Data.Set
has:It would be nice to have similar functions for
MultiSet
:I'm mostly interested in
elemAt
for my purposes (usingMultiSet
as a bag to randomly take from).You could theoretically bring down all the complexities to
O(log n)
but it would require changing the internal structure.