Thema: Delphi 2 dimensionale sets?

Einzelnen Beitrag anzeigen

Benutzerbild von 3_of_8
3_of_8

Registriert seit: 22. Mär 2005
Ort: Dingolfing
4.129 Beiträge
 
Turbo Delphi für Win32
 
#9

Re: 2 dimensionale sets?

  Alt 16. Mär 2008, 17:54
Ein Bitvektor ist im Prinzip das, was die Pascal/Delphi-Sets machen oder auch die Klasse TBits: Man benutzt einfach einzelne Bits, um einen Boolean-Wert zu speichern.

In einem 32-Bit-Cardinal hat man z.B. 32 Bits, kann also 32 Booleans darin kodieren. Realisiert wird das über die binären Operatoren von Delphi.

Zum Abfragen eines Bits verwendet man sowas:

Delphi-Quellcode:
function GetBit(const Vector, Index: Cardinal): Boolean;
begin
  Result:=Vector and (1 shl Index)>0;
end;
Und zum Setzen:

Delphi-Quellcode:
procedure SetBit(var Vector: Cardinal; const Index: Cardinal; const Value: Boolean);
begin
  if Value then
    Vector:=Vector or (1 shl Index)
  else
    Vector:=Vector and not (1 shl Index);
end;
Manuel Eberl
„The trouble with having an open mind, of course, is that people will insist on coming along and trying to put things in it.“
- Terry Pratchett
  Mit Zitat antworten Zitat