Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Some Noob (to QB64) Questions
#8
Well if you insist... This library (when it will compile) brings mathematical sets (like in Pascal) to QB64. It worked fine in QuickBasic 4.5. In order to explain about what it actually does I'll quote the original readme I included with it -

Quote:So what is charset I hear you ask. Charset consists of three files, Charset.BI, Charset.BAS and Testsets.BAS. The first 2 files are the interface and the source code for a small library that deals with an abstract data type while the final file is a very rough and ready test program for the library. The abstract data type that is dealt with is called a CharSet and is a simulation of mathematical sets in the domain of the 256 different characters of the PC's (western) character set (cor! What a mouthful! :-) ). In other words you now no longer need Pascal if you want to use sets of characters. In fact with my implementation you have 18 different things you can do with sets as opposed to the ten you can with Pascal.

If you know about set theory please skip to the next section because what I am about to say is for those who have no idea what I'm talking about up to this point. Beware what follows is a gross over-simplification and is the absolute minimum needed in order to make full use of the charset library.

What is a set? A set is a collection of things, with no duplicates. What sort of items. Well in our case characters (those things you get when you use CHR$() :-) ). So what is the minimum number of items needed for a collection of items to be a set? Absolutely zero (this is termed the empty set). The items that are part of a set are termed the members of the set and the number of members a set has is termed the cardinality of the set. Another term to do with sets is subset, which is itself a set. Suppose you have two sets, one set will be a subset of the other if all of its members are included in the other. By this definition the empty set is a subset of all other sets and a set is a subset of itself. There is another type of subset, called a strict (or proper) subset. This type of subset is identical to an ordinary subset except that a set cannot be a strict subset of itself. Five set operations that you need to know about are Union, difference, intersection and symmetric set difference and complement. The first 4 of these operations take 2 arguments and return a third.

Set union - The action of this operation is to combine the contents of the 2 arguments and place the result in the third. The order of the 2 arguments is not important.

Set difference - This operation removes those items contained in the second argument that also occur in the first argument, from the first argument and places the result in the third. The order of the first 2 arguments is  paramount.

Set intersection - All the items that occur in both the first argument and the second argument are placed in the third. Order of the first 2 arguments is unimportant.

Symmetric set difference - All the items that occur in either the first argument or the second argument but do not occur in both arguments simultaneously are placed in the third. Order of the first 2 arguments is not a problem for this operation.

Set complement - This operation takes a single argument and returns a second. In order to explain what this operation does I will have to introduce another term. That term is "the universe of a set". The universe of a set is all the items that could possibly be held in a set. In the case of the library that I have placed in this echo that is all the characters in the PC's (western) character set i.e. CHR$(0) to CHR$(255) inclusive. What set complement does is to place into the second all the items in the universe of the set *except* those that are already in the first
        argument.

Having dealt with sets in general, I will now deal with the library I have written. As I have already said a number of times, the sets that are manipulated in this library deal exclusively with characters. This is not as great a limitation as might at first be imagined as (at least in Pascal) sets of characters are by far the most heavily used type of set. So what can you do with these sets of characters? Below is a list of all the routines that are in the library. Those items marked with a * are also supported by Pascal, while those that are marked with an M are part of formal set theory. Those which remain are there to increase the usefulness of the library as a whole. For further information see the comments in CharSet.BI.

Code: (Select All)
Initialise a set                        (InitialiseSet)         *
Add items to a set                      (IncludeInSet)          *
Remove items from a set                 (ExcludeFromSet)        *
Assign one set to another               (CopySet)               *
Make a set completely empty             (MakeSetEmpty)
Copy the contents of a set to a string  (GetSetContents)

How many items are in a set             (Cardinality%)           M
Is an item a member of set              (IsMember)              *M
Is a set empty                          (SetIsEmpty)
Are two sets identical                  (SetEquality)           *M
Are two sets not identical              (SetInequality)         *M
Is one set a subset of another          (IsSubsetOf)            *M
Is one set a strict subset of another   (IsStrictSubsetOf)       M

Set Complement                          (SetComplement)          M
Set Union                               (SetUnion)              *M
Set Difference                          (SetDifference)         *M
Set Intersection                        (SetIntersection)       *M
Symmetric Set Difference                (SymmetricSetDifference) M


Code in next post.

TR
Reply


Messages In This Thread
Some Noob (to QB64) Questions - by TarotRedhand - 05-07-2022, 08:29 AM
RE: Some Noob (to QB64) Questions - by SMcNeill - 05-07-2022, 09:14 AM
RE: Some Noob (to QB64) Questions - by bplus - 05-07-2022, 03:34 PM
RE: Some Noob (to QB64) Questions - by bplus - 05-07-2022, 04:25 PM
RE: Some Noob (to QB64) Questions - by SMcNeill - 05-12-2022, 06:55 PM
RE: Some Noob (to QB64) Questions - by TarotRedhand - 05-13-2022, 09:39 AM
RE: Some Noob (to QB64) Questions - by SMcNeill - 05-13-2022, 11:59 AM



Users browsing this thread: 3 Guest(s)