The generic interface List provides operations on linked lists of
arbitrary element types. This interface extends the operations you
can perform on the generic lists.
GENERIC INTERFACEListFuncs (Elem, List);
WhereElem.Tis the parameter passed to the generic listList. Thus,Elem.Tcontains
CONST Brand = <text-constant>; PROCEDURE Equal(k1, k2: Elem.T): BOOLEAN;as described inList.ig.Listis the instead ofList.iginstantiated withElem.
CONST Brand = "(ListFuncs " & Elem.Brand & ")"; TYPE T = List.T;As with
List.ig, none of the operations of this interface modify
the head field of an existing list element. Operations that may
modify the tail field of existing list elements are called {\it
destructive}. By convention, their names end in D.
\index{naming conventions!destructive list operations}
PROCEDURE DeleteD(VAR list: T; READONLY elem: Elem.T): T;
Delete the first occurrance ofeleminlist. Return the single element list containing this cell.listwill be modified if required. This happens if the first cell inlistiselem, for example.
PROCEDURE DeleteAllD(VAR list: T; READONLY elem: Elem.T): T;Delete the all occurrances of
elem in list. Return the list
containing these cells. list will be modified if required. This
happens if the first cell in list is an elem, for example.
PROCEDURE Count(l: T; READONLY e: Elem.T): INTEGER;
Return the number of occurances ofeinl. The comparison is performed byElem.Equal.
PROCEDURE New(READONLY elem: Elem.T): T;Allocate a new list element. Might reuse a cached element which was released by
Free below.
PROCEDURE Free(list: T): T;Free the single list element pointed at by
list and return the
remainder of the list pointed at by list.tail. NOTE: since
freed elements may be retained, you should clear list.head if it
contains a reference you don't want to be retained.
END ListFuncs.