[fpc-pascal] Set size limit
Sven Barth
pascaldragon at googlemail.com
Mon Mar 11 14:52:26 CET 2013
Am 11.03.2013 14:43, schrieb Jonas Maebe:
>
> On 11 Mar 2013, at 14:32, Daniel Gaspary wrote:
>
>> In my case the enum has near 600 elements.
>>
>> TMyEnum = (me1, me2...);
>>
>> The set though would never be used to contain more than 256.
>>
>> TMySet = set of TMyEnum;
>>
>> Is it not viable to modify the compiler to compile the code and raise
>> an exception if I try to add more than 256 elements to the set ?
>
> A set is basically a bitpacked array of boolean. Element X is set to
> true if you add X to the set, and to false if you remove it again.
> That means that if you have a set with 600 possible values, you need
> at least 600 bits, regardless of how many elements are inside it.
>
> The above also shows an alternative to sets in that case: you can use
> a bitpacked array[TMyEnum] of boolean instead. Of course, then you
> can't use the regular set operators.
If the array is a named one (e.g. "TMyArraySet = bitpacked
array[TMyEnum] of Boolean") then operator overloading could be used...
Regards,
Sven
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20130311/584ea682/attachment.html>
More information about the fpc-pascal
mailing list