double Statistics::effic(AbstractHash **abh) { if (dynamic_cast<ListHash*>((*abh)) != NULL) return 100; else if (dynamic_cast<ArrayHash*>((*abh)) != NULL) { ArrayHash *ah = dynamic_cast<ArrayHash*>((*abh)); int num = 0; for (int i = 0; i < ah->getSize(); i++) if (ah->getStr()[i].length() != 0) num++; return ((num * 100) / (double)ah->getSize()); } else std::cout << "ERROR WHILE TESTING." << std::endl; }
int Statistics::memory(AbstractHash **abh) { if (dynamic_cast<ListHash*>((*abh)) != NULL) { int value = 0; ListHash *lh = dynamic_cast<ListHash*>((*abh)); for (int i = 0; i < lh->getSize(); i++) { ListElem *curr = lh->getList()[i].getHead(); ListElem *tail = lh->getList()[i].getTail(); while (*curr != *tail) { value += curr->str.capacity(); curr = curr->next; } } return (value + sizeof(int)); } else if (dynamic_cast<ArrayHash*>((*abh)) != NULL) { int value = 0; ArrayHash *ah = dynamic_cast<ArrayHash*>((*abh)); for (int i = 0; i < ah->getSize(); i++) value += ah->getStr()[i].capacity(); return (sizeof(int) + value); } else std::cout << "ERROR WHILE TESTING." << std::endl; }