-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add EnumArray #1314
Add EnumArray #1314
Conversation
Unit testing passed. |
class isPowerTwo { | ||
public: | ||
enum { | ||
ret = (n != 0) && !(n & (n - 1)), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this mean ret is true just when n=1,2,4,8,16... like 0x100000...0000?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ha, it just handles the unsigned integer.
auto bIdx = blockIndex(idx); | ||
auto offset = bitOffset(idx); | ||
uint64_t mask = v << offset; | ||
blocks_[bIdx] |= mask; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is need set 0 to blocks_[bIdx]? if call put with same idx but diffirent e, then maybe can not get correct e?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point! We need to handle it.
Unit testing passed. |
Co-authored-by: Sophie <84560950+Sophie-Xie@users.noreply.github.com> Co-authored-by: Lipeng Zhu <lipzhu@icloud.com> Co-authored-by: Sophie <84560950+Sophie-Xie@users.noreply.github.com>
It will save lots of space occupied when the Enum has only few values.