Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


ID: 14018, Counting number of elements in a set

by Robert Lee Email: rhlee@optimalcode.com


Download Details
FTP  download also available 0 bytes
CDN Login Required to Download. (You will be redirected to the login page if you click on the Download Link)
To download this, you must have registered:
A free membership

For Delphi, Version 1.0  to 1.0 23 downloads
Copyright: No significant restrictions


Size: 0 bytes
Updated on Thu, 11 Nov 1999 00:00:00 GMT
Originally uploaded on Thu, 11 Nov 1999 00:00:00 GMT
Description
This routine will count the number of elements contained within a set. Alternatively it can be used to count the number of bits set in a structure of any length. -----------------------
function card(var tar; size: integer): integer;
// Returns the number of bits set in the Size bytes starting from Tar.
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;
Usage:
Var
  mySet: TsomeSetType;
begin
...
  myCount := card(mySet, sizeof(mySet));
...
end;

   Latest Comments  View All Add New

Move mouse over comment to see the full text

Could not retrieve comments. Please try again later.

Server Response from: ETNACDC03