DEFINITION LRU;

(* generic LRU (least recently used) - lists *)

(*    7'93 by Dirk_Theisen@SU.maus.de       *)

  CONST

    mrufirst = 0;
    lrufirst = 1;

  TYPE

    Elem     = POINTER TO ElemDesc;
    ElemDesc = RECORD
                 prev   : Elem;
                 next   : Elem;
                 used   : INTEGER;
                 PROCEDURE (x: Elem) EqualTo(y: Elem): BOOLEAN;(* please override *)
               END;
    DoProc   = PROCEDURE (e: Elem): BOOLEAN;
    List     = RECORD
                 PROCEDURE (VAR list: List) Init();
                 PROCEDURE (VAR list: List) Use(el: Elem);
                   (* call this proc when Element el in LRU is used *)
                 PROCEDURE (VAR list: List) Insert(el: Elem);
                   (* adds an element el to the end of LRU-List list. *)
                 PROCEDURE (VAR list: List) Delete(el: Elem);
                   (* removes element el from LRU-list LRU. *)
                 PROCEDURE (VAR list: List) Traverse(mode: SHORTINT; more: DoProc);
                   (* calls proc more for the least recently used elements
                      of LRU list and stops if more returns FALSE *)
                 PROCEDURE (VAR list: List) Search(x: Elem): Elem;
                   (* searches fpr the element x in list using procedure
                      EqualTo. MRU first. *)
               END;

END LRU.
