我正在读的书使用以下功能创建了一个哈希表size_t hash(const std::string &str) { int count = 16; size_t hash_value = 0; const char *cstr = str.c_str(); while(cstr && *cstr && --count) hash_value += (*cstr++ - 'a') << (count % 4); return hash_value;<<运算符在这种情况下做什么? 最佳答案 这有点移位。如果您用二进制将数字X表示为00001111,则X > 3将是00000001。实际上,X << n与X * 2^n相同(考虑到无符号类型的溢出)。 X >> n等效于X / 2^n。 ^是指力量。关于c++ - 哈希表创建,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/19041293/
10-11 19:08