Rehash bug.

This commit is contained in:
Federico Ponchio 2004-07-01 21:34:04 +00:00
parent 95a66a4153
commit fbe6bc4d8f
1 changed files with 9 additions and 2 deletions

View File

@ -24,6 +24,9 @@
History History
$Log: not supported by cvs2svn $ $Log: not supported by cvs2svn $
Revision 1.1 2004/06/24 14:32:45 ponchio
Moved from wrap/nexus
Revision 1.1 2004/06/24 14:18:58 ponchio Revision 1.1 2004/06/24 14:18:58 ponchio
Created Created
@ -31,12 +34,14 @@ Created
****************************************************************************/ ****************************************************************************/
#include "mfhash.h" #include "mfhash.h"
#include <iostream>
using namespace std; using namespace std;
using namespace nxs; using namespace nxs;
bool MFHash::Create(const string &file, unsigned int reserved) { bool MFHash::Create(const string &file, unsigned int reserved) {
if(!buffer.Create(file)) return false; if(!buffer.Create(file)) return false;
buffer.Resize(reserved); buffer.Resize(reserved);
Bucket empty; Bucket empty;
for(unsigned int i = 0; i < buffer.Size(); i++) for(unsigned int i = 0; i < buffer.Size(); i++)
@ -98,8 +103,10 @@ void MFHash::Insert(unsigned int key, unsigned int value, bool rehash) {
if(rehash) { if(rehash) {
float ratio = space / (float)buffer.Size(); float ratio = space / (float)buffer.Size();
if(ratio < 0.4) //need to resize if(ratio < 0.4) { //need to resize
Resize(buffer.Size() * 2 - 1); cerr << "rehash" << endl;
Resize(buffer.Size() * 2 + 3);
}
} }
} }