summaryrefslogtreecommitdiff
path: root/fpcsrc/utils/fppkg/lnet/lcontainers.inc
blob: 7f9d6723036d12676913a63e12c7cc6900a7ccc0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
constructor TLFront.Create(const DefaultItem: __front_type__);
begin
  FEmptyItem:=DefaultItem;
  Clear;
end;

function TLFront.GetEmpty: Boolean;
begin
  Result:=FCount = 0;
end;

function TLFront.First: __front_type__;
begin
  Result:=FEmptyItem;
  if FCount > 0 then
    Result:=FItems[FBottom];
end;

function TLFront.Remove: __front_type__;
begin
  Result:=FEmptyItem;
  if FCount > 0 then begin
    Result:=FItems[FBottom];
    Dec(FCount);
    Inc(FBottom);
    if FBottom >= MAX_FRONT_ITEMS then
      FBottom:=0;
  end;
end;

function TLFront.Insert(const Value: __front_type__): Boolean;
begin
  Result:=False;
  if FCount < MAX_FRONT_ITEMS then begin
    if FTop >= MAX_FRONT_ITEMS then
      FTop:=0;
    FItems[FTop]:=Value;
    Inc(FCount);
    Inc(FTop);
    Result:=True;
  end;
end;

procedure TLFront.Clear;
begin
  FCount:=0;
  FBottom:=0;
  FTop:=0;
end;