Name: Set Maintainer: Paul Rovner Date: September 22, 1982 4:56 pm Purpose: Provision of a SET abstraction for Cedar client programmers Accessible via: [Indigo]<Cedar>Top>Set.df This package is intended for use with Cedar for dealing with "sets" of REFs, i.e. variable length collections of elements in which there are no duplicates. Elements are REF ANYs. The interface described herein is defined in Set.Mesa. An implementation resides in SetImpl.bcd. The following procedures are defined in the Set interface: New: PROC RETURNS[Set.Handle]; This creates a new (empty) set. Equal: PROC[s1, s2: Handle] RETURNS[BOOLEAN]; This returns TRUE if the two sets (s1 and s2) contain the same elements. In, Put, Remove: PROC[set: Handle, element: Element] RETURNS[found: BOOLEAN]; In returns TRUE if the specified Element is a member of the specified set. Put causes the specified Element to become a member of the specified set. Put returns TRUE if the specified Element was already in the set (the set is not changed in this case). Remove deletes the specified Element from the specified set. It returns FALSE if the element was not a member of the set (the set is not changed in this case). Union, Difference, Intersection: PROC[s1, s2: Handle] RETURNS[ans: Handle]; These implement the specified operations on sets. Cardinality: PROC[set: Handle] RETURNS[LONG CARDINAL]; This returns the number of elements of the specified set. Enumerate: PROC[set: Handle, proc: PROC[e: Element] RETURNS[stop: BOOLEAN]] RETURNS[stopped: BOOLEAN]; This causes the specified procedure (proc) to be invoked once for each Element of the specified set. If any call of proc returns TRUE, the enumeration is terminated at that point and Enumerate returns TRUE. If no call of proc returns TRUE, then Enumerate returns FALSE. The enumeration order of set elements is arbitrary. Modifications may be made to the specified set during its enumeration (e.g. elements added or elements removed by the action of proc), but such elements may or may not be included in the enumeration. Nth: PROC[set: Handle, index: LONG CARDINAL--starting at 1--] RETURNS[element: Element ← NIL]; This is provided for convenience as an alternative to Enumerate. It returns NIL if index > Cardinality[set]. It returns the nth element of the specified set. The order of set elements is arbitrary.