home *** CD-ROM | disk | FTP | other *** search
-
- #ifndef __STDSET__
- #define __STDSET__
-
- /* File StdSet.h
- operations for sets of long integers or pointers, interface.
- Copyright (c) 1996, 1997 by John Montbriand. All Rights Reserved.
- Permission hereby granted for public use.
- Distribute freely in areas where the laws of copyright apply.
- USE AT YOUR OWN RISK.
- DO NOT DISTRIBUTE MODIFIED COPIES.
- Comments/questions/postcards* to the author at the address:
- John Montbriand
- P.O. Box. 1133
- Saskatoon Saskatchewan Canada
- S7K 3N2
- or by email at:
- tinyjohn@sk.sympatico.ca
- *if you mail a postcard, then I will provide you with technical support
- regarding questions you may have about this file.
- see also: <http://www3.sk.sympatico.ca/tinyjohn>
- */
-
- #include <Types.h>
-
- /* TSETELT can be any type to which the < > >= and <= operators apply. */
- typedef long TSETELT;
-
- typedef struct {
- long n; /* number of elements in the set */
- TSETELT elt[1]; /* the elements, in ascending order */
- } SetRecord, **SetHandle;
-
-
- /* NewSet creates a new empty set. NULL on error. */
- SetHandle NewSet(void);
-
- /* BuildSet creates a new set from an unsorted array. NULL on error.
- count indicates the number of elements stored in the array data. Elements
- in the array need not be sorted. */
- SetHandle BuildSet(long count, TSETELT *data);
-
- /* DisposeSet reclaims the storage occupied by the set. Note, if you are
- storing pointers in the set, be sure to dispose of them before disposing
- of the set. */
- void DisposeSet(SetHandle set);
-
- /* ClearSet re-initializes the set to an empty set. */
- void ClearSet(SetHandle set);
-
- /* SetCopy copies the set in src to dst such that the resulting
- sets are identical. true if successfull. */
- Boolean SetCopy(SetHandle dst, SetHandle src);
-
- /* SetCard returns the number of elements in the set a */
- long SetCard(SetHandle a);
-
- /* SetElement returns the i'th element of the set a. */
- TSETELT SetElement(SetHandle a, long index);
-
- /* SetAddElt adds the element to the set, true if the element
- has been successfully added to the set. */
- Boolean SetAddElt(SetHandle a, TSETELT value);
-
- /* SetRemoveElt removes the element from the set */
- void SetRemoveElt(SetHandle a, TSETELT value);
-
- /* SetMember = true if value is in the set a */
- Boolean SetMember(SetHandle a, TSETELT value);
-
- /* SetEmpty = true if a is the empty set */
- Boolean SetEmpty(SetHandle a);
-
- /* SetEqual = true if a and b contain the same elements */
- Boolean SetEqual(SetHandle a, SetHandle b);
-
- /* SetSubset = true if b is a subset of a */
- Boolean SetSubset(SetHandle a, SetHandle b);
-
- /* SetAnd = a and b, set intersection.
- returns a new set, NULL on error. */
- SetHandle SetAnd(SetHandle a, SetHandle b);
-
- /* SetOr = a or b, set union. returns a new set, NULL on error. */
- SetHandle SetOr(SetHandle a, SetHandle b);
-
- /* SetXor = a xor b, set difference. returns
- a new set, NULL on error. */
- SetHandle SetXor(SetHandle a, SetHandle b);
-
- /* SetRemove = a xor (a and b), remove common
- elements. returns a new set, NULL on error. */
- SetHandle SetRemove(SetHandle a, SetHandle b);
-
-
- /* POWERSETS */
-
- typedef SetHandle **PowerSet;
-
- /* GeneratePowerSet returns the powerset of set a, the set
- of all subsets on the elements in a. subsets are sorted
- according to their cardinality. result is NULL on error. */
- PowerSet GeneratePowerSet(SetHandle a);
-
- /* DisposePowerSet reclaims storage occupied by the powerset */
- void DisposePowerSet(PowerSet powerset);
-
- /* PowerSetSize returns the number of subsets in the powerset */
- long PowerSetSize(PowerSet powerset);
-
- /* PowerSetElt returns the i'th subset in the powerset */
- SetHandle PowerSetElt(PowerSet powerset, long index);
-
-
- /* PERMUTATIONS */
-
- /* SetPermute calls the SetPermutation function, perm, that you define
- once for each permutation of the elements in the set a. param is
- defined for your own use. if the SetPermutation function returns
- false, SetPermute returns immediately. */
- typedef Boolean (*SetPermutation)(TSETELT *elts, long nelts, long param);
- OSErr SetPermute(SetHandle a, SetPermutation perm, long param);
-
- #endif
-