有谁知道优秀的教程甚至一本精通比特级操作的书?我的意思是几乎每个操作都可以做什么(例如在Java中)或在哪里可以找到正确的文档,但是我对这个话题还很陌生,我想知道事情是怎样的:
// Find a power of 2 >= initialCapacity
int capacity = 1;
while (capacity < initialCapacity)
capacity <<= 1;
工作(从
HashMap
复制)。我无法想象位运算如何影响整数,长整型或任何数据类型:-(我的意思是我不想了解每种操作,就像所提供的示例一样,对于Java或Scala的高级程序员来说,这似乎是最基本的。
另一个示例是:
/**
* Applies a supplemental hash function to a given hashCode, which
* defends against poor quality hash functions. This is critical
* because HashMap uses power-of-two length hash tables, that
* otherwise encounter collisions for hashCodes that do not differ
* in lower bits. Note: Null keys always map to hash 0, thus index 0.
*/
static int hash(int h) {
// This function ensures that hashCodes that differ only by
// constant multiples at each bit position have a bounded
// number of collisions (approximately 8 at default load factor).
h ^= (h >>> 20) ^ (h >>> 12);
return h ^ (h >>> 7) ^ (h >>> 4);
}
那似乎是不可思议的:(
最佳答案
要了解基础知识,您需要了解如何表示数据。这需要理解二进制文件,通常是two's complement。
了解基本知识后,可以在ubiquitous Stanford source上找到许多有用的技巧。