* * *

Author Topic: Pascal's set size limit  (Read 884 times)

Itamar

  • Newbie
  • Posts: 1
Pascal's set size limit
« on: April 03, 2018, 12:41:33 pm »
Hi,
This question is for my homwork assigmnent (and we need to search the interent so  8))
is there a size limit on Pascal's sets, if so, then why?
google wasn't able to give and exact answer...

Thanks!

furious programming

  • Jr. Member
  • **
  • Posts: 52
  • I click a little.
    • TreeStructInfo - format for text and binary configuration files
Re: Pascal's set size limit
« Reply #1 on: April 03, 2018, 01:00:20 pm »
All is described in documentation:

3.3.3 Set types
1.2.61 $PACKSET : Specify set size

It all depends on the number of elements and used settings for sets packing.
« Last Edit: April 03, 2018, 01:07:31 pm by furious programming »

taazz

  • Hero Member
  • *****
  • Posts: 5051
Re: Pascal's set size limit
« Reply #2 on: April 03, 2018, 01:05:31 pm »
as far as I know the maximum number of items in a set is 256. I'm not aware of any specific reason that 256 was used as a limit other than I haven't encounter any sets in the 100s of items range.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

furious programming

  • Jr. Member
  • **
  • Posts: 52
  • I click a little.
    • TreeStructInfo - format for text and binary configuration files
Re: Pascal's set size limit
« Reply #3 on: April 03, 2018, 01:24:58 pm »
By default, the size of set is 4 or 32 bytes, depends of elements range. Sets with at most 32 elements are store in 4 bytes, otherwise 32. Short example:

Code: Pascal  [Select]
  1. {$MODE OBJFPC}{$LONGSTRINGS ON}
  2.  
  3. type
  4.   TFewElement       = 0 .. 2;
  5.   TMoreElement      = 0 .. 31;
  6.   TEvenMoreElement  = 0 .. 32;
  7.   TManyElement      = 0 .. 255;
  8.  
  9. type
  10.   TFewElements      = set of TFewElement;
  11.   TMoreElements     = set of TMoreElement;
  12.   TEvenMoreElements = set of TEvenMoreElement;
  13.   TManyElements     = set of TManyElement;
  14.  
  15. begin
  16.   WriteLn('TFewElements:      ', SizeOf(TFewElements));
  17.   WriteLn('TMoreElements:     ', SizeOf(TMoreElements));
  18.   WriteLn('TEvenMoreElements: ', SizeOf(TEvenMoreElements));
  19.   WriteLn('TManyElements:     ', SizeOf(TManyElements));
  20.  
  21.   ReadLn();
  22. end.

Output:

Code: Pascal  [Select]
  1. TFewElements:      4
  2. TMoreElements:     4
  3. TEvenMoreElements: 32
  4. TManyElements:     32

And then with {$PACKSET 1}:

Code: Pascal  [Select]
  1. TFewElements:      1
  2. TMoreElements:     4
  3. TEvenMoreElements: 5
  4. TManyElements:     32

and then with {$PACKSET 2}:

Code: Pascal  [Select]
  1. TFewElements:      2
  2. TMoreElements:     4
  3. TEvenMoreElements: 6
  4. TManyElements:     32

Thats how it works. Play with it.
« Last Edit: April 03, 2018, 01:26:47 pm by furious programming »

howardpc

  • Hero Member
  • *****
  • Posts: 2669
Re: Pascal's set size limit
« Reply #4 on: April 18, 2018, 09:44:53 am »
is there a size limit on Pascal's sets, if so, then why?

The upper limit on set size is arbitrary, in the sense that you can implement sets of any size by designing the compiler accordingly.
Presumably the upper limit of 256 elements was chosen on grounds of practicality. It is a classic tradeoff between size and speed.
Given that the native integer size on commonly available 64-bit hardware is 8 bytes, a multiple of 8 bytes (or 64 elements) is clearly a sensible choice.
A maximum set size four times the native integer size still allows for pretty fast processing and covers all common use cases (allowing for up to 256 elements).
Where more than 256 set elements are needed, you just have to code the TLargeSet routines yourself, and not rely on the code already written and debugged by the compiler developers.
Perhaps the upper limit was chosen at a time when hardware was commonly 32-bit or even 16-bit. But similar considerations would have applied.
But as taazz points out, who regularly needs such large sets? Probably only people who are heavily into mathematical stuff, people who are well able to code what they need anyway.
If you're dealing with more than 256 elements you're probably interested in more than a simple boolean flag associated with each element, and you're verging on needing a proper database.
« Last Edit: April 18, 2018, 10:15:52 am by howardpc »

Thaddy

  • Hero Member
  • *****
  • Posts: 5987
Re: Pascal's set size limit
« Reply #5 on: April 18, 2018, 10:02:48 am »
In trunk there are  -in generic.collections -generic sets that can contain an arbitrary number of elements and support set operations.
I might not give the answer that you want me to.. Peter Green 1969

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus