I want to implement Hash table in c++.I for some reason get error C2563 Missmatch in formal parameter list in class ChainedHashTable.
Here code for ChainedHashTable class:
#include"LancanaLista.h"
#include"HashTable.h"
template<class T, class R>
class ChainedHashTable : public HashTable<T, R>
{
protected:
LancanaLista<HashObject<T, R>>* niz;
public:
ChainedHashTable(unsigned int len)
{
this->lenght = len;
count = 0;
niz = new LancanaLista<HashObject<T, R>>[len];
}
~ChainedHashTable()
{
for (unsigned int i = 0; i < this->length; i++)
{
while (!niz[i].isEmpty())
{
niz[i].DeleteFromHead();
}
}
delete[] niz;
}
void insert(HashObject<T, R> obj)
{
niz[h(obj)].AddToHead(obj);
count++;
}
void withdraw(HashObject<T, R> obj)
{
niz[h(obj)].DeleteEl(obj);
count--;
}
void withdraw(T key)
{
HashObject<T, R> obj = find(key);
withdraw(obj);
}
HashObject<T, R> find(T key)
{
HashObject<T, R> obj;
unsigned int i = f(key) % this->lenght;
obj = niz[i].GetHeadEl();
while (!(obj.isEqualKey(key)))
{
obj = niz[i].GetNextEl(obj);
}
return obj;
}
/*void print()
{
for (int i = 0; i < count; i++)
{
niz[i].PrintAll();
cout << endl;
}
}*/
};
HashTable is base class, ChainedHashTable is derived class
Here code for HashTable class:
#pragma once
#include"HashObject.h"
template <class T, class R>
class HashTable
{
protected:
unsigned int lenght; // velicina tablice
unsigned int count; // broj elemenata u tablici
protected:
unsigned int h(HashObject<T, R> obj)
{
return (f(obj.getKey()) % lenght);
}
virtual unsigned int f(int i) { return abs(i); }
virtual unsigned int f(double d)
{
if (d == 0)return 0;
else
{
int exp;
double mantisa = frexp(d, &exp);
return (unsigned int)((2 * fabs(mantisa) - 1) * ~0U);
}
}
virtual unsigned int f(char* s)
{
unsigned int res = 0;
unsigned int a = 7;
for (int i = 0; s[i] != 0; i++)
{
res = res << a ^ s[i];
}
return res;
}
virtual unsigned int g(unsigned int i)
{
return (i + 1) % lenght;
}
public:
unsigned int GetLenght() { return lenght; }
virtual double getLoadFactor()
{
return (double)count / (double)lenght;
}
};
Here code for HashObject class:
#pragma once
#include<iostream>
using namespace std;
template<class T, class R>
class HashObject
{
protected:
T key;
R* record;
public:
HashObject() { key = (T)0; record = nullptr; }
HashObject(T k) { key = k; record = nullptr; }
HashObject(T k, R* o) { key = k; record = o; }
~HashObject() { deleteRecord(); }
HashObject& operator=(HashObject const& obj)
{
if (obj != this)
{
key = obj.key;
record = obj.record;
}
return *this;
}
bool operator ==(HashObject const& obj)
{
return record == obj.record;
}
void deleteRecord() {
if (record)
{
delete record;
record = nullptr;
}
}
T getKey() { return key; }
R* GetRecord() { return record; }
bool isEqualKey(T k) { return key == k; }
void print() { cout << key << "|" << record; }
};
Its implemented with LinkedList
Please help me to solve this problem.