Changeset 313
- Timestamp:
- Jan 9, 2012, 4:03:09 PM (13 years ago)
- Location:
- Generics/NativeGenerics
- Files:
-
- 10 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
Generics/NativeGenerics/NativeGenerics.lpk
r132 r313 1 1 <?xml version="1.0"?> 2 2 <CONFIG> 3 <Package Version=" 3">3 <Package Version="4"> 4 4 <PathDelim Value="\"/> 5 5 <Name Value="NativeGenerics"/> 6 <AddToProjectUsesSection Value="True"/> 6 7 <Author Value="Chronos"/> 7 8 <CompilerOptions> 8 <Version Value=" 9"/>9 <Version Value="11"/> 9 10 <PathDelim Value="\"/> 10 11 <SearchPaths> 11 12 <OtherUnitFiles Value="Units"/> 12 <UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS) \"/>13 <UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/> 13 14 </SearchPaths> 14 15 <CodeGeneration> … … 27 28 <License Value="GNU/GPL"/> 28 29 <Version Minor="1"/> 29 <Files Count=" 8">30 <Files Count="11"> 30 31 <Item1> 31 32 <Filename Value="ReadMe.txt"/> … … 60 61 <UnitName Value="GenericStack"/> 61 62 </Item8> 63 <Item9> 64 <Filename Value="Units\GenericMatrix.pas"/> 65 <UnitName Value="GenericMatrix"/> 66 </Item9> 67 <Item10> 68 <Filename Value="Units\GenericStream.pas"/> 69 <UnitName Value="GenericStream"/> 70 </Item10> 71 <Item11> 72 <Filename Value="Units\SpecializedList.pas"/> 73 <UnitName Value="SpecializedList"/> 74 </Item11> 62 75 </Files> 63 76 <Type Value="RunAndDesignTime"/> -
Generics/NativeGenerics/NativeGenerics.pas
r132 r313 9 9 uses 10 10 GenericList, GenericTree, GenericDictionary, GenericQueue, GenericRange, 11 GenericSet, GenericStack, LazarusPackageIntf; 11 GenericSet, GenericStack, GenericMatrix, GenericStream, SpecializedList, 12 LazarusPackageIntf; 12 13 13 14 implementation -
Generics/NativeGenerics/Units/GenericList.pas
r132 r313 12 12 private 13 13 type 14 T GListIndex = Integer;14 TIndex = NativeInt; 15 15 TSortCompare = function(Item1, Item2: TItem): Integer of object; 16 16 TToStringConverter = function(Item: TItem): string; … … 19 19 var 20 20 FItems: array of TItem; 21 FCount: T GListIndex;22 function Get(Index: T GListIndex): TItem;23 function GetCapacity: T GListIndex;21 FCount: TIndex; 22 function Get(Index: TIndex): TItem; 23 function GetCapacity: TIndex; 24 24 function GetLast: TItem; 25 25 function GetFirst: TItem; 26 procedure SetCapacity(const AValue: T GListIndex);27 procedure SetCapacityOptimized(const NewCapacity: T GListIndex);26 procedure SetCapacity(const AValue: TIndex); 27 procedure SetCapacityOptimized(const NewCapacity: TIndex); 28 28 procedure SetLast(AValue: TItem); 29 29 procedure SetFirst(AValue: TItem); 30 procedure Put(Index: T GListIndex; const AValue: TItem); virtual;31 procedure SetCount(const AValue: T GListIndex); virtual;32 procedure QuickSort(L, R : T GListIndex; Compare: TSortCompare);30 procedure Put(Index: TIndex; const AValue: TItem); virtual; 31 procedure SetCount(const AValue: TIndex); virtual; 32 procedure QuickSort(L, R : TIndex; Compare: TSortCompare); 33 33 public 34 function Add(Item: TItem): T GListIndex;34 function Add(Item: TItem): TIndex; 35 35 procedure AddArray(Values: array of TItem); 36 36 procedure AddList(List: TGList); 37 37 procedure Assign(Source: TGList); virtual; 38 38 procedure Clear; virtual; 39 procedure Delete(Index: T GListIndex); virtual;40 procedure DeleteItems(Index, Count: T GListIndex);39 procedure Delete(Index: TIndex); virtual; 40 procedure DeleteItems(Index, Count: TIndex); 41 41 function EqualTo(List: TGList): Boolean; 42 procedure Exchange(Index1, Index2: T GListIndex);42 procedure Exchange(Index1, Index2: TIndex); 43 43 procedure Explode(Text, Separator: string; Converter: TFromStringConverter; SlicesCount: Integer = -1); 44 44 function Extract(Item: TItem): TItem; 45 45 property First: TItem read GetFirst write SetFirst; 46 procedure Fill(Start, Count: T GListIndex; Value: TItem);46 procedure Fill(Start, Count: TIndex; Value: TItem); 47 47 function GetArray: TItemArray; 48 48 function Implode(Separator: string; Converter: TToStringConverter): string; 49 function IndexOf(Item: TItem; Start: T GListIndex = 0): TGListIndex;50 function IndexOfList(List: TGList; Start: T GListIndex = 0): TGListIndex;51 procedure Insert(Index: T GListIndex; Item: TItem);52 procedure InsertList(Index: T GListIndex; List: TGList);53 procedure InsertArray(Index: T GListIndex; Values: array of TItem);54 procedure Move(CurIndex, NewIndex: T GListIndex);55 procedure MoveItems(CurIndex, NewIndex, Count: T GListIndex);56 function Remove(Item: TItem): T GListIndex;49 function IndexOf(Item: TItem; Start: TIndex = 0): TIndex; 50 function IndexOfList(List: TGList; Start: TIndex = 0): TIndex; 51 procedure Insert(Index: TIndex; Item: TItem); 52 procedure InsertList(Index: TIndex; List: TGList); 53 procedure InsertArray(Index: TIndex; Values: array of TItem); 54 procedure Move(CurIndex, NewIndex: TIndex); 55 procedure MoveItems(CurIndex, NewIndex, Count: TIndex); 56 function Remove(Item: TItem): TIndex; 57 57 procedure Reverse; 58 58 procedure Sort(Compare: TSortCompare); 59 procedure SetArray(Values: TItemArray);60 property Count: T GListIndex read FCount write SetCount;61 property Capacity: T GListIndex read GetCapacity write SetCapacity;62 property Items[Index: T GListIndex]: TItem read Get write Put; default;59 procedure SetArray(Values: array of TItem); 60 property Count: TIndex read FCount write SetCount; 61 property Capacity: TIndex read GetCapacity write SetCapacity; 62 property Items[Index: TIndex]: TItem read Get write Put; default; 63 63 property Last: TItem read GetLast write SetLast; 64 64 end; … … 84 84 constructor Create; 85 85 destructor Destroy; override; 86 86 87 end; 87 88 … … 94 95 { TGList } 95 96 96 function TGList<TItem>.GetCapacity: T GListIndex;97 function TGList<TItem>.GetCapacity: TIndex; 97 98 begin 98 99 Result := Length(FItems); 99 100 end; 100 101 101 procedure TGList<TItem>.SetCapacity(const AValue: T GListIndex);102 procedure TGList<TItem>.SetCapacity(const AValue: TIndex); 102 103 begin 103 104 if (AValue < FCount) then … … 106 107 end; 107 108 108 procedure TGList<TItem>.SetCapacityOptimized(const NewCapacity: T GListIndex);109 var 110 IncSize: T GListIndex;109 procedure TGList<TItem>.SetCapacityOptimized(const NewCapacity: TIndex); 110 var 111 IncSize: TIndex; 111 112 begin 112 113 if NewCapacity > Capacity then begin … … 130 131 end; 131 132 132 function TGList<TItem>.Get(Index: T GListIndex): TItem;133 function TGList<TItem>.Get(Index: TIndex): TItem; 133 134 begin 134 135 if (Index < 0) or (Index >= Count) then … … 137 138 end; 138 139 139 procedure TGList<TItem>.Put(Index: T GListIndex; const AValue: TItem);140 procedure TGList<TItem>.Put(Index: TIndex; const AValue: TItem); 140 141 begin 141 142 if (Index < 0) or (Index >= Count) then … … 144 145 end; 145 146 146 procedure TGList<TItem>.SetCount(const AValue: T GListIndex);147 procedure TGList<TItem>.SetCount(const AValue: TIndex); 147 148 begin 148 149 if (AValue < 0) then … … 165 166 end; 166 167 167 procedure TGList<TItem>.QuickSort(L, R: T GListIndex; Compare: TSortCompare);168 var 169 I, J: T GListIndex;168 procedure TGList<TItem>.QuickSort(L, R: TIndex; Compare: TSortCompare); 169 var 170 I, J: TIndex; 170 171 P, Q: TItem; 171 172 begin … … 196 197 procedure TGList<TItem>.Assign(Source: TGList); 197 198 var 198 I: T GListIndex;199 I: TIndex; 199 200 begin 200 201 Count := Source.Count; … … 208 209 function TGList<TItem>.Extract(Item: TItem): TItem; 209 210 var 210 I: T GListIndex;211 I: TIndex; 211 212 begin 212 213 I := IndexOf(Item); … … 218 219 end; 219 220 220 function TGList<TItem>.IndexOf(Item: TItem; Start: T GListIndex): TGListIndex;221 function TGList<TItem>.IndexOf(Item: TItem; Start: TIndex): TIndex; 221 222 begin 222 223 Result := Start; … … 227 228 end; 228 229 229 procedure TGList<TItem>.Insert(Index: T GListIndex; Item: TItem);230 procedure TGList<TItem>.Insert(Index: TIndex; Item: TItem); 230 231 begin 231 232 if (Index < 0) or (Index > FCount ) then … … 238 239 end; 239 240 240 procedure TGList<TItem>.InsertList(Index: T GListIndex; List: TGList);241 var 242 I: T GListIndex;241 procedure TGList<TItem>.InsertList(Index: TIndex; List: TGList); 242 var 243 I: TIndex; 243 244 begin 244 245 I := 0; … … 249 250 end; 250 251 251 function TGList<TItem>.IndexOfList(List: TGList; Start: T GListIndex): TGListIndex;252 var 253 I: T GListIndex;252 function TGList<TItem>.IndexOfList(List: TGList; Start: TIndex): TIndex; 253 var 254 I: TIndex; 254 255 begin 255 256 if List.Count > 0 then begin … … 300 301 end; 301 302 302 procedure TGList<TItem>.Move(CurIndex, NewIndex: T GListIndex);303 procedure TGList<TItem>.Move(CurIndex, NewIndex: TIndex); 303 304 var 304 305 Temp: TItem; … … 320 321 end; 321 322 322 procedure TGList<TItem>.MoveItems(CurIndex, NewIndex, Count: T GListIndex);323 procedure TGList<TItem>.MoveItems(CurIndex, NewIndex, Count: TIndex); 323 324 var 324 325 S: Integer; … … 345 346 end; 346 347 347 function TGList<TItem>.Remove(Item: TItem): T GListIndex;348 function TGList<TItem>.Remove(Item: TItem): TIndex; 348 349 begin 349 350 Result := IndexOf(Item); … … 354 355 function TGList<TItem>.EqualTo(List: TGList): Boolean; 355 356 var 356 I: T GListIndex;357 I: TIndex; 357 358 begin 358 359 Result := Count = List.Count; … … 371 372 procedure TGList<TItem>.Reverse; 372 373 var 373 I: T GListIndex;374 I: TIndex; 374 375 begin 375 376 I := 0; … … 388 389 procedure TGList<TItem>.AddArray(Values: array of TItem); 389 390 var 390 I: T GListIndex;391 I: TIndex; 391 392 begin 392 393 I := 0; … … 397 398 end; 398 399 399 procedure TGList<TItem>.SetArray(Values: TItemArray);400 var 401 I: T GListIndex;400 procedure TGList<TItem>.SetArray(Values: array of TItem); 401 var 402 I: TIndex; 402 403 begin 403 404 Clear; … … 409 410 end; 410 411 411 procedure TGList<TItem>.InsertArray(Index: T GListIndex; Values: array of TItem);412 var 413 I: T GListIndex;412 procedure TGList<TItem>.InsertArray(Index: TIndex; Values: array of TItem); 413 var 414 I: TIndex; 414 415 begin 415 416 I := 0; … … 422 423 function TGList<TItem>.Implode(Separator: string; Converter: TToStringConverter): string; 423 424 var 424 I: T GListIndex;425 I: TIndex; 425 426 begin 426 427 Result := ''; … … 445 446 end; 446 447 447 function TGList<TItem>.Add(Item: TItem): T GListIndex;448 function TGList<TItem>.Add(Item: TItem): TIndex; 448 449 begin 449 450 Count := Count + 1; … … 454 455 procedure TGList<TItem>.AddList(List: TGList); 455 456 var 456 I: T GListIndex;457 I: TIndex; 457 458 begin 458 459 I := 0; … … 469 470 end; 470 471 471 procedure TGList<TItem>.Delete(Index: T GListIndex);472 procedure TGList<TItem>.Delete(Index: TIndex); 472 473 begin 473 474 if (Index < 0) or (Index >= FCount) then … … 478 479 end; 479 480 480 procedure TGList<TItem>.DeleteItems(Index, Count: T GListIndex);481 var 482 I: T GListIndex;481 procedure TGList<TItem>.DeleteItems(Index, Count: TIndex); 482 var 483 I: TIndex; 483 484 begin 484 485 I := Index; … … 489 490 end; 490 491 491 procedure TGList<TItem>.Fill(Start, Count: T GListIndex; Value: TItem);492 var 493 I: T GListIndex;492 procedure TGList<TItem>.Fill(Start, Count: TIndex; Value: TItem); 493 var 494 I: TIndex; 494 495 begin 495 496 I := Start; … … 500 501 end; 501 502 502 procedure TGList<TItem>.Exchange(Index1, Index2: T GListIndex);503 procedure TGList<TItem>.Exchange(Index1, Index2: TIndex); 503 504 var 504 505 Temp: TItem;
Note:
See TracChangeset
for help on using the changeset viewer.