In Java we have two nice classes: EnumSet for sets of enums and EnumMap for a map whose keys are enums. EnumSet is represented as a 64-bit word (or an array of 64-bit words) and EnumMap as an array of values, both indexed by the ordinal numbers of enums. So insert/lookup/remove/... operations take just O(1) time.
Do we have something like that in Scala - mutable or immutable?
I found BitSet (both mutable and immutable) which operates on integers, so I assumed there would be an efficient implementation of sets of Enumeration.Values backed up by it. But I found only Enumeration.ValueSet, which is backed up by SortedSet[Int]. While that's not so bad, BitSet seems to be quite more efficient for this purpose.
I didn't find any optimized implementation of maps with Enumeration.Value as keys similar to EnumMap.
Actually, in 2.10 Enumeration.ValueSet uses BitSet.
class ValueSet private[ValueSet] (private[this] var nnIds: immutable.BitSet)
That would be here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With