Revision | 265 (tree) |
---|---|
Zeit | 2016-05-30 02:02:34 |
Autor | twm |
moved to dzlib
@@ -1,89 +0,0 @@ | ||
1 | -unit u_Int64List; | |
2 | - | |
3 | -interface | |
4 | - | |
5 | -uses | |
6 | - SysUtils, | |
7 | - Classes, | |
8 | - u_dzTranslator; | |
9 | - | |
10 | -type | |
11 | - ///<summary> | |
12 | - /// A List for storing Int64 values | |
13 | - /// Note: If you use Add to add a huge amount of items to the list, you will | |
14 | - /// likely get an EOutOfMemory exception before actually running out of memory | |
15 | - /// because of memory framentation. If you know how many items you want to | |
16 | - /// store, set Capacity to that number. Capacity can be set to a maximum of | |
17 | - /// Classes.MaxListSize which means the list takes up around 1 GB of memory. </summary> | |
18 | - TInt64List = class | |
19 | - private | |
20 | - FData: array of Int64; | |
21 | - FCapacity: integer; | |
22 | - FCount: integer; | |
23 | - procedure Grow; | |
24 | - procedure SetCapacity(_NewCapacity: integer); | |
25 | - function GetItems(_Idx: integer): Int64; | |
26 | - procedure SetItems(_Idx: integer; const _Value: Int64); | |
27 | - public | |
28 | - function Add(_Value: Int64): integer; | |
29 | - property Items[_Idx: integer]: Int64 read GetItems write SetItems; | |
30 | - property Capacity: integer read FCapacity write SetCapacity; | |
31 | - property Count: integer read FCount; | |
32 | - end; | |
33 | - | |
34 | -implementation | |
35 | - | |
36 | -{ TInt64List } | |
37 | - | |
38 | -function TInt64List.Add(_Value: Int64): integer; | |
39 | -begin | |
40 | - Result := FCount; | |
41 | - if Result = FCapacity then | |
42 | - Grow; | |
43 | - FData[Result] := _Value; | |
44 | - Inc(FCount); | |
45 | -end; | |
46 | - | |
47 | -procedure TInt64List.Grow; | |
48 | -var | |
49 | - Delta: integer; | |
50 | -begin | |
51 | - if FCapacity > 64 then | |
52 | - Delta := FCapacity div 4 | |
53 | - else if FCapacity > 8 then | |
54 | - Delta := 16 | |
55 | - else | |
56 | - Delta := 4; | |
57 | - SetCapacity(FCapacity + Delta); | |
58 | -end; | |
59 | - | |
60 | -procedure TInt64List.SetCapacity(_NewCapacity: integer); | |
61 | -begin | |
62 | - if _NewCapacity <> FCapacity then begin | |
63 | - if (_NewCapacity < FCount) then | |
64 | - raise Exception.CreateFmt(_('Cannot set list capacity (%d) to less than current item count (%d).'), | |
65 | - [_NewCapacity, FCount]); | |
66 | - if (_NewCapacity > MaxListSize) then | |
67 | - raise Exception.CreateFmt(_('Cannot set list capacity (%d) higher than MaxListSize (%d).'), | |
68 | - [_NewCapacity, MaxListSize]); | |
69 | - | |
70 | - SetLength(FData, _NewCapacity); | |
71 | - FCapacity := _NewCapacity; | |
72 | - end; | |
73 | -end; | |
74 | - | |
75 | -function TInt64List.GetItems(_Idx: integer): Int64; | |
76 | -begin | |
77 | - if (_Idx < 0) or (_Idx >= FCount) then | |
78 | - raise Exception.CreateFmt(_('List index out of bounds (%d) (Count=%d)'), [_Idx, FCount]); | |
79 | - Result := FData[_Idx]; | |
80 | -end; | |
81 | - | |
82 | -procedure TInt64List.SetItems(_Idx: integer; const _Value: Int64); | |
83 | -begin | |
84 | - if (_Idx < 0) or (_Idx >= FCount) then | |
85 | - raise Exception.CreateFmt(_('List index out of bounds (%d) (Count=%d)'), [_Idx, FCount]); | |
86 | - FData[_Idx] := _Value; | |
87 | -end; | |
88 | - | |
89 | -end. |