home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / Libraries / StdSet 1.0 / StdSet.h < prev   
Encoding:
C/C++ Source or Header  |  1997-07-19  |  4.0 KB  |  125 lines  |  [TEXT/MPS ]

  1.  
  2. #ifndef __STDSET__
  3. #define __STDSET__
  4.  
  5. /* File StdSet.h
  6.     operations for sets of long integers or pointers, interface.
  7.     Copyright (c) 1996, 1997 by John Montbriand.  All Rights Reserved.
  8.     Permission hereby granted for public use.
  9.         Distribute freely in areas where the laws of copyright apply.
  10.     USE AT YOUR OWN RISK.
  11.     DO NOT DISTRIBUTE MODIFIED COPIES.
  12.     Comments/questions/postcards* to the author at the address:
  13.       John Montbriand
  14.       P.O. Box. 1133
  15.       Saskatoon Saskatchewan Canada
  16.       S7K 3N2
  17.     or by email at:
  18.       tinyjohn@sk.sympatico.ca
  19.     *if you mail a postcard, then I will provide you with technical support
  20.     regarding questions you may have about this file.
  21.           see also: <http://www3.sk.sympatico.ca/tinyjohn>
  22. */
  23.  
  24. #include <Types.h>
  25.  
  26. /* TSETELT can be any type to which the < > >= and <= operators apply. */
  27. typedef long TSETELT;
  28.  
  29. typedef struct {
  30.     long n;        /* number of elements in the set */
  31.     TSETELT elt[1];    /* the elements, in ascending order */
  32. } SetRecord, **SetHandle;
  33.  
  34.  
  35. /* NewSet creates a new empty set.  NULL on error.  */
  36. SetHandle NewSet(void);
  37.  
  38. /* BuildSet creates a new set from an unsorted array.   NULL on error. 
  39.     count indicates the number of elements stored in the array data.  Elements
  40.     in the array need not be sorted.  */
  41. SetHandle BuildSet(long count, TSETELT *data);
  42.  
  43. /* DisposeSet reclaims the storage occupied by the set.  Note, if you are
  44.     storing pointers in the set, be sure to dispose of them before disposing
  45.     of the set.  */
  46. void DisposeSet(SetHandle set);
  47.  
  48. /* ClearSet re-initializes the set to an empty set. */
  49. void ClearSet(SetHandle set);
  50.  
  51. /* SetCopy copies the set in src to dst such that the resulting
  52.     sets are identical.  true if successfull. */
  53. Boolean SetCopy(SetHandle dst, SetHandle src);
  54.  
  55. /* SetCard returns the number of elements in the set a */
  56. long SetCard(SetHandle a);
  57.  
  58. /* SetElement returns the i'th element of the set a. */
  59. TSETELT SetElement(SetHandle a, long index);
  60.  
  61. /* SetAddElt adds the element to the set, true if the element
  62.     has been successfully added to the set. */
  63. Boolean SetAddElt(SetHandle a, TSETELT value);
  64.  
  65. /* SetRemoveElt removes the element from the set */
  66. void SetRemoveElt(SetHandle a, TSETELT value);
  67.  
  68. /* SetMember = true if value is in the set a */
  69. Boolean SetMember(SetHandle a, TSETELT value);
  70.  
  71. /* SetEmpty = true if a is the empty set */
  72. Boolean SetEmpty(SetHandle a);
  73.  
  74. /* SetEqual = true if a and b contain the same elements */
  75. Boolean SetEqual(SetHandle a, SetHandle b);
  76.  
  77. /* SetSubset = true if b is a subset of a */
  78. Boolean SetSubset(SetHandle a, SetHandle b);
  79.  
  80. /* SetAnd = a and b, set intersection.
  81.     returns a new set, NULL on error. */
  82. SetHandle SetAnd(SetHandle a, SetHandle b);
  83.  
  84. /* SetOr = a or b, set union. returns a new set, NULL on error. */
  85. SetHandle SetOr(SetHandle a, SetHandle b);
  86.  
  87. /* SetXor = a xor b, set difference. returns
  88.     a new set, NULL on error. */
  89. SetHandle SetXor(SetHandle a, SetHandle b);
  90.  
  91. /* SetRemove = a xor (a and b), remove common
  92.     elements. returns a new set, NULL on error. */
  93. SetHandle SetRemove(SetHandle a, SetHandle b);
  94.  
  95.  
  96. /* POWERSETS */
  97.  
  98. typedef SetHandle **PowerSet;
  99.  
  100. /* GeneratePowerSet returns the powerset of set a, the set
  101.     of all subsets on the elements in a.  subsets are sorted
  102.     according to their cardinality.  result is NULL on error.   */
  103. PowerSet GeneratePowerSet(SetHandle a);
  104.  
  105. /* DisposePowerSet reclaims storage occupied by the powerset */
  106. void DisposePowerSet(PowerSet powerset);
  107.  
  108. /* PowerSetSize returns the number of subsets in the powerset */
  109. long PowerSetSize(PowerSet powerset);
  110.  
  111. /* PowerSetElt returns the i'th subset in the powerset */
  112. SetHandle PowerSetElt(PowerSet powerset, long index);
  113.  
  114.  
  115. /* PERMUTATIONS */
  116.  
  117. /* SetPermute calls the SetPermutation function, perm,  that you define
  118.     once for each permutation of the elements in the set a.  param is
  119.     defined for your own use.  if the SetPermutation function returns
  120.     false, SetPermute returns immediately. */
  121. typedef Boolean (*SetPermutation)(TSETELT *elts, long nelts, long param);
  122. OSErr SetPermute(SetHandle a, SetPermutation perm, long param);
  123.  
  124. #endif
  125.