I'm programming in Pascal and I'm trying to find if is there any already created function/procedure in the standard library or similar that allows me to know how many elements a set has?
I know how to do it by using a for loop and a counter increasing +1 when it finds an element (similar to what it has to be done when you want to print a set) but I was wondering if is there any other easier way of doing it, like I said, some predefined standard function/procedure?
If your sets are 1,2,4 or 8 byte, one can use the recently introduced popcnt intrinsic.
This intrinsic is in system, but only in trunk (2.7.1)
function PopCnt(Const AValue: Byte): Byte;[internproc:fpc_in_popcnt_x];
function PopCnt(Const AValue: Word): Word;[internproc:fpc_in_popcnt_x];
function PopCnt(Const AValue : DWord): DWord;[internproc:fpc_in_popcnt_x];
function PopCnt(Const AValue : QWord): QWord;[internproc:fpc_in_popcnt_x];
The reason must probably be sought more in speeding up encryption/compression algorithms though, rather than classic sets.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With