Changeset 77 for Generics/TemplateGenerics/Generic
- Timestamp:
- Oct 29, 2010, 1:26:32 PM (14 years ago)
- Location:
- Generics/TemplateGenerics/Generic
- Files:
-
- 2 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
Generics/TemplateGenerics/Generic/ListImplementation.tpl
r76 r77 109 109 end; 110 110 111 function TGList.IndexOf(Item: TListItem ): TListIndex;112 begin 113 Result := 0;111 function TGList.IndexOf(Item: TListItem; Start: TListIndex): TListIndex; 112 begin 113 Result := Start; 114 114 while (Result < FCount) and 115 115 not CompareMem(Addr(FItems[Result]), Addr(Item), SizeOf(TListItem)) do … … 138 138 I := I + 1; 139 139 end; 140 end; 141 142 function TGList.IndexOfList(List: TGList; Start: TListIndex): TListIndex; 143 var 144 I: TListIndex; 145 begin 146 if List.Count > 0 then begin 147 Result := IndexOf(List[0], Start); 148 if Result <> -1 then begin 149 I := 1; 150 while I < List.Count do begin 151 if not CompareMem(Addr(FItems[Result + I]), Addr(List.FItems[I]), SizeOf(TListItem)) then begin 152 Result := -1; 153 Break; 154 end; 155 I := I + 1; 156 end; 157 end; 158 end else Result := -1; 140 159 end; 141 160 … … 200 219 end; 201 220 202 (*function TGList.Equals(Obj: TObject): Boolean;203 var 204 I: TListIndex; 205 begin 206 Result := Count = (Obj as TGList).Count;221 function TGList.Equals(List: TGList): Boolean; 222 var 223 I: TListIndex; 224 begin 225 Result := Count = List.Count; 207 226 if Result then begin 208 227 I := 0; 209 228 while I < Count do begin 210 if Items[I] <> (Obj as TGList)[I]then begin229 if not CompareMem(Addr(FItems[I]), Addr(List.FItems[I]), SizeOf(TListItem)) then begin 211 230 Result := False; 212 231 Break; … … 215 234 end; 216 235 end; 217 end; *)236 end; 218 237 219 238 procedure TGList.Reverse; … … 241 260 while I <= High(Values) do begin 242 261 Add(Values[I]); 262 I := I + 1; 263 end; 264 end; 265 266 procedure TGList.SetArray(Values: array of TListItem); 267 var 268 I: TListIndex; 269 begin 270 Clear; 271 I := 0; 272 while I <= High(Values) do begin 273 Add(Values[I]); 274 I := I + 1; 275 end; 276 end; 277 278 procedure TGList.InsertArray(Index: TListIndex; Values: array of TListItem); 279 var 280 I: TListIndex; 281 begin 282 I := 0; 283 while I <= High(Values) do begin 284 Insert(Index + I, Values[I]); 243 285 I := I + 1; 244 286 end; … … 255 297 if I < (Count - 1) then 256 298 Result := Result + Separator; 299 I := I + 1; 300 end; 301 end; 302 303 procedure TGList.Perform(Operation: TGListOperation); 304 var 305 I: TListIndex; 306 begin 307 I := 0; 308 while I < Count do begin 309 Operation(Self, @FItems[I]); 257 310 I := I + 1; 258 311 end; … … 309 362 end; 310 363 364 procedure TGList.Fill(Start, Count: TListIndex; Value: TListItem); 365 begin 366 while Count > 0 do begin 367 Items[Start] := Value; 368 Count := Count - 1; 369 Start := Start + 1; 370 end; 371 end; 372 311 373 procedure TGList.Exchange(Index1, Index2: TListIndex); 312 374 var -
Generics/TemplateGenerics/Generic/ListInterface.tpl
r74 r77 1 2 PGListItem = ^TListItem; 3 TGList = class; 1 4 2 5 TGListSortCompare = function(const Item1, Item2: TListItem): Integer of object; 3 6 TGListStringConverter = function(Item: TListItem): string; 7 TGListOperation = procedure(List: TGList; Item: PGListItem); 4 8 //TGListNotification = (lnAdded, lnExtracted, lnDeleted); 5 9 … … 16 20 procedure SetCount(const AValue: TListIndex); 17 21 procedure QuickSort(L, R : TListIndex; Compare: TGListSortCompare); 18 property Capacity: TListIndex read GetCapacity write SetCapacity;19 22 public 20 23 // All items … … 24 27 procedure Sort(Compare: TGListSortCompare); 25 28 function Implode(Separator: string; Converter: TGListStringConverter): string; 29 procedure Perform(Operation: TGListOperation); 26 30 // Many items 27 31 procedure MoveItems(CurIndex, NewIndex, Count: TListIndex); 28 32 procedure DeleteItems(Index, Count: TListIndex); 33 procedure Fill(Start, Count: TListIndex; Value: TListItem); 29 34 // One item 30 35 function Add(Item: TListItem): TListIndex; … … 33 38 procedure Exchange(Index1, Index2: TListIndex); 34 39 function First: TListItem; 35 function IndexOf(Item: TListItem ): TListIndex;40 function IndexOf(Item: TListItem; Start: TListIndex = 0): TListIndex; 36 41 procedure Insert(Index: TListIndex; Item: TListItem); 37 42 function Last: TListItem; … … 42 47 procedure AddList(List: TGList); 43 48 procedure Assign(List: TGList); 44 //function Equals(Obj: TObject): Boolean; override;49 function Equals(List: TGList): Boolean; 45 50 procedure InsertList(Index: TListIndex; List: TGList); 51 function IndexOfList(List: TGList; Start: TListIndex = 0): TListIndex; 46 52 // Other 47 53 property Count: TListIndex read GetCount write SetCount; 48 // Additional 54 property Capacity: TListIndex read GetCapacity write SetCapacity; 55 // Array 49 56 procedure AddArray(Values: array of TListItem); 57 procedure SetArray(Values: array of TListItem); 58 procedure InsertArray(Index: TListIndex; Values: array of TListItem); 50 59 end; -
Generics/TemplateGenerics/Generic/SetImplementation.tpl
r76 r77 3 3 { TGSet } 4 4 5 function TGSet.IsIn(Item: TSetItem): Boolean; 6 begin 7 Result := FList.IndexOf(Item) <> -1; 8 end; 5 9 10 constructor TGSet.Create; 11 begin 12 FList := TGList.Create; 13 end; 6 14 15 destructor TGSet.Destroy; 16 begin 17 FList.Free; 18 inherited Destroy; 19 end;
Note:
See TracChangeset
for help on using the changeset viewer.