int hash( const string & key, int tableszie )
int hash( const string & key, int tablesize )
/** * a hash routine for string objects.
*/int hash( const string & key, int tablesize )
; int hash( const string & key );
int hash( int key );
/*雜湊表的myhash成員函式*/
int myhash( const hashedobj & x ) const
/* fig5-8 可以作為hashedobj 使用的類的乙個例子*/
// example of an employee class
class employee
bool operator==( const employee & rhs ) const
bool operator != ( const employee & rhs ) const
//additional pulic members not shown
pribate:
string name;
double salary;
int seniority;
//additional private members not shown
};int hash( const employee & item )
/*fig5-9 分離鏈結雜湊表的makeempty、contains、remove 例程*/
void makeempty()
bool contains( const hashedobj & x ) const
bool remove( const hashedobj & x )
/*fig5-10 分離鏈結雜湊表的insert例程*/
bool insert( const hashedobj & x )
/*fig 5-14 使用探測策略的雜湊表的類介面,包括巢狀的hashentry類*/
class hashtable
};vectorarray;
int currentsize;
bool isactive( int currentpos ) const;
int findpos( const hashedobj & x ) const;
void rehash();
int myhash( const hashedobj & x ) const;
};/*fig5-15 初始化平方探測雜湊表的例程*/
explicit hashtable( int size = 101 ) :array( nextprime( size ))
void makeempty()
/*fig 5-16 使用平方探測進行雜湊的contains例程(和它的private助手)*/
bool contains( const hashedobj & x ) const
int findpos( const hashedobj & x ) const
return currentpos;
}bool isactive( int currentpos ) const
/* 使用平方探測的雜湊表的insert和remove例程*/
bool insert( const hashedobj & x )
bool remove( const hashedobj & x )
資料結構之雜湊
題目1 實現乙個簡單的雜湊結構 使用youlookdeliciousc的做法,即用拉鍊表來實現。技巧是vector來做為容器 struct node int len 1000 class myhashmap void put int key,int value pre cur cur cur nex...
資料結構之雜湊表
雜湊表和雜湊化有乙個重要的概念是如何把關鍵字轉換成陣列下標,在雜湊表中這個轉換是通過雜湊函式來完成的。比如規定乙個單詞含有4個字元,對於單詞cats,我們採用 冪的連乘 的方式將乙個單詞對映成數字。因為有27個可能的字元,包括空格,所以冪採用27,則cats的數字下標是3 27 3 1 27 2 2...
資料結構之雜湊表
wikipedia上的解釋 下圖示意了雜湊表 hash table 這種資料結構。雜湊表 如上圖所示,首先分配乙個指標陣列,陣列的每個元素是乙個鍊錶的頭指標,每個鍊錶稱為乙個槽 slot 哪個資料應該放入哪個槽中由雜湊函式決定,在這個例子中我們簡單地選取雜湊函式h x x 11,這樣任意資料x都可以...