Sets with more than 32 elements?
Sets with more than 32 elements?
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!
- Ivan Denisov
- Posts: 359
- Joined: Tue Sep 17, 2013 12:21 am
- Location: Krasnoyarsk, Russia
Re: Sets with more than 32 elements?
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.
-
- Posts: 54
- Joined: Wed Sep 18, 2013 10:06 pm
- Contact:
Re: Sets with more than 32 elements?
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
You can download a copy of the book from:
http://ssw.jku.at/Research/Books/Oberon2.pdf
Re: Sets with more than 32 elements?
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
https://www.mathematik.uni-ulm.de/obero ... s.mod.html
- Ivan Denisov
- Posts: 359
- Joined: Tue Sep 17, 2013 12:21 am
- Location: Krasnoyarsk, Russia
Re: Sets with more than 32 elements?
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.
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?
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
Maybe it is what you are looking for.
- Helmut
Re: Sets with more than 32 elements?
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.
CONST myArray : ARRAY 10 OF SET = ({},{}...). You can do something similar in Free Pascal.
Re: Sets with more than 32 elements?
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.
The module also contains procedures for things like creating random sets, and converting to and from ASCII.