mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-04-06 10:07:54 +02:00
* Use dyn array for bitset
This commit is contained in:
parent
c74c4ad9ad
commit
58df41dcf0
@ -453,6 +453,7 @@ type
|
|||||||
Next : pdynamicblock;
|
Next : pdynamicblock;
|
||||||
data : tdynamicblockdata;
|
data : tdynamicblockdata;
|
||||||
end;
|
end;
|
||||||
|
tdynamicblockarray = array of tdynamicblock;
|
||||||
|
|
||||||
const
|
const
|
||||||
dynamicblockbasesize = sizeof(tdynamicblock)-sizeof(tdynamicblockdata);
|
dynamicblockbasesize = sizeof(tdynamicblock)-sizeof(tdynamicblockdata);
|
||||||
@ -566,10 +567,12 @@ type
|
|||||||
tbitset
|
tbitset
|
||||||
*******************************************************************}
|
*******************************************************************}
|
||||||
|
|
||||||
|
{ tbitset }
|
||||||
|
|
||||||
tbitset = class
|
tbitset = class
|
||||||
private
|
private
|
||||||
fdata: pbyte;
|
fdata: TByteDynArray;
|
||||||
fdatasize: longint;
|
function getdatasize: longint;
|
||||||
public
|
public
|
||||||
constructor create(initsize: longint);
|
constructor create(initsize: longint);
|
||||||
constructor create_bytesize(bytesize: longint);
|
constructor create_bytesize(bytesize: longint);
|
||||||
@ -586,8 +589,8 @@ type
|
|||||||
procedure addset(aset: tbitset);
|
procedure addset(aset: tbitset);
|
||||||
procedure subset(aset: tbitset);
|
procedure subset(aset: tbitset);
|
||||||
|
|
||||||
property data: pbyte read fdata;
|
property data: TByteDynArray read fdata;
|
||||||
property datasize: longint read fdatasize;
|
property datasize: longint read getdatasize;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
@ -3228,6 +3231,11 @@ end;
|
|||||||
tbitset
|
tbitset
|
||||||
****************************************************************************}
|
****************************************************************************}
|
||||||
|
|
||||||
|
function tbitset.getdatasize: longint;
|
||||||
|
begin
|
||||||
|
result:=length(fdata);
|
||||||
|
end;
|
||||||
|
|
||||||
constructor tbitset.create(initsize: longint);
|
constructor tbitset.create(initsize: longint);
|
||||||
begin
|
begin
|
||||||
create_bytesize((initsize+7) div 8);
|
create_bytesize((initsize+7) div 8);
|
||||||
@ -3236,30 +3244,27 @@ end;
|
|||||||
|
|
||||||
constructor tbitset.create_bytesize(bytesize: longint);
|
constructor tbitset.create_bytesize(bytesize: longint);
|
||||||
begin
|
begin
|
||||||
fdatasize:=bytesize;
|
setLength(fdata,bytesize);
|
||||||
getmem(fdata,fdataSize);
|
|
||||||
clear;
|
clear;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
destructor tbitset.destroy;
|
destructor tbitset.destroy;
|
||||||
begin
|
begin
|
||||||
freemem(fdata,fdatasize);
|
fdata:=Nil;
|
||||||
inherited destroy;
|
inherited destroy;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
procedure tbitset.clear;
|
procedure tbitset.clear;
|
||||||
begin
|
begin
|
||||||
fillchar(fdata^,fdatasize,0);
|
fillchar(fdata[0],length(fdata),0);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
procedure tbitset.grow(nsize: longint);
|
procedure tbitset.grow(nsize: longint);
|
||||||
begin
|
begin
|
||||||
reallocmem(fdata,nsize);
|
setlength(fdata,nsize);
|
||||||
fillchar(fdata[fdatasize],nsize-fdatasize,0);
|
|
||||||
fdatasize:=nsize;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user