# EnumSet

### EnumSet

EnumSet是JDK 1.5推出的，针对Enum类型的特殊的Set数据接口。这种数据结构只能由同一种类型的Enum类型进行创建。

Null元素不允许插入，它不是线程安全的。

EnumSet设计为抽象类，因此只能通过静态工厂来进行创建，整个创建过程EnumSet进行了进一步的封装

### RegularEnumSet

RegularEnumSet使用 -1L >>> -universe.length来进行位向量设置。

Shift Operators

If the promoted type of the left-hand operand is int, only the five lowest-order bits of the right-hand operand are used as the shift distance. It is as if the right-hand operand were subjected to a bitwise logical AND operator & with the mask value 0x1f (0b11111). The shift distance actually used is therefore always in the range 0 to 31, inclusive.
If the promoted type of the left-hand operand is long, then only the six lowest- order bits of the right-hand operand are used as the shift distance. It is as if the right-hand operand were subjected to a bitwise logical AND operator & with the mask value 0x3f (0b111111). The shift distance actually used is therefore always in the range 0 to 63, inclusive.

-1L >>> -n [1,64]，是一个常用技巧，生成长度为n的bit vectors.

### JumboEnumSet

(universe.length+64)>>>6 右移6位 = 除以2^6，即除以64，长度直接除64，显然不对，比如68/64=1，此时显然应该为2，因此，通过+63再进行该除法，从而确定了数组长度。

### Benchmark

enumset-benchmark

RegularEnumSet

• contains: 2.5%