Changeset 78 for Generics/TemplateGenerics/Generic
- Timestamp:
- Oct 30, 2010, 6:39:12 PM (14 years ago)
- Location:
- Generics/TemplateGenerics/Generic
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
Generics/TemplateGenerics/Generic/ListImplementation.tpl
r77 r78 17 17 begin 18 18 Result := FItems[Index]; 19 end;20 21 function TGList.GetCount: TListIndex;22 begin23 Result := FCount;24 19 end; 25 20 … … 89 84 end; 90 85 86 procedure TGList.Contract; 87 begin 88 if (Capacity > 256) and (FCount < Capacity shr 2) then 89 begin 90 Capacity := Capacity shr 1; 91 end; 92 end; 93 91 94 function TGList.Extract(Item: TListItem): TListItem; 92 95 var … … 344 347 FCount := FCount - 1; 345 348 System.Move(FItems[Index + 1], FItems[Index], (FCount - Index) * SizeOf(TListItem)); 346 // Shrink the list if appropriate 347 if (Capacity > 256) and (FCount < Capacity shr 2) then 348 begin 349 Capacity := Capacity shr 1; 350 end; 349 Contract; 351 350 end; 352 351 -
Generics/TemplateGenerics/Generic/ListInterface.tpl
r77 r78 14 14 FCount: TListIndex; 15 15 function Get(Index: TListIndex): TListItem; 16 function GetCount: TListIndex;17 16 function GetCapacity: TListIndex; 18 17 procedure SetCapacity(const AValue: TListIndex); 19 procedure Put(Index: TListIndex; const AValue: TListItem); 18 procedure Put(Index: TListIndex; const AValue: TListItem); virtual; 20 19 procedure SetCount(const AValue: TListIndex); 21 20 procedure QuickSort(L, R : TListIndex; Compare: TGListSortCompare); … … 23 22 // All items 24 23 procedure Reverse; 25 procedure Clear; 24 procedure Clear; virtual; 26 25 procedure Expand; 26 procedure Contract; 27 27 procedure Sort(Compare: TGListSortCompare); 28 28 function Implode(Separator: string; Converter: TGListStringConverter): string; … … 34 34 // One item 35 35 function Add(Item: TListItem): TListIndex; 36 procedure Delete(Index: TListIndex); 36 procedure Delete(Index: TListIndex); virtual; 37 37 function Extract(Item: TListItem): TListItem; 38 38 procedure Exchange(Index1, Index2: TListIndex); … … 51 51 function IndexOfList(List: TGList; Start: TListIndex = 0): TListIndex; 52 52 // Other 53 property Count: TListIndex read GetCount write SetCount;53 property Count: TListIndex read FCount write SetCount; 54 54 property Capacity: TListIndex read GetCapacity write SetCapacity; 55 55 // Array
Note:
See TracChangeset
for help on using the changeset viewer.