Changeset 93 for trunk/Packages/TemplateGenerics/Generic/GenericMatrix.inc
- Timestamp:
- Jul 20, 2018, 10:25:06 AM (6 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
- Property svn:ignore
-
old new 6 6 compiled 7 7 heaptrclog.trc 8 LazFuck.dbg
-
- Property svn:ignore
-
trunk/Packages/TemplateGenerics/Generic/GenericMatrix.inc
r72 r93 1 // Work in progress... 2 1 3 {$IFDEF INTERFACE} 2 3 TGMatrix = class;4 5 TGMatrixSortCompare = function(const Item1, Item2: TGMatrixItem): Integer of object;6 TGMatrixToStringConverter = function(Item: TGMatrixItem): string;7 TGMatrixFromStringConverter = function(Text: string): TGMatrixItem;8 TGMatrixRow = array of TGMatrixItem;9 TGMatrixMerge = function(Item1, Item2: TGMatrixItem): TGMatrixItem of object;10 11 TGMatrixIndex = record12 X: TGMatrixIndexX;13 Y: TGMatrixIndexY;14 end;15 4 16 5 // TGMatrix<TGMatrixIndex, TGMatrixIndex, TGMatrixItem> = class 17 6 TGMatrix = class 7 public 8 type 9 TSortCompare = function(const Item1, Item2: TGMatrixItem): Integer of object; 10 TToStringConverter = function(Item: TGMatrixItem): string; 11 TFromStringConverter = function(Text: string): TGMatrixItem; 12 TRow = array of TGMatrixItem; 13 TMerge = function(Item1, Item2: TGMatrixItem): TGMatrixItem of object; 14 15 TIndex = record 16 X: TGMatrixIndexX; 17 Y: TGMatrixIndexY; 18 end; 18 19 private 19 20 FItems: array of array of TGMatrixItem; 20 FCount: T GMatrixIndex;21 FCount: TIndex; 21 22 function GetItemXY(X: TGMatrixIndexX; Y: TGMatrixIndexY): TGMatrixItem; 22 function GetItem(Index: T GMatrixIndex): TGMatrixItem;23 function GetCapacity: T GMatrixIndex;23 function GetItem(Index: TIndex): TGMatrixItem; 24 function GetCapacity: TIndex; 24 25 function GetLast: TGMatrixItem; 25 26 function GetFirst: TGMatrixItem; 26 procedure SetCapacity(const AValue: T GMatrixIndex);27 procedure SetCapacity(const AValue: TIndex); 27 28 procedure SetLast(AValue: TGMatrixItem); 28 29 procedure SetFirst(AValue: TGMatrixItem); 29 30 procedure PutItemXY(X: TGMatrixIndexX; Y: TGMatrixIndexY; const AValue: TGMatrixItem); virtual; 30 procedure PutItem(Index: T GMatrixIndex; const AValue: TGMatrixItem); virtual;31 procedure SetCount(const AValue: T GMatrixIndex);31 procedure PutItem(Index: TIndex; const AValue: TGMatrixItem); virtual; 32 procedure SetCount(const AValue: TIndex); 32 33 public 33 function Add(Item: TGMatrixItem): T GMatrixIndex;34 procedure AddMatrix(Values: array of T GMatrixRow);34 function Add(Item: TGMatrixItem): TIndex; 35 procedure AddMatrix(Values: array of TRow); 35 36 procedure AddList(List: TGMatrix); 36 37 procedure Assign(Source: TGMatrix); 37 38 procedure Clear; virtual; 38 39 procedure Contract; 39 function CreateIndex(X: TGMatrixIndexY; Y: TGMatrixIndexX): T GMatrixIndex;40 procedure Delete(Index: T GMatrixIndex); virtual;41 procedure DeleteItems(Index, Count: T GMatrixIndex);40 function CreateIndex(X: TGMatrixIndexY; Y: TGMatrixIndexX): TIndex; 41 procedure Delete(Index: TIndex); virtual; 42 procedure DeleteItems(Index, Count: TIndex); 42 43 function EqualTo(List: TGMatrix): Boolean; 43 44 procedure Expand; 44 45 function Extract(Item: TGMatrixItem): TGMatrixItem; 45 procedure Exchange(Index1, Index2: T GMatrixIndex);46 procedure Exchange(Index1, Index2: TIndex); 46 47 property First: TGMatrixItem read GetFirst write SetFirst; 47 48 procedure FillAll(Value: TGMatrixItem); 48 procedure Fill(Start, Count: T GMatrixIndex; Value: TGMatrixItem);49 function Implode(RowSeparator, ColSeparator: string; Converter: T GMatrixToStringConverter): string;50 procedure Explode(Text, Separator: string; Converter: T GMatrixFromStringConverter; SlicesCount: Integer = -1);51 function IndexOf(Item: TGMatrixItem; Start: T GMatrixIndex): TGMatrixIndex;52 function IndexOfList(List: TGMatrix; Start: T GMatrixIndex): TGMatrixIndex;53 procedure Insert(Index: T GMatrixIndex; Item: TGMatrixItem);54 procedure InsertList(Index: T GMatrixIndex; List: TGMatrix);55 procedure InsertArray(Index: T GMatrixIndex; Values: array of TGMatrixItem);56 procedure Move(CurIndex, NewIndex: T GMatrixIndex);57 procedure MoveItems(CurIndex, NewIndex, Count: T GMatrixIndex);58 procedure Merge(Index: T GMatrixIndex; Source: TGMatrix; Proc: TGMatrixMerge);59 procedure Replace(Index: T GMatrixIndex; Source: TGMatrix);60 function Remove(Item: TGMatrixItem): T GMatrixIndex;49 procedure Fill(Start, Count: TIndex; Value: TGMatrixItem); 50 function Implode(RowSeparator, ColSeparator: string; Converter: TToStringConverter): string; 51 procedure Explode(Text, Separator: string; Converter: TFromStringConverter; SlicesCount: Integer = -1); 52 function IndexOf(Item: TGMatrixItem; Start: TIndex): TIndex; 53 function IndexOfList(List: TGMatrix; Start: TIndex): TIndex; 54 procedure Insert(Index: TIndex; Item: TGMatrixItem); 55 procedure InsertList(Index: TIndex; List: TGMatrix); 56 procedure InsertArray(Index: TIndex; Values: array of TGMatrixItem); 57 procedure Move(CurIndex, NewIndex: TIndex); 58 procedure MoveItems(CurIndex, NewIndex, Count: TIndex); 59 procedure Merge(Index: TIndex; Source: TGMatrix; Proc: TMerge); 60 procedure Replace(Index: TIndex; Source: TGMatrix); 61 function Remove(Item: TGMatrixItem): TIndex; 61 62 procedure Reverse; 62 63 procedure ReverseHorizontal; 63 64 procedure ReverseVertical; 64 procedure Sort(Compare: T GMatrixSortCompare);65 procedure Sort(Compare: TSortCompare); 65 66 procedure SetArray(Values: array of TGMatrixItem); 66 property Count: T GMatrixIndex read FCount write SetCount;67 property Capacity: T GMatrixIndex read GetCapacity write SetCapacity;67 property Count: TIndex read FCount write SetCount; 68 property Capacity: TIndex read GetCapacity write SetCapacity; 68 69 property ItemsXY[X: TGMatrixIndexX; Y: TGMatrixIndexY]: TGMatrixItem 69 70 read GetItemXY write PutItemXY; default; 70 property Items[Index: T GMatrixIndex]: TGMatrixItem71 property Items[Index: TIndex]: TGMatrixItem 71 72 read GetItem write PutItem; 72 73 property Last: TGMatrixItem read GetLast write SetLast; … … 91 92 { TGMatrix } 92 93 93 procedure TGMatrix.Replace(Index: T GMatrixIndex; Source: TGMatrix);94 procedure TGMatrix.Replace(Index: TIndex; Source: TGMatrix); 94 95 var 95 96 X: TGMatrixIndexX; … … 107 108 end; 108 109 109 procedure TGMatrix.Merge(Index: T GMatrixIndex; Source: TGMatrix; Proc: TGMatrixMerge);110 procedure TGMatrix.Merge(Index: TIndex; Source: TGMatrix; Proc: TMerge); 110 111 var 111 112 X: TGMatrixIndexX; … … 123 124 end; 124 125 125 function TGMatrix.CreateIndex(X: TGMatrixIndexY; Y: TGMatrixIndexX): T GMatrixIndex;126 function TGMatrix.CreateIndex(X: TGMatrixIndexY; Y: TGMatrixIndexX): TIndex; 126 127 begin 127 128 Result.X := X; … … 129 130 end; 130 131 131 function TGMatrix.GetCapacity: T GMatrixIndex;132 function TGMatrix.GetCapacity: TIndex; 132 133 begin 133 134 Result.Y := Length(FItems); … … 135 136 end; 136 137 137 procedure TGMatrix.SetCapacity(const AValue: T GMatrixIndex);138 procedure TGMatrix.SetCapacity(const AValue: TIndex); 138 139 var 139 140 Y: TGMatrixIndexY; … … 160 161 end; 161 162 162 function TGMatrix.GetItem(Index: T GMatrixIndex): TGMatrixItem;163 function TGMatrix.GetItem(Index: TIndex): TGMatrixItem; 163 164 begin 164 165 if (Index.X < 0) or (Index.X >= Count.X) or … … 176 177 end; 177 178 178 procedure TGMatrix.PutItem(Index: T GMatrixIndex; const AValue: TGMatrixItem);179 procedure TGMatrix.PutItem(Index: TIndex; const AValue: TGMatrixItem); 179 180 begin 180 181 if (Index.X < 0) or (Index.X >= Count.X) or … … 184 185 end; 185 186 186 procedure TGMatrix.SetCount(const AValue: T GMatrixIndex);187 procedure TGMatrix.SetCount(const AValue: TIndex); 187 188 begin 188 189 Capacity := AValue; … … 192 193 procedure TGMatrix.Assign(Source: TGMatrix); 193 194 var 194 Index: T GMatrixIndex;195 Index: TIndex; 195 196 begin 196 197 Count := Source.Count; … … 208 209 procedure TGMatrix.Expand; 209 210 var 210 IncSize: T GMatrixIndex;211 NewCapacity: T GMatrixIndex;211 IncSize: TIndex; 212 NewCapacity: TIndex; 212 213 begin 213 214 if (FCount.X = Capacity.X) then begin … … 230 231 procedure TGMatrix.Contract; 231 232 var 232 NewCapacity: T GMatrixIndex;233 NewCapacity: TIndex; 233 234 begin 234 235 if (Capacity.X > 256) and (FCount.X < Capacity.X shr 2) then … … 245 246 function TGMatrix.Extract(Item: TGMatrixItem): TGMatrixItem; 246 247 var 247 I: T GMatrixIndex;248 I: TIndex; 248 249 begin 249 250 (* I := IndexOf(Item); … … 256 257 end; 257 258 258 function TGMatrix.IndexOf(Item: TGMatrixItem; Start: T GMatrixIndex): TGMatrixIndex;259 function TGMatrix.IndexOf(Item: TGMatrixItem; Start: TIndex): TIndex; 259 260 begin 260 261 (* Result := Start; … … 266 267 end; 267 268 268 procedure TGMatrix.Insert(Index: T GMatrixIndex; Item: TGMatrixItem);269 procedure TGMatrix.Insert(Index: TIndex; Item: TGMatrixItem); 269 270 begin 270 271 (* if (Index < 0) or (Index > FCount ) then … … 278 279 end; 279 280 280 procedure TGMatrix.InsertList(Index: T GMatrixIndex; List: TGMatrix);281 var 282 I: T GMatrixIndex;281 procedure TGMatrix.InsertList(Index: TIndex; List: TGMatrix); 282 var 283 I: TIndex; 283 284 begin 284 285 (* I := 0; … … 290 291 end; 291 292 292 function TGMatrix.IndexOfList(List: TGMatrix; Start: T GMatrixIndex): TGMatrixIndex;293 var 294 I: T GMatrixIndex;293 function TGMatrix.IndexOfList(List: TGMatrix; Start: TIndex): TIndex; 294 var 295 I: TIndex; 295 296 begin 296 297 (* if List.Count > 0 then begin … … 346 347 end; 347 348 348 procedure TGMatrix.Move(CurIndex, NewIndex: T GMatrixIndex);349 procedure TGMatrix.Move(CurIndex, NewIndex: TIndex); 349 350 var 350 351 Temp: TGMatrixItem; … … 366 367 end; 367 368 368 procedure TGMatrix.MoveItems(CurIndex, NewIndex, Count: T GMatrixIndex);369 procedure TGMatrix.MoveItems(CurIndex, NewIndex, Count: TIndex); 369 370 var 370 371 S: Integer; … … 391 392 end; 392 393 393 function TGMatrix.Remove(Item: TGMatrixItem): T GMatrixIndex;394 function TGMatrix.Remove(Item: TGMatrixItem): TIndex; 394 395 begin 395 396 (* Result := IndexOf(Item); … … 400 401 function TGMatrix.EqualTo(List: TGMatrix): Boolean; 401 402 var 402 I: T GMatrixIndex;403 I: TIndex; 403 404 begin 404 405 (* Result := Count = List.Count; … … 463 464 end; 464 465 465 procedure TGMatrix.Sort(Compare: T GMatrixSortCompare);466 procedure TGMatrix.Sort(Compare: TSortCompare); 466 467 begin 467 468 (* if FCount > 1 then … … 469 470 end; 470 471 471 procedure TGMatrix.AddMatrix(Values: array of T GMatrixRow);472 var 473 I: T GMatrixIndex;472 procedure TGMatrix.AddMatrix(Values: array of TRow); 473 var 474 I: TIndex; 474 475 begin 475 476 (* I := 0; … … 482 483 procedure TGMatrix.SetArray(Values: array of TGMatrixItem); 483 484 var 484 I: T GMatrixIndex;485 I: TIndex; 485 486 begin 486 487 (* Clear; … … 492 493 end; 493 494 494 procedure TGMatrix.InsertArray(Index: T GMatrixIndex; Values: array of TGMatrixItem);495 var 496 I: T GMatrixIndex;495 procedure TGMatrix.InsertArray(Index: TIndex; Values: array of TGMatrixItem); 496 var 497 I: TIndex; 497 498 begin 498 499 (* I := 0; … … 503 504 end; 504 505 505 function TGMatrix.Implode(RowSeparator, ColSeparator: string; Converter: T GMatrixToStringConverter): string;506 function TGMatrix.Implode(RowSeparator, ColSeparator: string; Converter: TToStringConverter): string; 506 507 var 507 508 Y: TGMatrixIndexY; … … 524 525 end; 525 526 526 procedure TGMatrix.Explode(Text, Separator: string; Converter: T GMatrixFromStringConverter; SlicesCount: Integer = -1);527 procedure TGMatrix.Explode(Text, Separator: string; Converter: TFromStringConverter; SlicesCount: Integer = -1); 527 528 begin 528 529 (* Clear; … … 535 536 end; 536 537 537 function TGMatrix.Add(Item: TGMatrixItem): T GMatrixIndex;538 function TGMatrix.Add(Item: TGMatrixItem): TIndex; 538 539 begin 539 540 (* if FCount = Capacity then … … 546 547 procedure TGMatrix.AddList(List: TGMatrix); 547 548 var 548 I: T GMatrixIndex;549 I: TIndex; 549 550 begin 550 551 (* I := 0; … … 561 562 end; 562 563 563 procedure TGMatrix.Delete(Index: T GMatrixIndex);564 procedure TGMatrix.Delete(Index: TIndex); 564 565 begin 565 566 (* if (Index < 0) or (Index >= FCount) then … … 571 572 end; 572 573 573 procedure TGMatrix.DeleteItems(Index, Count: T GMatrixIndex);574 var 575 I: T GMatrixIndex;574 procedure TGMatrix.DeleteItems(Index, Count: TIndex); 575 var 576 I: TIndex; 576 577 begin 577 578 (* I := Index; … … 583 584 end; 584 585 585 procedure TGMatrix.Fill(Start, Count: T GMatrixIndex; Value: TGMatrixItem);586 procedure TGMatrix.Fill(Start, Count: TIndex; Value: TGMatrixItem); 586 587 var 587 588 X: TGMatrixIndexX; … … 604 605 end; 605 606 606 procedure TGMatrix.Exchange(Index1, Index2: T GMatrixIndex);607 procedure TGMatrix.Exchange(Index1, Index2: TIndex); 607 608 var 608 609 Temp: TGMatrixItem;
Note:
See TracChangeset
for help on using the changeset viewer.