Sets with more than 32 elements?

Programming language questions
Post Reply
jackD
Posts: 10
Joined: Fri Oct 15, 2021 9:10 am

Sets with more than 32 elements?

Post 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!
User avatar
Ivan Denisov
Posts: 357
Joined: Tue Sep 17, 2013 12:21 am
Location: Krasnoyarsk, Russia

Re: Sets with more than 32 elements?

Post 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.
cfbsoftware
Posts: 51
Joined: Wed Sep 18, 2013 10:06 pm
Contact:

Re: Sets with more than 32 elements?

Post 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
jackD
Posts: 10
Joined: Fri Oct 15, 2021 9:10 am

Re: Sets with more than 32 elements?

Post 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
User avatar
Ivan Denisov
Posts: 357
Joined: Tue Sep 17, 2013 12:21 am
Location: Krasnoyarsk, Russia

Re: Sets with more than 32 elements?

Post 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.
Zinn
Posts: 117
Joined: Mon Nov 24, 2014 10:47 am
Location: Frankfurt am Main
Contact:

Re: Sets with more than 32 elements?

Post 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
jackD
Posts: 10
Joined: Fri Oct 15, 2021 9:10 am

Re: Sets with more than 32 elements?

Post 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.
User avatar
Robert
Posts: 177
Joined: Sat Sep 28, 2013 11:04 am
Location: Edinburgh, Scotland

Re: Sets with more than 32 elements?

Post 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.
Post Reply