int main() { std::unique_ptr <App> my_list(new App()); std::unique_ptr <Solution> mySolution(new Solution()); std::unique_ptr <InsertToHead> insertToHead(new InsertToHead()); try { long a1 = std::clock(); std::cout << "Time Start: " << a1 << "\n"; // my_list->Run(); // mySolution->Run(); insertToHead->Run(); long b1 = std::clock(); std::cout << "Time END: " << b1 << "\n\n"; std::cout << "Open file Time TOTAL: " << (b1-a1)/1000.0 << " sec.\n"; } catch(std::runtime_error) { std::cout << "EXCEPTION_EXECUTE_HANDLER\n"; } /* __except (EXCEPTION_EXECUTE_HANDLER) { std::cout << "EXCEPTION_EXECUTE_HANDLER has number - " << EXCEPTION_EXECUTE_HANDLER << "\n"; } */ //std::string p; system("PAUSE"); //std::cout << "\nPress any key to exit...\n"; //cin >> p; return 1; }
void set(int key, int value) { /* exist, change value, move to head not found, check cache capacity if not full, insert to head if full, delete the tail(least recently used), insert to head */ if(dllist.find(key) != dllist.end()) { dllist[key]->value = value; node *p = dllist[key]; moveToHead(p); } else { // full if(dllist.size() == capacity) { node *p = tail->prev; // delete node from map dllist.erase(p->key); deleteTailNode(p); } node *q = new node(key, value); dllist[key] = q; // Add node to map insertToHead(q); } }