Skip to content
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

RingBuffer:189行calSlotIndex方法,为什么代码实际使用&运算而不是注释中的%取模? #40

Closed
chenqiandeveloper opened this issue Aug 16, 2019 · 0 comments

Comments

@chenqiandeveloper
Copy link

chenqiandeveloper commented Aug 16, 2019

作者你好!最近在下正在试图阅读理解源码,对calSlotIndex的计算方式有些疑惑:
/**
* Calculate slot index with the slot sequence (sequence % bufferSize)
*/
protected int calSlotIndex(long sequence) {
return (int) (sequence & indexMask);
}
如此计算出的nextIndex将是不序列递增且极易连续重复的,怎么能用于slots[nextIndex]取uid呢?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant