<div style='font-family:arial; font-size:13px;'><div>Diego,</div><div><br></div><div>Many thanks! That's saved me some work. :-).</div><div>Joe<br></div><br><div>March 20, 2022 5:58:11 PM CET Diego Sardina <dsar@eml.cc> wrote:<blockquote type="cite" cite="<b24310a9-d9bd-4098-b939-c9dfafd099f1@www.fastmail.com>"><pre style="font-size:13px;">On Sun, Mar 20, 2022, at 4:44 PM, Joe Turner wrote:<br>> <br>> [...] Anyway, I'll look around for a library, or I guess it wouldn't be too<br>hard to write one myself using an array of boolean.<br>> <br><br>Or an array of SET ;-)<br><br><br>MODULE Sets;<br><br> IMPORT SYSTEM;<br><br> CONST size = SYSTEM.SIZE(SET) * 8;<br><br> PROCEDURE Clear* (VAR s: ARRAY OF SET);<br> VAR i: INTEGER;<br> BEGIN<br> FOR i := 0 TO LEN(s)-1 DO s[i] := {} END<br> END Clear;<br><br> PROCEDURE Fill* (VAR s: ARRAY OF SET);<br> VAR i: INTEGER;<br> BEGIN<br> FOR i := 0 TO LEN(s)-1 DO s[i] := {0 .. size-1} END<br> END Fill;<br><br> PROCEDURE Include* (VAR s: ARRAY OF SET; x: INTEGER);<br> BEGIN<br> (* ASSERT(x DIV size < LEN(s)); *)<br> INCL(s[x DIV size], x MOD size)<br> END Include;<br><br> PROCEDURE Exclude* (VAR s: ARRAY OF SET; x: INTEGER);<br> BEGIN<br> (* ASSERT(x DIV size < LEN(s)); *)<br> EXCL(s[x DIV size], x MOD size)<br> END Exclude;<br><br> PROCEDURE In* (s: ARRAY OF SET; x: INTEGER): BOOLEAN;<br> BEGIN<br> (* ASSERT(x DIV size < LEN(s)); *)<br> RETURN x MOD size IN s[x DIV size]<br> END In;<br><br> PROCEDURE Subset* (s1, s2: ARRAY OF SET): BOOLEAN;<br> VAR i: INTEGER;<br> BEGIN<br> (* ASSERT(LEN(s1) <= LEN(s2)); *)<br> i := 0;<br> WHILE (i < LEN(s1)) & (s1[i] + s2[i] = s1[i]) DO INC(i) END;<br> RETURN i = LEN(s1)<br> END Subset;<br><br> PROCEDURE Count* (s: ARRAY OF SET): INTEGER;<br> VAR i, n: INTEGER;<br> BEGIN<br> n := 0;<br> FOR i := 0 TO (LEN(s)*size)-1 DO<br> IF (i MOD size) IN s[i DIV size] THEN INC(n) END<br> END;<br> RETURN n<br> END Count;<br><br> PROCEDURE Empty* (s: ARRAY OF SET): BOOLEAN;<br> VAR i: INTEGER;<br> BEGIN<br> i := 0;<br> WHILE (i < LEN(s)) & (s[i] = {}) DO INC(i) END;<br> RETURN i = LEN(s)<br> END Empty;<br><br> PROCEDURE Same* (s1, s2: ARRAY OF SET): BOOLEAN;<br> VAR i: INTEGER;<br> BEGIN<br> (* ASSERT(LEN(s1) = LEN(s2)); *)<br> i := 0;<br> WHILE (i < LEN(s1)) & (s1[i] = s2[i]) DO INC(i) END;<br> RETURN i = LEN(s1)<br> END Same;<br><br> PROCEDURE Distinct* (s1, s2: ARRAY OF SET): BOOLEAN;<br> VAR i: INTEGER;<br> BEGIN<br> (* ASSERT(LEN(s1) = LEN(s2)); *)<br> i := 0;<br> WHILE (i < LEN(s1)) & (s1[i] * s2[i] = {}) DO INC(i) END;<br> RETURN i = LEN(s1)<br> END Distinct;<br><br> PROCEDURE Union* (VAR s1, s2: ARRAY OF SET);<br> VAR i: INTEGER;<br> BEGIN<br> FOR i := 0 TO LEN(s1)-1 DO s1[i] := s1[i] + s2[i] END<br> END Union;<br><br> PROCEDURE Difference* (VAR s1, s2: ARRAY OF SET);<br> VAR i: INTEGER;<br> BEGIN<br> FOR i := 0 TO LEN(s1) DO s1[i] := s1[i] - s2[i] END<br> END Difference;<br><br> PROCEDURE Intersection* (VAR s1, s2, s3: ARRAY OF SET);<br> VAR i: INTEGER;<br> BEGIN<br> FOR i := 0 TO LEN(s1) DO s3[i] := s1[i] * s2[i] END<br> END Intersection;<br><br>END Sets.<br>--<br>Oberon@lists.inf.ethz.ch mailing list for ETH Oberon and related systems<br><a href="https://lists.inf.ethz.ch/mailman/listinfo/oberon" target="_blank">https://lists.inf.ethz.ch/mailman/listinfo/oberon</a><br></pre></blockquote></div></div>
--
Sent with https://mailfence.com
Secure and private email