node<T>* Tree<T>::deleteNode(node<T> *el, T valueOfElement) { node<T> *t = NULL, *q = NULL; if (!el) return NULL; else if (valueOfElement < el->inf) el->L = deleteNode(el->L, valueOfElement); else if (valueOfElement > el->inf) el->R = deleteNode(el->R, valueOfElement); else if (el->L && el->R) { t = findMinElement(el->R); el->inf = t->inf; el->R = deleteNode(el->R, el->inf); } else { t = el; if (el->L == NULL) q = el->R; if (el->R == NULL) q = el->L; delete t; return q; } return el; }
void referencePage(unsigned long long pageId, unsigned long long *numReferences, unsigned long long *numFaults) { /* -------------------------------- * LEAST RECENTLY USED ALGORITHM: * ------------------------------- * If we find the requested page in our cache, then set its counter to our global counter value. Finished. * Else, if our cache is full, then erase the element with the lowest counter. * Then, insert the requested page and set its counter to our global counter value. Finished. */ (*numReferences)++; if(findElement(lru->pages, pageId) >= 0) { setCounterOnElement(lru->pages, pageId, *numReferences); } else { if(getSetSize(lru->pages) == lru->numPages) eraseElement(lru->pages, findMinElement(lru->pages)); insertElement(lru->pages, pageId); setCounterOnElement(lru->pages, pageId, *numReferences); (*numFaults)++; printPageFault(pageId); } }
node<T>* Tree<T>::findMinElement(node<T> *el) { if (!el) return NULL; else if (el->L == NULL) return el; else return findMinElement(el->L); }