Article

From:
To:
Philippe Ranger
Subject:
Re: Cardinality of a set
Newsgroup:
borland.public.delphi.objectpascal

Re: Cardinality of a set



Philippe Ranger wrote:
> 
> <<Bob:
> Besides, it would seem that wrapping around the best of the
> "bitsInByte" solutions would be both faster and less cumbersome.
> >>
> 
> Perhaps, but that involves one call per byte. 

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.

function card1(var tar; size: integer): integer; const   nibbleTable:array[0..15] of integer=( 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4); var   Data:PByteArray;   i,b:integer; begin   result:=0;   Data:=@TByteArray(tar)[size];   i:=-size;   while i<0 do   begin     b:=Data[i];     inc(result,NibbleTable[b and $F]+NibbleTable[(b shr 4) and $F]);     inc(i);   end; end;

-- Bob Lee High Performance Delphi - http://www.econos.com/optimize/ Updated August 2
FYI: Phrase searches are enclosed in either single or double quotes
 
 
Originally created by
Tamarack Associates
Tue, 26 Nov 2024 11:25:14 UTC
Copyright © 2009-2024
HREF Tools Corp.