?? unit1.pas
字號:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
AHMTOfficeButton, StdCtrls, AHMTLabel, Grids, AHMTBackground,
AHMControls, AHMTFillBackground;
const m=256;
type
chen=array[0..m]of integer;
TForm1 = class(TForm)
AHMFillBackground1: TAHMFillBackground;
AHMBackground1: TAHMBackground;
StringGrid1: TStringGrid;
AHMLabel1: TAHMLabel;
AHMLabel2: TAHMLabel;
AHMLabel3: TAHMLabel;
AHMLabel4: TAHMLabel;
AHMLabel5: TAHMLabel;
AHMLabel6: TAHMLabel;
AHMLabel7: TAHMLabel;
AHMLabel8: TAHMLabel;
AHMLabel9: TAHMLabel;
AHMLabel10: TAHMLabel;
AHMLabel11: TAHMLabel;
AHMLabel12: TAHMLabel;
AHMOfficeButton1: TAHMOfficeButton;
procedure create_a(var a:chen);
procedure fifo(c:chen;block:integer;wai:integer);
procedure lru(c:chen;block:integer;wai:integer);
procedure opt(c:chen;block:integer);
function power(wai:integer):integer;
procedure main(var c:chen;a:chen);
procedure AHMOfficeButton1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
a,c:chen;
implementation
{$R *.DFM}
procedure tform1.create_a(var a:chen);
const n=10000;
var
i,r:integer;
begin
a[0]:=n;{rukoudizhi}
randomize;
for i:=1 to m do
begin
r:=random(1024);
if (0<=r)and(r<=512)
then a[i]:=a[i-1]+1 {order}
else if (512<r)and(r<=768)
then a[i]:=random(a[i-1]-1)+1 {forword}
else if (768<r)and(r<=1024)
then a[i]:=a[i-1]+random(30720-a[i-1]-1)+1;{forback}
end;
end;
{***************************************************************************}
procedure tform1.fifo(c:chen;block:integer;wai:integer);
type
chenke=record
value:integer;
age:integer;
end;
var
i,j,queye,wzz,wu,i1,k,zhonghe:integer;
block1:array[1..30]of chenke;
begin
queye:=0;
for i:= 1 to 30 do block1[i].value:=-1;
for i:= 1 to 30 do block1[i].age:=0;
for i:=0 to m do
begin
wu:=0;
if c[i]<>-1 then
begin
for j:=1 to block do
begin
if c[i]=block1[j].value then break;
if c[i]<>block1[j].value then wu:=wu+1;
end;
if wu=block then {find_max();}
begin
for k:=1 to block do block1[k].age:=block1[k].age+1;
wzz:=block1[1].age;
i1:=1;
for k:=2 to block do
begin
if block1[k].age>wzz then
begin
wzz:=block1[k].age;
i1:=k;{i1:queyexuhao}
end;
end;
block1[i1].age:=0;
block1[i1].value:=c[i];
queye:=queye+1;
end;
end;
end;
zhonghe:=0;
for i:=0 to m do if c[i]<>-1 then zhonghe:=zhonghe+1;
StringGrid1.Cells[wai,block]:=floattostr(queye/zhonghe);
end;
{***************************************************************************}
procedure tform1.lru(c:chen;block:integer;wai:integer);
type
chenke=record
value:integer;
visit:integer;
end;
var
block1:array[1..30]of chenke;
i,j,queye,wu,wzz,i1,k,zhonghe:integer;
begin
queye:=0;
for i:= 1 to 30 do block1[i].value:=-1;
for i:= 1 to 30 do block1[i].visit:=0;
for i:=0 to m do
begin
wu:=0;
if c[i]<>-1 then
begin
for j:=1 to block do
begin
if c[i]=block1[j].value then
begin
block1[j].visit:=block1[j].visit+1;
break;
end;
if c[i]<>block1[j].value then wu:=wu+1;
end;
if wu=block then
begin
wzz:=block1[1].visit;
i1:=1;
for k:=2 to block do
begin
if block1[k].visit<wzz then
begin
wzz:=block1[k].visit;
i1:=k;{i1:queyexuhao}
end;
end;
block1[i1].visit:=1;
block1[i1].value:=c[i];
queye:=queye+1;
end;
end;
end;
zhonghe:=0;
for i:=0 to m do if c[i]<>-1 then zhonghe:=zhonghe+1;
StringGrid1.Cells[wai+1,block]:=floattostr(queye/zhonghe);
end;
{***************************************************************************}
procedure tform1.opt(c:chen;block:integer);
begin
end;
{***************************************************************************}
function tform1.power(wai:integer):integer;
begin
case wai of
1:power:=1;
2:power:=2;
3:power:=4;
4:power:=8;
end;
end;
{***************************************************************************}
procedure tform1.main(var c:chen;a:chen);
var
wai,ye,i,r:integer;
b:chen;
begin
wai:=1; {the forgien cycle parameter}
{ ye:=1024;the size of leaf}
for i:=1 to m do c[i]:=-1;
{the leaf array which is not repeat}
repeat
ye:=1024*power(wai);
for i:=0 to m do b[i]:=trunc(a[i]/ye);{get the repeated leaf}
r:=0;{the parameter of c[]}
c[r]:=b[r];
for i:=1 to m do
begin
if c[r]<>b[i] then
begin
r:=r+1;
c[r]:=b[i];
end;
end; {set the b[i],let c[i] became unique}
for i :=1 to 30 do fifo(c,i,(wai-1)*3);
for i :=1 to 30 do lru(c,i,(wai-1)*3);
for i :=1 to 30 do opt(c,i);
wai:=wai+1;
until ye=8192;
end;
{***************************************************************************}
procedure TForm1.AHMOfficeButton1Click(Sender: TObject);
begin
create_a(a);
main(c,a);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
StringGrid1.Cells[0,0]:='1024';
StringGrid1.Cells[1,0]:='1024';
StringGrid1.Cells[2,0]:='1024';
StringGrid1.Cells[3,0]:='2048';
StringGrid1.Cells[4,0]:='2048';
StringGrid1.Cells[5,0]:='2048';
StringGrid1.Cells[6,0]:='4096';
StringGrid1.Cells[7,0]:='4096';
StringGrid1.Cells[8,0]:='4096';
StringGrid1.Cells[9,0]:='8192';
StringGrid1.Cells[10,0]:='8192';
StringGrid1.Cells[11,0]:='8192';
end;
end.
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -