Size of a set 
Author Message
 Size of a set

Hallo allemaal,

I building a small computer meant for 6502-computers like the C64 and
VIC-20. I ran into the following problem. When defining a variable as
a string, char, record, array etc, the datasize increases with the
size of thing. But when defining a "set of ...." then the size only
increases with two. I expected the size to be increased with the
number of items of the original set.

So how is a "set of ...." stored?

Thanks for any answer.

--
    ___
   / __|__
  / /  |_/     Groetjes, Ruud
  \ \__|_\
   \___|       http://www.*-*-*.com/



Sat, 23 Apr 2005 19:35:38 GMT  
 Size of a set


Quote:
> Hallo allemaal,

> I building a small computer meant for 6502-computers like the C64 and
> VIC-20. I ran into the following problem. When defining a variable as
> a string, char, record, array etc, the datasize increases with the
> size of thing. But when defining a "set of ...." then the size only
> increases with two. I expected the size to be increased with the
> number of items of the original set.

> So how is a "set of ...." stored?

> Thanks for any answer.

A set is just a bitmap of the size to hold the number of values in
the set.  The number of bytes for a set of size n is (n+7) div 8.

Also in Turbo/Borland Pascal the set numbers are limited to
256 (0-255) so the maximum memory requirements is 32 bytes.

I imagine this value can be offset (which I've never done) as in:

var
    SomeSet : set of MinSetValue..MaxSetValue;

Where MaxSetValue - MinSetValue < 256

95% of the time I've used it, was for character checking, e.g.

  const
        Vowels: set of char = ['A','E','I','O','U','Y','a','e','i','o','u','y'];

var
    ch: char;

if ch in Vowels then ...

Rufus



Sat, 23 Apr 2005 23:53:05 GMT  
 Size of a set



Quote:
>A set is just a bitmap of the size to hold the number of values in
>the set.  The number of bytes for a set of size n is (n+7) div 8.

Over-simplified.     A set of 7..8   needs 2 bytes.  The LS 3B of the
item number selects bit within byte, the MS 5B selects byte.  Un-needed
bytes are not allocated (except for sets in Delphi which by the above
need 3 bytes).

Quote:
>Also in Turbo/Borland Pascal the set numbers are limited to
>256 (0-255) so the maximum memory requirements is 32 bytes.

>I imagine this value can be offset (which I've never done) as in:

>var
>    SomeSet : set of MinSetValue..MaxSetValue;

I think not.

--

  <URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/&c., FAQqy topics & links;
  <URL:http://www.merlyn.demon.co.uk/clpb-faq.txt> Pedt Scragg: c.l.p.b. mFAQ;
  <URL:ftp://garbo.uwasa.fi/pc/link/tsfaqp.zip> Timo Salmi's Turbo Pascal FAQ.



Sun, 24 Apr 2005 04:35:28 GMT  
 Size of a set



Quote:



> >A set is just a bitmap of the size to hold the number of values in
> >the set.  The number of bytes for a set of size n is (n+7) div 8.

> Over-simplified.     A set of 7..8   needs 2 bytes.  The LS 3B of the
> item number selects bit within byte, the MS 5B selects byte.  Un-needed
> bytes are not allocated (except for sets in Delphi which by the above
> need 3 bytes).

> >Also in Turbo/Borland Pascal the set numbers are limited to
> >256 (0-255) so the maximum memory requirements is 32 bytes.

> >I imagine this value can be offset (which I've never done) as in:

> >var
> >    SomeSet : set of MinSetValue..MaxSetValue;

> I think not.

Right you are, Dr. John!  That'll teach me for guessing without testing.

While array indices are offset by the lower value used in the definition, set arguments
are not!

(The Lesson: Don't run off believing the first reply you get in Usenet...)

Rufus



Sun, 24 Apr 2005 08:02:11 GMT  
 Size of a set


Quote:
>While array indices are offset by the lower value used in the definition, set
>arguments
>are not!

You can consider sets as being arrays of bits, with a fixed dimension. A set of
10000..10002 is equivalent to an array[10000..10002] of bit (or boolean). As
for fixed size arrays, the size and starting index is not stored in memory.

DoDi



Sun, 24 Apr 2005 11:57:53 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. setting block size with ttable.createtable

2. Setting Rowset size during runtime

3. Setting up memo field size

4. size of sets in FPC vs TP

5. Setting Paper Sizes And Bins seems to have a problem on HP 1000C

6. Setting Paper Sizes And Bins seems to have a problem on HP 1000C

7. size of sets

8. Setting the Paper size on the printer.

9. Set window size?

10. Multi Dimentional Arrays - Setting Variable Size ??

11. Paradox and Block Size setting

12. Paradox Block Size Setting in BDE Administrator

 

 
Powered by phpBB® Forum Software