क्या कोई मुझे स्थिर हैश मैप # हैश (int) विधि समझा सकता है?हैश मैप # हैश (int) विधि का स्पष्टीकरण
समान रूप से वितरित हैंश उत्पन्न करने के लिए इसके पीछे क्या औचित्य है?
/**
* 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);
}
एक उदाहरण पचाने में आसान बना देगा।
स्पष्टीकरण मैं ऑपरेटरों, सत्य तालिकाओं और बिटवाईर संचालन से अवगत हूं। मैं वास्तव में कार्यान्वयन और वास्तव में टिप्पणी वास्तव में डीकोड नहीं कर सकता। या इसके पीछे भी तर्क।
जावा का कौन सा संस्करण आप उपयोग कर रहे हैं? मुझे कहीं भी कोई स्थिर हैश (int) विधियां नहीं मिल सकतीं – tom
क्षमा करें कि हैश मैप। – qnoid
मैंने दूसरों के लाभ के लिए, स्रोत से अधिक टिप्पणियां रखने के लिए मूल प्रश्न संपादित किया। – polygenelubricants