Page 1 of 1
Sets with more than 32 elements?
Posted: Tue Feb 08, 2022 2:37 pm
by jackD
In CP the largest element of a set is 31, which is too restrictive for my application. Is there an efficient way to create sets with up to 100 elements? (actually, 0-63 would be enough). I'm aware that there is way to do it using boolean arrays, but haven't been able to figure out exactly how. Thanks!
Re: Sets with more than 32 elements?
Posted: Tue Feb 08, 2022 4:11 pm
by Ivan Denisov
I can imaging smth like this
Code: Select all
MODULE TestSet64;
IMPORT Log := StdLog, In, Math;
TYPE
Set = POINTER TO RECORD
a, b: SET;
END;
PROCEDURE (s: Set) Add (n: BYTE), NEW;
BEGIN
ASSERT(n >= 0, 20); ASSERT(n < 64, 21);
IF n < 32 THEN
s.a := s.a + {n}
ELSE
s.b := s.b + {n-32}
END
END Add;
PROCEDURE (s: Set) Remove (n: BYTE), NEW;
BEGIN
ASSERT(n >= 0, 20); ASSERT(n < 64, 21);
IF n < 32 THEN
s.a := s.a - {n}
ELSE
s.b := s.b - {n-32}
END
END Remove;
PROCEDURE (s: Set) Check (n: BYTE): BOOLEAN, NEW;
BEGIN
ASSERT(n >= 0, 20); ASSERT(n < 64, 21);
IF n < 32 THEN
RETURN n IN s.a
ELSE
RETURN n-32 IN s.b
END
END Check;
END TestSet64.
Re: Sets with more than 32 elements?
Posted: Wed Feb 09, 2022 12:38 am
by cfbsoftware
There's an example of how to define a class for sets of arbitrary integers in Section 4.3 of the book
Object-Oriented Programming in Oberon-2 by Hanspeter Mössenböck. The Component Pascal solution would be very similar.
You can download a copy of the book from:
http://ssw.jku.at/Research/Books/Oberon2.pdf
Re: Sets with more than 32 elements?
Posted: Wed Feb 09, 2022 7:50 am
by jackD
Thanks guys for the responses. I'm still learning and haven't quite grasped how OOP works in CP, so I don't fully understand the code, but I'll get there. I found a module for sets here :
https://www.mathematik.uni-ulm.de/obero ... s.mod.html
Re: Sets with more than 32 elements?
Posted: Wed Feb 09, 2022 12:24 pm
by Ivan Denisov
Actually OOP does not mean much. Syntactic sugar.
However many stuff in framework done in OOP way, so it is impossible to use BlackBox features without it.
Re: Sets with more than 32 elements?
Posted: Wed Feb 09, 2022 7:39 pm
by Zinn
Have a look at the MODULE Sets inside subsystem Coco. You can download Coco from
https://zinnamturm.eu/downloadsAC.htm#Coco
Maybe it is what you are looking for.
- Helmut
Re: Sets with more than 32 elements?
Posted: Thu Feb 10, 2022 11:59 am
by jackD
Helmut, thanks for the heads up regarding Coco. I've adapted the Ulm Sets library I linked to previously and it works fine, although it's a bit clunky and more work to initialize a set with known elements because you can't just do mySet := {....}. It would be nice to be able to do something like:
CONST myArray : ARRAY 10 OF SET = ({},{}...). You can do something similar in Free Pascal.
Re: Sets with more than 32 elements?
Posted: Sun Feb 20, 2022 12:22 pm
by Robert
On the website Component Pascal Collection (
http://zinnamturm.eu/downloadsIN.htm#Lib) there is a sub-system called Lib. It contains a module "LibSets" which contains a type "BiSet" which is essentially a 64-bit set.
The module also contains procedures for things like creating random sets, and converting to and from ASCII.