<<Bob: By wrap I meant put the code inside a loop. This is between 1.7 and 3x faster depending on the size of the set on a PII, and it uses your BitsInByte Nibble algorithm crushed into one pascal expression. >>
This is getting embarrassing!
To get your code to compile with typed @, I had to replace your Data assignment with --
Data:=PbyteArray(@TByteArray(tar)[size]);
(I've been bitten recently with just kind of problem, untyped @ on an indexed array.)
It looks like you worked on this. Can I ask --
-- Why not a For loop?
-- Why scan down the array?
-- Why use the var b? Is using this buffercheaper than doing a second indexed access to the same spot?
In other words, what if this was --
---------- function card2(var tar; size: integer): integer; const (*nibble table*) Ca: array[0..15] of integer=( 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4); var ab: TbyteArray absolute tar; j: integer; begin result:=0; for j := 0 to size - 1 do begin inc(result, Ca[ab[j] and $F] + Ca[ab[j] shr 4]); end; end; --------------------
PhR