Добавил:
Upload
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз:
Предмет:
Файл:12пми / MyHashTable / Документ
.txt#ifndef MYHASHTABLE_H_
#define MYHASHTABLE_H_
#include <iostream>
#include <climits>
using namespace std;
template <typename T>
class MyHashTable
{
public:
MyHashTable(const unsigned size);
virtual ~MyHashTable();
void clear();
bool empty();
unsigned size();
unsigned maxSize();
bool get(const string& key, T& value);
bool set(const string& key, const T value);
void printLog();
private:
class Element
{
public:
Element(const string& key, const T value);
virtual ~Element();
string key;
T value;
Element *next;
};
unsigned mSize; // size of the hash table
unsigned mCount; // number elements which are contained in the hash table
Element **mArray;
unsigned hashFunction(const string& key);
};
template <typename T>
MyHashTable<T>::MyHashTable(const unsigned size)
{
mSize = size;
//Create table of pointers
mArray = new Element*[mSize];
mCount = 0;
for(unsigned i=0; i<mSize; i++)
{
mArray[i]=NULL;
}
}
template <typename T>
MyHashTable<T>::~MyHashTable()
{
if (mArray != NULL)
{
//Clean the hash table
clear();
//Erase table of pointers
delete[] mArray;
mArray = NULL;
}
}
Соседние файлы в папке MyHashTable