Skip to content
Snippets Groups Projects
Commit 8158a10c authored by Nicholas Yang's avatar Nicholas Yang
Browse files

updating dht with error checking

parent fc6a0337
No related branches found
No related tags found
1 merge request!3Indexer
...@@ -48,8 +48,8 @@ public: ...@@ -48,8 +48,8 @@ public:
maxKeySize = maxKeySize_in; maxKeySize = maxKeySize_in;
maxValueSize = maxValueSize_in; maxValueSize = maxValueSize_in;
nodeSize = maxKeySize + maxValueSize + 2; nodeSize = maxKeySize + maxValueSize + 2;
if(nodeSize % 10 != 0) { if(1000 % nodeSize != 0) {
cerr << "The sum of key size + value size + 2 must be divisible by 10!"; cerr << "The sum of key size + value size + 2 must divide a multiple of 1000!";
exit(1); exit(1);
} }
if(fileSize <= 0) { // no file, or empty file if(fileSize <= 0) { // no file, or empty file
...@@ -79,6 +79,14 @@ public: ...@@ -79,6 +79,14 @@ public:
* @return * @return
*/ */
bool insert(string key, string value) { bool insert(string key, string value) {
if(key.size() > maxKeySize) {
cerr << "A key you tried to insert into a disk hash table was larger than the set max key size!";
exit(1);
}
if(value.size() > maxValueSize) {
cerr << "A value you tried to insert into a disk hash table was larger than the set max value size!";
exit(1);
}
if((double) size / capacity >= 0.75) { if((double) size / capacity >= 0.75) {
rehash(); rehash();
} }
......
No preview for this file type
...@@ -70,7 +70,7 @@ void Indexer::verbose_run() { ...@@ -70,7 +70,7 @@ void Indexer::verbose_run() {
void Indexer::save ( ) void Indexer::save ( )
{ {
map< string, vector< size_t > > maps( masterDictionary.begin( ), masterDictionary.end( ) ); map< string, vector< size_t > > maps( masterDictionary.begin( ), masterDictionary.end( ) );
DiskHashTable seeker(util::GetCurrentWorkingDir( ) + "/indexer/output/" + to_string( currentFile ) + "-seek.txt", 20, 8 ); DiskHashTable seeker(util::GetCurrentWorkingDir( ) + "/indexer/output/" + to_string( currentFile ) + "-seek.txt", 30, 8 );
string fileName = util::GetCurrentWorkingDir( ) + "/indexer/output/" + to_string( currentFile ) + ".txt"; string fileName = util::GetCurrentWorkingDir( ) + "/indexer/output/" + to_string( currentFile ) + ".txt";
int file = open( fileName.c_str( ), O_CREAT | O_WRONLY, S_IRWXU ); int file = open( fileName.c_str( ), O_CREAT | O_WRONLY, S_IRWXU );
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment