summaryrefslogtreecommitdiff
path: root/fpcsrc/tests/bench/shootout/obsolete/lists.pp
blob: 0c421ad831b371859ace6feff04d9cd4aa6778c8 (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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
{ List Operations }

Program lists;

uses SysUtils, classes;

const SIZE : longint = 10000;

Function test_lists : integer;
var
    i, len1, len2 : longint;
    Li1, Li2, Li3 : TList;
    lists_equal : Integer;
begin

    Li1 := TList.Create;
    Li1.Capacity := SIZE;
    For i := 0 to SIZE Do
        Li1.Add(Pointer(i));



    Li2 := TList.Create;
    Li2.Capacity := SIZE;
    For i:= 0 to SIZE Do
        Li2.Add(Li1.Items[i]);

    { remove each individual item from left side of Li2 and
      append to right side of Li3 (preserving order) }
    Li3 := TList.Create;
    Li3.Capacity := SIZE;
    For i := 0 to SIZE Do
    begin
        Li3.Add( Li2.First );
        Li2.Remove( Li2.First );
    end;


    { remove each individual item from right side of Li3 and
      append to right side of Li2 (reversing list) }
    For i := 0 To SIZE Do
    begin
        Li2.Add( Li3.Last );
        Li3.Count -= 1;
    end;




    For i := 0 To (SIZE div 2) Do
    begin
        Li1.Exchange( i, SIZE-i );
    end;


    If longint(Li1.first) <> SIZE Then
    begin

        test_lists := 0;
        exit;
    end;


    len1 := Li1.Count - 1;
    len2 := Li2.Count - 1;
    If  len1 <> len2 Then
    begin
        test_lists := 0;
        exit;
    end;

    lists_equal := 1;
    For i := 0 To len1 Do
    begin
        If longint(Li1.items[i]) <> longint(Li2.items[i]) Then
        begin
            lists_equal := 0;
            break;
        end;
    end;

    If lists_equal = 0 Then
    begin
        test_lists := 0;
    end
    else
        test_lists := len1;
end;

var
    ITER, i, result: integer;

begin
    if ParamCount = 0 then
        ITER := 1
    else
        ITER := StrToInt(ParamStr(1));

    if ITER < 1 then ITER := 1;

    For i := 1 To ITER Do result := test_lists();
    Writeln (IntToStr(result));

end.