hash table(用乘法散列法实现)
生活随笔
收集整理的這篇文章主要介紹了
hash table(用乘法散列法实现)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
hash table(用乘法散列法實現)
#ifndef C11LEARN_HASHMULTI_H #define C11LEARN_HASHMULTI_H #include "HashDivision.h" template<typename T> class HashMulti:public HashDivision<T> { private:long w;long p;long long s;long long two_32; public:HashMulti():HashDivision<T>(1<<14){s = 2654435769;w = 32;p = 14;two_32 = 1;two_32 = two_32<<32;}HashMulti(const HashMulti<T>& multi):HashDivision<T>(1<<14){s = 2654435769;w = 32;p = 14;two_32 = 1;two_32 = two_32<<32;HashDivision<T>::copy(multi);}protected:virtual int hashing(int key); }; template<typename T> int HashMulti<T>::hashing(int key){return ((key*s)%two_32)>>(w-p); } #endif //C11LEARN_HASHMULTI_H測試代碼
HashMulti<string> hashMulti;hashMulti[2] = "hello";hashMulti[123456] = "world";cout << hashMulti[2] << endl;cout << hashMulti[123456] << endl;輔助類
HashDivision鏈接地址
乘法哈希和除法哈希的不同點是哈希函數不同,
共同點都是用雙向鏈表解決沖突問題。
總結
以上是生活随笔為你收集整理的hash table(用乘法散列法实现)的全部內容,希望文章能夠幫你解決所遇到的問題。