本文整理汇总了C++中hashes类的典型用法代码示例。如果您正苦于以下问题:C++ hashes类的具体用法?C++ hashes怎么用?C++ hashes使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了hashes类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: findPrime
void SCHashTable<K,V>::resizeTable() {
typename list< pair<K,V> >::iterator it;
/**
* @todo Implement this function.
*
* Please read the note in the spec about list iterators!
* The size of the table should be the closest prime to size * 2.
*
* @hint Use findPrime()!
*/
size_t doubleSize = findPrime(size*2);
list<pair<K, V> > * temp = new list< pair<K,V> >[doubleSize];
for (size_t i = 0; i < size; i++)
{
for (it = table[i].begin(); it != table[i].end(); it++)
{
int id = hash(it->first, doubleSize);
pair<K,V> pear(it->first, it->second);
temp[id].push_back(pear);
}
}
delete [] table;
table = temp;
size = doubleSize;
}
开发者ID:itsabigaundy,项目名称:CS_225,代码行数:31,代码来源:schashtable.cpp
示例2: findPrime
void LPHashTable<K,V>::resizeTable() {
size_t newSize = findPrime( size * 2 );
pair<K,V> ** temp = new pair<K,V>*[newSize];
delete [] should_probe;
should_probe = new bool[newSize];
for( int i = 0; i < newSize; i++ ) {
temp[i] = NULL;
should_probe[i] = false;
}
for( int i = 0; i < size; i++ ) {
if( table[i] != NULL ) {
int idx = hash( table[i]->first, newSize );
while( temp[idx] != NULL )
idx = ( idx + 1 ) % newSize;
temp[idx] = table[i];
should_probe[idx] = true;
}
}
delete [] table;
// don't delete elements since we just moved their pointers around
table = temp;
size = newSize;
}
开发者ID:cwang100,项目名称:class-projects,代码行数:25,代码来源:lphashtable.cpp
示例3: findPrime
void SCHashTable<K,V>::resizeTable() {
typename list< pair<K,V> >::iterator it;
/**
* @todo Implement this function.
*
* Please read the note in the spec about list iterators!
* The size of the table should be the closest prime to size * 2.
*
* @hint Use findPrime()!
*/
size_t new_size = findPrime( 2*size );
std::list< std::pair<K, V> > * my_table = new list< pair<K,V> >[new_size];
for( int i = 0; i < size; i++)
{
for (it = table[i].begin(); it != table[i].end(); it++ )
{
int index = hash(it->first, new_size);
pair<K,V> p(it->first, it->second);
my_table[index].push_back(p);
}
}
delete [] table;
table = my_table;
size = new_size;
}
开发者ID:dwatring,项目名称:Data-Structures,代码行数:29,代码来源:schashtable.cpp
示例4: hash
void LPHashTable<K,V>::insert( K const & key, V const & value ) {
/**
* @todo Implement this function.
*
* @note Remember to resize the table when necessary (load factor >=
* 0.7). **Do this check *after* increasing elems!!** Also, don't
* forget to mark the cell for probing with should_probe!
*/
elems++;
if((double)elems/size>=0.7)
resizeTable(); //
int idx = hash(key, size);
while(should_probe[idx])
{
idx = (idx + 1) % size;
}
if (table[idx] == NULL)
{
table[idx] = new pair<K,V>(key, value);
should_probe[idx] = true;
}
}
开发者ID:karanghai,项目名称:cs225Labs,代码行数:31,代码来源:lphashtable.cpp
示例5: hash
void LPHashTable<K,V>::insert( K const & key, V const & value ) {
/**
* @todo Implement this function.
*
* @note Remember to resize the table when necessary (load factor >=
* 0.7). **Do this check *after* increasing elems!!** Also, don't
* forget to mark the cell for probing with should_probe!
*/
++elems;
if(shouldResize())
resizeTable();
if(findIndex(key) == -1){
int temp = hash(key,size);
if(table[temp] == NULL){
table[temp] = new std::pair<K,V>(key,value);
should_probe[temp] = true;
}else{
int i = temp + 1;
for( ; table[i%size] != table[temp]; i++){
if(table[i%size] == NULL){
table[i%size] = new std::pair<K,V>(key,value);
should_probe[i%size] = true;
return;
}
}
}
}
}
开发者ID:Arkhtyi,项目名称:Discrete-structures,代码行数:35,代码来源:lphashtable.cpp
示例6: hash
void SCHashTable<K,V>::resizeTable() {
typename list< pair<K,V> >::iterator it;
/**
* @todo Implement this function.
*
* Please read the note in the spec about list iterators!
* The size of the table should be the closest prime to size * 2.
*
* @hint Use findPrime()!
*/
int ret_value=findPrime(2*size);
std::list< std::pair<K, V> > * new_table = new list< pair<K,V> >[ret_value];
for(int i=0;i<size;i++)
{
for(it=table[i].begin();it!=table[i].end();it++)
{
int idx = hash( it->first, ret_value );
new_table[idx].push_front(*it);
}
}
delete [] table;
table=new_table;
size=ret_value;
}
开发者ID:guptadipanshu,项目名称:Data_structure,代码行数:27,代码来源:schashtable.cpp
示例7: hash
V & SCHashTable<K,V>::operator[]( K const & key ) {
size_t idx = hash( key, size );
typename list< pair<K,V> >::iterator it;
for( it = table[idx].begin(); it != table[idx].end(); it++ ) {
if( it->first == key )
return it->second;
}
++elems;
if( shouldResize() )
resizeTable();
idx = hash( key, size );
pair<K,V> p( key, V() );
table[idx].push_front( p );
return table[idx].front().second;
}
开发者ID:itsabigaundy,项目名称:CS_225,代码行数:17,代码来源:schashtable.cpp
示例8: resizeTable
void SCHashTable<K,V>::insert( K const & key, V const & value ) {
++elems;
if( shouldResize() )
resizeTable();
pair<K,V> p( key, value );
size_t idx = hash( key, size );
table[idx].push_front( p );
}
开发者ID:itsabigaundy,项目名称:CS_225,代码行数:8,代码来源:schashtable.cpp
示例9: V
V SCHashTable<K,V>::find( K const & key ) const {
size_t idx = hash( key, size );
typename list< pair<K,V> >::iterator it;
for( it = table[idx].begin(); it != table[idx].end(); it++ ) {
if( it->first == key )
return it->second;
}
return V();
}
开发者ID:itsabigaundy,项目名称:CS_225,代码行数:9,代码来源:schashtable.cpp
示例10: hash
void SCHashTable<K,V>::resizeTable() {
/**
* @todo Implement this function.
*
* Please read the note in the spec about list iterators!
* The size of the table should be the closest prime to size * 2.
*
* @hint Use findPrime()!
*/
list< pair<K, V> > * new_table = new list< pair<K, V> >[size*2];
for(int i=0;i<size;i++)
{
if(!table[i].empty())
{
typename list< pair<K,V> >::iterator it;
for(it = table[i].begin();it!=table[i].end();it++)
{
int idx = hash(it->first,size*2);
new_table[idx].push_back(*it);
}
}
}
delete []table;
table = new_table;
size = size*2;
elems = elems;
/*
typename list< pair<K,V> >::iterator it;
int newSize = findPrime( 2*size );
list<pair<K,V> > * newTable = new list<pair<K,V> > [newSize];
for (int idx=0;idx<size;idx++)
{
if (!table[idx].empty())
{
for( it = table[idx].begin(); it != table[idx].end(); it++ )
{
pair<K,V> p( it->first, it->second );
int i = hash( it->first, it->second );
newTable[i].push_front( p );
}
}
}
delete [] table;
table = newTable;
size = newSize;
*/
}
开发者ID:victorliking,项目名称:Data-Structure,代码行数:54,代码来源:schashtable.cpp
示例11: hash
int LPHashTable<K,V>::findIndex( const K & key ) const {
int idx = hash( key, size );
int start = idx;
while( should_probe[idx] ) {
if( table[idx] != NULL && table[idx]->first == key )
return idx;
idx = ( idx + 1 ) % size;
// if we've looped all the way around, the key has not been found
if( idx == start )
break;
}
return -1;
}
开发者ID:cwang100,项目名称:class-projects,代码行数:13,代码来源:lphashtable.cpp
示例12:
void SCHashTable<K,V>::remove( K const & key ) {
typename list< pair<K,V> >::iterator it;
/**
* @todo Implement this function.
*
* Please read the note in the lab spec about list iterators and the
* erase() function on std::list!
*/
int temp=hash(key, size);
for(it=table[temp].begin(); it!=table[temp].end(); it++){
if(it->first==key){
table[temp].erase(it);
elems--;
}
}
//(void) key; // prevent warnings... When you implement this function, remove this line.
}
开发者ID:itsabigaundy,项目名称:CS_225,代码行数:19,代码来源:schashtable.cpp
示例13: resizeTable
void LPHashTable<K,V>::insert( K const & key, V const & value ) {
/**
* @todo Implement this function.
*
* @note Remember to resize the table when necessary (load factor >=
* 0.7). **Do this check *after* increasing elems!!** Also, don't
* forget to mark the cell for probing with should_probe!
*/
++elems;
if( shouldResize() )
resizeTable();
int idx = hash( key, size );
while (table[idx]!=NULL)
{
idx++;
}
pair<K,V> *temp = new pair<K,V> (key, value);
table[idx] = temp;
should_probe[idx] = true;
}
开发者ID:cwang100,项目名称:class-projects,代码行数:21,代码来源:lphashtable.cpp
示例14: findPrime
void SCHashTable<K, V>::resizeTable()
{
typename list<pair<K, V>>::iterator it;
/**
* @todo Implement this function.
*
* Please read the note in the spec about list iterators!
* The size of the table should be the closest prime to size * 2.
*
* @hint Use findPrime()!
*/
size_t size2 = findPrime(size*2);
std::list<std::pair<K, V>>* table2 = new list<pair<K, V>>[size2];
for (size_t i = 0; i < size; i++){
for (it = table[i].begin(); it != table[i].end(); it++){
size_t idx = hash(it -> first, size2);
table2[idx].push_back(*it);
}
}
delete [] table;
table = table2;
size = size2;
}
开发者ID:nglokhei,项目名称:cs225,代码行数:23,代码来源:schashtable.cpp
注:本文中的hashes类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论