#include <stdio.h> #include "copyright.h" #include "config.h" #include "db.h" #include "externs.h" #include "params.h" #include "lru.h" #ifdef USE_DBP static dbref head = NOTHING; static dbref tail = NOTHING; static int listlen = 0; int lru_count(void) { return listlen; } void lru_use(dbref key) { dbref tmp, scout; if (head == NOTHING) { head = tail = key; listlen++; DBSTORE(key, lru_next, NOTHING); return; } if (head == key) return; for (tmp = head; tmp != NOTHING; tmp = DBFETCH(tmp)->lru_next) { scout = DBFETCH(tmp)->lru_next; if (scout == key) { DBSTORE(tmp, lru_next, DBFETCH(scout)->lru_next); DBSTORE(scout, lru_next, head); head = scout; if (tail == scout) tail = tmp; } } if (head != key) { DBSTORE(key, lru_next, head); head = key; listlen++; } } dbref lru_old(void) { dbref ret, tmp, previous; if (tail == NOTHING) return NOTHING; ret = tail; if (tail == head) { tail = head = NOTHING; } else { for (tmp = head; tmp != tail; tmp = DBFETCH(tmp)->lru_next) previous = tmp; DBSTORE(previous, lru_next, NOTHING); tail = previous; } listlen--; return ret; } int lru_hasp(dbref key) { dbref tmp; for (tmp = head; tmp != NOTHING; tmp = DBFETCH(tmp)->lru_next) if (tmp == key) return 1; return 0; } dbref lru_head(void) { return(head); } #endif