Exemplo n.º 1
0
void HashTable::rebuildTable(unsigned int newSize, HashFunction *hashFunct)
{
    List **oldTable = table;
    unsigned int oldSize = hTsize;
    hTsize = newSize;
    createTable();
    collisions = 0;
    maxCollLength = 0;
    LoadFactor = 0;
    elemQuantity = 0;
    delete hash;
    hash = hashFunct;
    for (unsigned int i = 0; i < oldSize; i++)
    {
        if (oldTable[i] != NULL && !oldTable[i]->isEmpty())
        {
            ListElement *temp = oldTable[i]->getHead();
            while (temp->getNext() != NULL)
            {
                add(temp->getStr(), temp->getElemCounter());
                temp = temp->getNext();
            }
            add(temp->getStr(), temp->getElemCounter());
        }
    }
    for (int i = 0; i < hTsize; i++)
		delete oldTable[i];
    delete[] oldTable;
}
Exemplo n.º 2
0
bool List::exists(string str)
{
    ListElement *temp = head;
    while (temp->getNext() != NULL)
    {
        if (str == temp->getStr())
        {
            return true;
        }
        else
            temp = temp->getNext();
    }
    return temp->getStr() == str;
}
Exemplo n.º 3
0
bool HashTable::isExist(string str)
{
    unsigned long long int index = hash->hash(str) % hTsize;
    if (table[index] != NULL && !table[index]->isEmpty())
    {
        ListElement *temp = table[index]->getHead();
        while(temp->getNext() != NULL)
        {
            if (temp->getStr() == str)
            {
                return true;
            }
            else
            {
                temp = temp->getNext();
            }
        }
        return temp->getStr() == str;
    }
    else
        return false;
}
Exemplo n.º 4
0
void List::remove(string str) throw (string)
{
    if (size >= 2)
    {
        if (head->getStr() == str)
        {
            ListElement *toDel = head;
            head = head->getNext();
            head->setPrev(NULL);
            toDel->setNext(NULL);
            delete toDel;
            size--;
            return;
        }
        ListElement *temp = head->getNext();
        while(temp->getNext() != NULL)
        {
            if (temp->getStr() == str)
            {
                temp->getNext()->setPrev(temp->getPrev());
                temp->getPrev()->setNext(temp->getNext());
                delete temp;
                size--;
                return;
            }
            temp = temp->getNext();
        }
        if (tail->getStr() == str)
        {
            ListElement *toDel = tail;
            tail = tail->getPrev();
            tail->setNext(NULL);
            size--;
            delete toDel;
            return;
        }
        throw string("No such word!");
    }
    else if (size == 1)
    {
        if (head->getStr() == str)
        {
            delete head;
            size--;
            return;
        }
        throw string("No such word!");
    }
    else
        throw string("List is Empty!");
}
Exemplo n.º 5
0
void List::add (string str, unsigned int quantity)
{
    if (size == 0)
    {
        ListElement *temp = new ListElement(str);
        head = temp;
        tail = temp;
        head->setElemCounter(temp->getElemCounter() + quantity);
        size++;
    }
    else
    {
        ListElement *tmp = head;
        while (tmp->getNext() != NULL)
        {
            if (tmp->getStr() == str)
            {
                tmp->setElemCounter(tmp->getElemCounter() + quantity);
                return;
            }
            tmp = tmp->getNext();
        }
        if (tail->getStr() == str)
        {
            tmp->setElemCounter(tmp->getElemCounter() + quantity);
            return;
        }
        else
        {
            ListElement *temp = new ListElement(str, tail, NULL);
            temp->setElemCounter(temp->getElemCounter() + quantity);
            tail->setNext(temp);
            tail = temp;
            size++;
        }
    }
}