Trying to create a hash table class that is basically like a spell checker. The header file seems all good but the implementation i'm having issues with. Primarily the insert function keeps vomiting on me when i try to compile. Basically complaining about my iterators being wrong??? Anyways, here's my code. Any help would be appreciated!
//spellcheck.h header file
#include <iostream>
#include "d_hashf.h"
#include <vector>
#include <list>
using namespace std;
template<typename keyType, typename T, typename Hfunc>
class spellCheck
{
public:
spellCheck(); //default constructor
class iterator;
typedef pair<keyType, T> EntryType;
bool empty(); // tells whether table is empty
int size(); //how many items in the hash table
iterator find(const string& key); //points to item if in table
pair<iterator, bool> insert(EntryType& entry) ; //inserts item into table
private:
static const int LENGTH = 1373; //length of buckets
int count; //amount of items in hash table
vector<list<string>> buckets; //vector of lists of strings as hash table
hFstring hash_fcn;
} ;
//Implementation file for spellcheck.h
#include "spellcheck.h"
#include <fstream>
string s = ""; //default value for hashfunction
spellCheck<string,string,hFstring>::spellCheck()
{
buckets.resize(LENGTH);
count = 0;
hash_fcn(s);
}
pair<iterator, bool> spellCheck<string,string,hFstring>::insert(EntryType& entry)
{
int index = hash_fcn(entry.first) % buckets.size();
list<EntryType>::iterator i = buckets[index].begin();
while(i != buckets[index].end() && i->first != entry.first)
++i;
if(i == buckets[index].end())
{
buckets[index].push_back(EntryType(entry));
count++;
return make_pair(iterator(this,index,--(buckets[index].end())),true);
}
else
return make_pair(iterator(this,index, i),false);
}
bool spellCheck::empty()
{
if count == 0;
return true;
else
return false;
}
int spellCheck::size()
{
return count;
}
}