Changeset 320
- Timestamp:
- Feb 7, 2012, 2:03:20 PM (13 years ago)
- Location:
- Generics/NativeGenerics
- Files:
-
- 1 deleted
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
Generics/NativeGenerics/Demo
- Property svn:ignore
-
old new 1 1 lib 2 backup 3 Demo.exe 4 heaptrclog.trc
-
- Property svn:ignore
-
Generics/NativeGenerics/Demo/Demo.lpi
r313 r320 38 38 </Item2> 39 39 </RequiredPackages> 40 <Units Count="5 3">40 <Units Count="59"> 41 41 <Unit0> 42 42 <Filename Value="Demo.lpr"/> … … 57 57 <EditorIndex Value="0"/> 58 58 <WindowIndex Value="0"/> 59 <TopLine Value=" 694"/>60 <CursorPos X=" 36" Y="719"/>59 <TopLine Value="127"/> 60 <CursorPos X="15" Y="47"/> 61 61 <UsageCount Value="233"/> 62 62 <Bookmarks Count="1"> 63 <Item0 X="65" Y="23 5" ID="2"/>63 <Item0 X="65" Y="234" ID="2"/> 64 64 </Bookmarks> 65 65 <Loaded Value="True"/> … … 437 437 <Filename Value="../Units/GenericList.pas"/> 438 438 <UnitName Value="GenericList"/> 439 <EditorIndex Value=" 6"/>440 <WindowIndex Value="0"/> 441 <TopLine Value=" 361"/>442 <CursorPos X="7" Y=" 374"/>443 <UsageCount Value="3 2"/>439 <EditorIndex Value="11"/> 440 <WindowIndex Value="0"/> 441 <TopLine Value="66"/> 442 <CursorPos X="7" Y="21"/> 443 <UsageCount Value="34"/> 444 444 <Loaded Value="True"/> 445 445 </Unit46> … … 447 447 <Filename Value="../Units/GenericMatrix.pas"/> 448 448 <UnitName Value="GenericMatrix"/> 449 <EditorIndex Value="4"/> 450 <WindowIndex Value="0"/> 451 <TopLine Value="352"/> 452 <CursorPos X="44" Y="365"/> 453 <UsageCount Value="12"/> 454 <Loaded Value="True"/> 449 <WindowIndex Value="0"/> 450 <TopLine Value="4"/> 451 <CursorPos X="12" Y="11"/> 452 <UsageCount Value="12"/> 455 453 </Unit47> 456 454 <Unit48> 457 455 <Filename Value="../Units/GenericStream.pas"/> 458 456 <UnitName Value="GenericStream"/> 459 <EditorIndex Value="5"/> 460 <WindowIndex Value="0"/> 461 <TopLine Value="1"/> 462 <CursorPos X="5" Y="12"/> 463 <UsageCount Value="12"/> 457 <IsVisibleTab Value="True"/> 458 <EditorIndex Value="9"/> 459 <WindowIndex Value="0"/> 460 <TopLine Value="59"/> 461 <CursorPos X="29" Y="67"/> 462 <UsageCount Value="14"/> 464 463 <Loaded Value="True"/> 465 464 </Unit48> … … 467 466 <Filename Value="../Units/GenericQueue.pas"/> 468 467 <UnitName Value="GenericQueue"/> 469 <EditorIndex Value=" 3"/>470 <WindowIndex Value="0"/> 471 <TopLine Value="1 "/>472 <CursorPos X=" 3" Y="11"/>473 <UsageCount Value="1 0"/>468 <EditorIndex Value="6"/> 469 <WindowIndex Value="0"/> 470 <TopLine Value="18"/> 471 <CursorPos X="24" Y="28"/> 472 <UsageCount Value="12"/> 474 473 <Loaded Value="True"/> 475 474 </Unit49> … … 477 476 <Filename Value="../Units/GenericDictionary.pas"/> 478 477 <UnitName Value="GenericDictionary"/> 479 <EditorIndex Value=" 2"/>480 <WindowIndex Value="0"/> 481 <TopLine Value="1"/> 482 <CursorPos X="1 7" Y="16"/>483 <UsageCount Value="1 0"/>478 <EditorIndex Value="4"/> 479 <WindowIndex Value="0"/> 480 <TopLine Value="1"/> 481 <CursorPos X="1" Y="1"/> 482 <UsageCount Value="12"/> 484 483 <Loaded Value="True"/> 485 484 </Unit50> 486 485 <Unit51> 487 486 <Filename Value="../../../../../Lazarus/0.9.31_2.6.0/fpc/2.6.0/source/rtl/objpas/sysutils/sysunih.inc"/> 488 <EditorIndex Value=" 1"/>487 <EditorIndex Value="3"/> 489 488 <WindowIndex Value="0"/> 490 489 <TopLine Value="9"/> 491 490 <CursorPos X="10" Y="22"/> 492 <UsageCount Value="10"/> 493 <Loaded Value="True"/> 491 <UsageCount Value="12"/> 492 <Loaded Value="True"/> 493 <DefaultSyntaxHighlighter Value="Delphi"/> 494 494 </Unit51> 495 495 <Unit52> 496 496 <Filename Value="../Units/SpecializedList.pas"/> 497 497 <UnitName Value="SpecializedList"/> 498 <IsVisibleTab Value="True"/> 498 <EditorIndex Value="12"/> 499 <WindowIndex Value="0"/> 500 <TopLine Value="1"/> 501 <CursorPos X="23" Y="11"/> 502 <UsageCount Value="12"/> 503 <Loaded Value="True"/> 504 </Unit52> 505 <Unit53> 506 <Filename Value="../../../../../Lazarus/0.9.31_2.7.1/fpc/2.7.1/source/rtl/objpas/classes/classesh.inc"/> 507 <EditorIndex Value="5"/> 508 <WindowIndex Value="0"/> 509 <TopLine Value="52"/> 510 <CursorPos X="49" Y="65"/> 511 <UsageCount Value="12"/> 512 <Loaded Value="True"/> 513 </Unit53> 514 <Unit54> 515 <Filename Value="../Units/GenericSet.pas"/> 516 <UnitName Value="GenericSet"/> 499 517 <EditorIndex Value="7"/> 500 518 <WindowIndex Value="0"/> 501 <TopLine Value="45"/> 502 <CursorPos X="7" Y="60"/> 503 <UsageCount Value="10"/> 504 <Loaded Value="True"/> 505 </Unit52> 519 <TopLine Value="17"/> 520 <CursorPos X="14" Y="33"/> 521 <UsageCount Value="12"/> 522 <Loaded Value="True"/> 523 </Unit54> 524 <Unit55> 525 <Filename Value="../Units/GenericStack.pas"/> 526 <UnitName Value="GenericStack"/> 527 <EditorIndex Value="8"/> 528 <WindowIndex Value="0"/> 529 <TopLine Value="22"/> 530 <CursorPos X="14" Y="38"/> 531 <UsageCount Value="12"/> 532 <Loaded Value="True"/> 533 </Unit55> 534 <Unit56> 535 <Filename Value="../Units/GenericRange.pas"/> 536 <UnitName Value="GenericRange"/> 537 <EditorIndex Value="1"/> 538 <WindowIndex Value="0"/> 539 <TopLine Value="4"/> 540 <CursorPos X="33" Y="8"/> 541 <UsageCount Value="12"/> 542 <Loaded Value="True"/> 543 </Unit56> 544 <Unit57> 545 <Filename Value="../../../../../Lazarus/0.9.31_2.7.1/fpc/2.7.1/source/rtl/inc/systemh.inc"/> 546 <EditorIndex Value="10"/> 547 <WindowIndex Value="0"/> 548 <TopLine Value="958"/> 549 <CursorPos X="11" Y="971"/> 550 <UsageCount Value="12"/> 551 <Loaded Value="True"/> 552 </Unit57> 553 <Unit58> 554 <Filename Value="../Units/GenericTree.pas"/> 555 <UnitName Value="GenericTree"/> 556 <EditorIndex Value="2"/> 557 <WindowIndex Value="0"/> 558 <TopLine Value="1"/> 559 <CursorPos X="33" Y="8"/> 560 <UsageCount Value="12"/> 561 <Loaded Value="True"/> 562 </Unit58> 506 563 </Units> 507 <JumpHistory Count="30" HistoryIndex="2 9">564 <JumpHistory Count="30" HistoryIndex="28"> 508 565 <Position1> 509 <Filename Value="../Units/Generic List.pas"/>510 <Caret Line=" 423" Column="16" TopLine="402"/>566 <Filename Value="../Units/GenericStream.pas"/> 567 <Caret Line="29" Column="42" TopLine="11"/> 511 568 </Position1> 512 569 <Position2> 513 <Filename Value="../Units/Generic List.pas"/>514 <Caret Line=" 425" Column="7" TopLine="404"/>570 <Filename Value="../Units/GenericStream.pas"/> 571 <Caret Line="39" Column="57" TopLine="26"/> 515 572 </Position2> 516 573 <Position3> 517 <Filename Value="../Units/Generic List.pas"/>518 <Caret Line=" 437" Column="17" TopLine="416"/>574 <Filename Value="../Units/GenericStream.pas"/> 575 <Caret Line="29" Column="19" TopLine="16"/> 519 576 </Position3> 520 577 <Position4> 521 <Filename Value="../Units/Generic List.pas"/>522 <Caret Line=" 448" Column="43" TopLine="427"/>578 <Filename Value="../Units/GenericStream.pas"/> 579 <Caret Line="16" Column="53" TopLine="7"/> 523 580 </Position4> 524 581 <Position5> 525 <Filename Value="../Units/Generic List.pas"/>526 <Caret Line="4 55" Column="45" TopLine="434"/>582 <Filename Value="../Units/GenericStream.pas"/> 583 <Caret Line="46" Column="19" TopLine="33"/> 527 584 </Position5> 528 585 <Position6> 529 <Filename Value="../Units/Generic List.pas"/>530 <Caret Line=" 457" Column="7" TopLine="436"/>586 <Filename Value="../Units/GenericStream.pas"/> 587 <Caret Line="34" Column="8" TopLine="24"/> 531 588 </Position6> 532 589 <Position7> 533 <Filename Value="../Units/Generic List.pas"/>534 <Caret Line=" 466" Column="17" TopLine="445"/>590 <Filename Value="../Units/GenericStream.pas"/> 591 <Caret Line="30" Column="19" TopLine="20"/> 535 592 </Position7> 536 593 <Position8> 537 <Filename Value="../Units/Generic List.pas"/>538 <Caret Line="4 72" Column="40" TopLine="451"/>594 <Filename Value="../Units/GenericStream.pas"/> 595 <Caret Line="41" Column="1" TopLine="33"/> 539 596 </Position8> 540 597 <Position9> 541 <Filename Value="../Units/Generic List.pas"/>542 <Caret Line=" 481" Column="52" TopLine="460"/>598 <Filename Value="../Units/GenericStream.pas"/> 599 <Caret Line="8" Column="13" TopLine="1"/> 543 600 </Position9> 544 601 <Position10> 545 <Filename Value="../Units/Generic List.pas"/>546 <Caret Line=" 483" Column="7" TopLine="462"/>602 <Filename Value="../Units/GenericStream.pas"/> 603 <Caret Line="29" Column="58" TopLine="14"/> 547 604 </Position10> 548 605 <Position11> 549 <Filename Value="../Units/Generic List.pas"/>550 <Caret Line=" 492" Column="45" TopLine="471"/>606 <Filename Value="../Units/GenericStream.pas"/> 607 <Caret Line="39" Column="1" TopLine="27"/> 551 608 </Position11> 552 609 <Position12> 553 <Filename Value="../Units/Generic List.pas"/>554 <Caret Line=" 494" Column="7" TopLine="473"/>610 <Filename Value="../Units/GenericStream.pas"/> 611 <Caret Line="29" Column="18" TopLine="6"/> 555 612 </Position12> 556 613 <Position13> 557 <Filename Value="../Units/Generic List.pas"/>558 <Caret Line=" 503" Column="51" TopLine="482"/>614 <Filename Value="../Units/GenericStream.pas"/> 615 <Caret Line="46" Column="23" TopLine="33"/> 559 616 </Position13> 560 617 <Position14> 561 <Filename Value="../Units/Generic List.pas"/>562 <Caret Line=" 516" Column="9" TopLine="495"/>618 <Filename Value="../Units/GenericStream.pas"/> 619 <Caret Line="66" Column="25" TopLine="53"/> 563 620 </Position14> 564 621 <Position15> 565 <Filename Value="../Units/Generic List.pas"/>566 <Caret Line=" 518" Column="52" TopLine="504"/>622 <Filename Value="../Units/GenericStream.pas"/> 623 <Caret Line="62" Column="29" TopLine="49"/> 567 624 </Position15> 568 625 <Position16> 569 <Filename Value="../Units/Generic List.pas"/>570 <Caret Line=" 525" Column="17" TopLine="504"/>626 <Filename Value="../Units/GenericRange.pas"/> 627 <Caret Line="1" Column="1" TopLine="1"/> 571 628 </Position16> 572 629 <Position17> 573 <Filename Value="../Units/Generic List.pas"/>574 <Caret Line=" 531" Column="17" TopLine="510"/>630 <Filename Value="../Units/GenericTree.pas"/> 631 <Caret Line="1" Column="1" TopLine="1"/> 575 632 </Position17> 576 633 <Position18> 577 <Filename Value="../Units/Generic List.pas"/>578 <Caret Line=" 537" Column="17" TopLine="516"/>634 <Filename Value="../Units/GenericTree.pas"/> 635 <Caret Line="8" Column="33" TopLine="1"/> 579 636 </Position18> 580 637 <Position19> 581 <Filename Value="../Units/Generic List.pas"/>582 <Caret Line=" 551" Column="19" TopLine="530"/>638 <Filename Value="../Units/GenericRange.pas"/> 639 <Caret Line="8" Column="33" TopLine="1"/> 583 640 </Position19> 584 641 <Position20> 585 <Filename Value="../Units/Generic List.pas"/>586 <Caret Line=" 557" Column="18" TopLine="536"/>642 <Filename Value="../Units/GenericTree.pas"/> 643 <Caret Line="8" Column="33" TopLine="1"/> 587 644 </Position20> 588 645 <Position21> 589 <Filename Value="../Units/Generic List.pas"/>590 <Caret Line=" 563" Column="9" TopLine="542"/>646 <Filename Value="../Units/GenericStream.pas"/> 647 <Caret Line="46" Column="23" TopLine="33"/> 591 648 </Position21> 592 649 <Position22> 593 <Filename Value="../Units/Generic List.pas"/>594 <Caret Line=" 565" Column="52" TopLine="544"/>650 <Filename Value="../Units/GenericStream.pas"/> 651 <Caret Line="86" Column="1" TopLine="61"/> 595 652 </Position22> 596 653 <Position23> 597 <Filename Value="../Units/Generic List.pas"/>598 <Caret Line=" 571" Column="17" TopLine="550"/>654 <Filename Value="../Units/GenericStream.pas"/> 655 <Caret Line="66" Column="18" TopLine="42"/> 599 656 </Position23> 600 657 <Position24> 601 <Filename Value="../Units/Generic List.pas"/>602 <Caret Line=" 211" Column="7" TopLine="198"/>658 <Filename Value="../Units/GenericStream.pas"/> 659 <Caret Line="46" Column="19" TopLine="33"/> 603 660 </Position24> 604 661 <Position25> 605 <Filename Value="../Units/Generic List.pas"/>606 <Caret Line=" 221" Column="62" TopLine="200"/>662 <Filename Value="../Units/GenericStream.pas"/> 663 <Caret Line="16" Column="53" TopLine="5"/> 607 664 </Position25> 608 665 <Position26> 609 <Filename Value="../Units/Generic List.pas"/>610 <Caret Line=" 357" Column="7" TopLine="344"/>666 <Filename Value="../Units/GenericStream.pas"/> 667 <Caret Line="45" Column="15" TopLine="34"/> 611 668 </Position26> 612 669 <Position27> 613 <Filename Value="../Units/ SpecializedList.pas"/>614 <Caret Line=" 1" Column="1" TopLine="1"/>670 <Filename Value="../Units/GenericStream.pas"/> 671 <Caret Line="47" Column="18" TopLine="34"/> 615 672 </Position27> 616 673 <Position28> 617 <Filename Value="../Units/ SpecializedList.pas"/>618 <Caret Line="2 5" Column="7" TopLine="12"/>674 <Filename Value="../Units/GenericStream.pas"/> 675 <Caret Line="20" Column="15" TopLine="7"/> 619 676 </Position28> 620 677 <Position29> 621 <Filename Value="../Units/ SpecializedList.pas"/>622 <Caret Line=" 34" Column="7" TopLine="21"/>678 <Filename Value="../Units/GenericStream.pas"/> 679 <Caret Line="48" Column="18" TopLine="35"/> 623 680 </Position29> 624 681 <Position30> 625 <Filename Value="../ Units/SpecializedList.pas"/>626 <Caret Line=" 49" Column="7" TopLine="36"/>682 <Filename Value="../../../../../Lazarus/0.9.31_2.7.1/fpc/2.7.1/source/rtl/objpas/classes/classesh.inc"/> 683 <Caret Line="65" Column="49" TopLine="52"/> 627 684 </Position30> 628 685 </JumpHistory> -
Generics/NativeGenerics/Demo/UMainForm.pas
r313 r320 7 7 uses 8 8 Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls, 9 ComCtrls, GenericList, GenericDictionary, GenericQueue, GenericMatrix,9 ComCtrls, GenericList, GenericDictionary, GenericQueue, 10 10 DateUtils, SpecializedList; 11 11 … … 101 101 102 102 procedure TMainForm.ButtonMatrixIntegerClick(Sender: TObject); 103 var 104 Matrix: TGMatrix<Integer, Integer, Integer>; 105 I: Integer; 106 begin 107 ListViewOutput.Clear; 103 //var 104 // Matrix: TGMatrix<Integer, Integer, Integer>; 105 begin 106 (* ListViewOutput.Clear; 108 107 LabelTestName.Caption := 'TMatrixInteger test'; 109 108 Matrix := TGMatrix<Integer, Integer, Integer>.Create; … … 121 120 finally 122 121 Free; 123 end; 122 end; *) 124 123 end; 125 124 … … 130 129 131 130 procedure TMainForm.ButtonListObjectClick(Sender: TObject); 132 var133 List: TGListObject<TObject>;134 I: Integer;131 //var 132 //List: TListObject<TObject>; 133 //I: Integer; 135 134 begin 136 135 (*ListViewOutput.Clear; … … 182 181 183 182 procedure TMainForm.ButtonDictionaryStringClick(Sender: TObject); 184 type185 TPairStringString = TGPair<String, String>;186 var 187 Dictionary: TGDictionary< TPairStringString>;183 //type 184 // TPairStringString = TGPair<string, string>; 185 var 186 Dictionary: TGDictionary<string, string>; 188 187 begin 189 188 ListViewOutput.Clear; 190 189 LabelTestName.Caption := 'TDictionaryString test'; 191 Dictionary := TGDictionary< TPairStringString>.Create;190 Dictionary := TGDictionary<string, string>.Create; 192 191 with Dictionary do try 193 192 Add('Key1', 'Value1'); 194 193 Add('Key2', 'Value2'); 195 194 Add('Key3', 'Value3'); 196 WriteOutput('Add(''Key1'', ''Value1''),Add(''Key1'', ''Value1''),Add(''Key1'', ''Value1'')', Implode(',', StringPairToStr));195 WriteOutput('Add(''Key1'', ''Value1''),Add(''Key1'', ''Value1''),Add(''Key1'', ''Value1'')', List.Implode(',', StringPairToStr)); 197 196 WriteOutput('Values[Key2]', Values['Key2']); 198 197 WriteOutput('Values[Key2] = None'); … … 392 391 393 392 procedure TMainForm.ButtonBenchmarkDictionaryClick(Sender: TObject); 394 type395 TPairStringString = TGPair<String, String>;396 var 397 Dictionary: TGDictionary< TPairStringString>;393 //type 394 // TPairStringString = TGPair<String, String>; 395 var 396 Dictionary: TGDictionary<string, string>; 398 397 Dictionary2: TStringList; 399 398 StartTime: TDateTime; … … 405 404 try 406 405 UpdateButtonState(False); 407 Dictionary := TGDictionary< TPairStringString>.Create;406 Dictionary := TGDictionary<string, string>.Create; 408 407 Dictionary2 := TStringList.Create; 409 408 Dictionary2.NameValueSeparator := '|'; … … 415 414 I := I + 1; 416 415 until (Now - StartTime) > MeasureDuration; 417 WriteOutput('TDictionaryStringString.Add', IntToStr(Dictionary. Count) + ' ops');416 WriteOutput('TDictionaryStringString.Add', IntToStr(Dictionary.List.Count) + ' ops'); 418 417 Application.ProcessMessages; 419 418 … … 430 429 StartTime := Now; 431 430 repeat 432 R := Dictionary.Values[IntToStr(I mod Dictionary. Count)];431 R := Dictionary.Values[IntToStr(I mod Dictionary.List.Count)]; 433 432 I := I + 1; 434 433 until (Now - StartTime) > MeasureDuration; … … 448 447 StartTime := Now; 449 448 repeat 450 R := Dictionary.Keys[I mod Dictionary. Count];449 R := Dictionary.Keys[I mod Dictionary.List.Count]; 451 450 I := I + 1; 452 451 until (Now - StartTime) > MeasureDuration; … … 466 465 StartTime := Now; 467 466 repeat 468 R := Dictionary. Items[I mod Dictionary.Count].Value;467 R := Dictionary.List.Items[I mod Dictionary.List.Count].Value; 469 468 I := I + 1; 470 469 until (Now - StartTime) > MeasureDuration; -
Generics/NativeGenerics/NativeGenerics.lpk
r313 r320 28 28 <License Value="GNU/GPL"/> 29 29 <Version Minor="1"/> 30 <Files Count="1 1">30 <Files Count="10"> 31 31 <Item1> 32 32 <Filename Value="ReadMe.txt"/> … … 62 62 </Item8> 63 63 <Item9> 64 <Filename Value="Units\Generic Matrix.pas"/>65 <UnitName Value="Generic Matrix"/>64 <Filename Value="Units\GenericStream.pas"/> 65 <UnitName Value="GenericStream"/> 66 66 </Item9> 67 67 <Item10> 68 <Filename Value="Units\GenericStream.pas"/>69 <UnitName Value="GenericStream"/>70 </Item10>71 <Item11>72 68 <Filename Value="Units\SpecializedList.pas"/> 73 69 <UnitName Value="SpecializedList"/> 74 </Item1 1>70 </Item10> 75 71 </Files> 76 72 <Type Value="RunAndDesignTime"/> -
Generics/NativeGenerics/NativeGenerics.pas
r313 r320 3 3 } 4 4 5 unit NativeGenerics; 5 unit NativeGenerics; 6 6 7 7 interface … … 9 9 uses 10 10 GenericList, GenericTree, GenericDictionary, GenericQueue, GenericRange, 11 GenericSet, GenericStack, GenericMatrix, GenericStream, SpecializedList, 12 LazarusPackageIntf; 11 GenericSet, GenericStack, GenericStream, SpecializedList, LazarusPackageIntf; 13 12 14 13 implementation 15 14 16 procedure Register; 15 procedure Register; 17 16 begin 18 end; 17 end; 19 18 20 19 initialization 21 RegisterPackage('NativeGenerics', @Register); 20 RegisterPackage('NativeGenerics', @Register); 22 21 end. -
Generics/NativeGenerics/Units/GenericDictionary.pas
r132 r320 14 14 end; 15 15 16 TGDictionary<T Pair> = class(TGList<TPair>)16 TGDictionary<TKey, TValue> = class 17 17 private 18 18 type 19 TGDictionaryIndex = Integer; 19 TIndex = NativeInt; 20 TDictionaryPair = TGPair<TKey, TValue>; 20 21 var 21 function GetKey(Index: TGDictionaryIndex): TPair.TKey; 22 function GetValue(Key: TPair.TKey): TPair.TValue; 23 procedure PutKey(Index: TGDictionaryIndex; const AValue: TPair.TKey); 24 procedure PutValue(Key: TPair.TKey; const AValue: TPair.TValue); 22 FList: TGList<TDictionaryPair>; 23 function GetKey(Index: TIndex): TKey; 24 function GetValue(Key: TKey): TValue; 25 procedure PutKey(Index: TIndex; const AValue: TKey); 26 procedure PutValue(Key: TKey; const AValue: TValue); 25 27 public 26 function SearchKey(Key: TPair.TKey): TGDictionaryIndex; 27 procedure Add(Key: TPair.TKey; Value: TPair.TValue); 28 property Values[Index: TPair.TKey]: TPair.TValue 28 constructor Create; 29 destructor Destroy; override; 30 function SearchKey(Key: TKey): TIndex; 31 procedure Add(Key: TKey; Value: TValue); 32 property Values[Index: TKey]: TValue 29 33 read GetValue write PutValue; 30 property Keys[Index: T GDictionaryIndex]: TPair.TKey34 property Keys[Index: TIndex]: TKey 31 35 read GetKey write PutKey; 36 property List: TGList<TDictionaryPair> read FList; 32 37 end; 33 38 … … 35 40 36 41 37 function TGDictionary<TPair>.GetKey(Index: TGDictionaryIndex): TPair.TKey;42 constructor TGDictionary<TKey, TValue>.Create; 38 43 begin 39 Result := Items[Index].Key;44 FList := TGList<TDictionaryPair>.Create; 40 45 end; 41 46 42 function TGDictionary<TPair>.GetValue(Key: TPair.TKey): TPair.TValue;47 destructor TGDictionary<TKey, TValue>.Destroy; 43 48 begin 44 Result := Items[SearchKey(Key)].Value;49 FList.Free; 45 50 end; 46 51 47 procedure TGDictionary<TPair>.PutKey(Index: TGDictionaryIndex; 48 const AValue: TPair.TKey); 52 function TGDictionary<TKey, TValue>.GetKey(Index: TIndex): TKey; 53 begin 54 Result := FList.Items[Index].Key; 55 end; 56 57 function TGDictionary<TKey, TValue>.GetValue(Key: TKey): TValue; 58 begin 59 Result := FList.Items[SearchKey(Key)].Value; 60 end; 61 62 procedure TGDictionary<TKey, TValue>.PutKey(Index: TIndex; 63 const AValue: TKey); 49 64 var 50 Item: T Pair;65 Item: TDictionaryPair; 51 66 begin 52 67 //Items[Index].Key := AValue; 53 Item := Items[Index];68 Item := FList.Items[Index]; 54 69 Item.Key := AValue; 55 Items[Index] := Item;70 FList.Items[Index] := Item; 56 71 end; 57 72 58 procedure TGDictionary<T Pair>.PutValue(Key: TPair.TKey;59 const AValue: T Pair.TValue);73 procedure TGDictionary<TKey, TValue>.PutValue(Key: TKey; 74 const AValue: TValue); 60 75 var 61 Item: T Pair;62 Index: T GDictionaryIndex;76 Item: TDictionaryPair; 77 Index: TIndex; 63 78 begin 64 79 //Items[SearchKey(Index)].Value := AValue; 65 80 Index := SearchKey(Key); 66 Item := Items[Index];81 Item := FList.Items[Index]; 67 82 Item.Value := AValue; 68 Items[Index] := Item;83 FList.Items[Index] := Item; 69 84 end; 70 85 71 function TGDictionary<T Pair>.SearchKey(Key: TPair.TKey): TGDictionaryIndex;86 function TGDictionary<TKey, TValue>.SearchKey(Key: TKey): TIndex; 72 87 begin 73 88 Result := 0; 74 while Result < Count do begin75 if Items[Result].Key = Key then begin89 while Result < FList.Count do begin 90 if FList.Items[Result].Key = Key then begin 76 91 Break; 77 92 end; … … 80 95 end; 81 96 82 procedure TGDictionary<T Pair>.Add(Key: TPair.TKey; Value: TPair.TValue);97 procedure TGDictionary<TKey, TValue>.Add(Key: TKey; Value: TValue); 83 98 var 84 NewPair: T Pair;99 NewPair: TDictionaryPair; 85 100 begin 86 101 NewPair.Key := Key; 87 102 NewPair.Value := Value; 88 inheritedAdd(NewPair);103 FList.Add(NewPair); 89 104 end; 90 105 -
Generics/NativeGenerics/Units/GenericList.pas
r313 r320 34 34 function Add(Item: TItem): TIndex; 35 35 procedure AddArray(Values: array of TItem); 36 procedure AddList(List: TGList );37 procedure Assign(Source: TGList ); virtual;36 procedure AddList(List: TGList<TItem>); 37 procedure Assign(Source: TGList<TItem>); virtual; 38 38 procedure Clear; virtual; 39 39 procedure Delete(Index: TIndex); virtual; 40 40 procedure DeleteItems(Index, Count: TIndex); 41 function EqualTo(List: TGList ): Boolean;41 function EqualTo(List: TGList<TItem>): Boolean; 42 42 procedure Exchange(Index1, Index2: TIndex); 43 43 procedure Explode(Text, Separator: string; Converter: TFromStringConverter; SlicesCount: Integer = -1); … … 48 48 function Implode(Separator: string; Converter: TToStringConverter): string; 49 49 function IndexOf(Item: TItem; Start: TIndex = 0): TIndex; 50 function IndexOfList(List: TGList ; Start: TIndex = 0): TIndex;50 function IndexOfList(List: TGList<TItem>; Start: TIndex = 0): TIndex; 51 51 procedure Insert(Index: TIndex; Item: TItem); 52 procedure InsertList(Index: TIndex; List: TGList );52 procedure InsertList(Index: TIndex; List: TGList<TItem>); 53 53 procedure InsertArray(Index: TIndex; Values: array of TItem); 54 54 procedure Move(CurIndex, NewIndex: TIndex); … … 64 64 end; 65 65 66 T GListObject<TItem> = class(TGList<TItem>)66 TListObject<TItem> = class(TGList<TItem>) 67 67 private 68 68 procedure Put(Index: Integer; const AValue: TItem); override; … … 76 76 end; 77 77 78 T GListString<TItem> = class(TGList<TItem>)78 TListString<TItem> = class(TGList<TItem>) 79 79 private 80 80 public … … 93 93 RtlConsts; 94 94 95 { TGList }95 { TGList<TItem> } 96 96 97 97 function TGList<TItem>.GetCapacity: TIndex; … … 195 195 end; 196 196 197 procedure TGList<TItem>.Assign(Source: TGList );197 procedure TGList<TItem>.Assign(Source: TGList<TItem>); 198 198 var 199 199 I: TIndex; … … 239 239 end; 240 240 241 procedure TGList<TItem>.InsertList(Index: TIndex; List: TGList );241 procedure TGList<TItem>.InsertList(Index: TIndex; List: TGList<TItem>); 242 242 var 243 243 I: TIndex; … … 250 250 end; 251 251 252 function TGList<TItem>.IndexOfList(List: TGList ; Start: TIndex): TIndex;252 function TGList<TItem>.IndexOfList(List: TGList<TItem>; Start: TIndex): TIndex; 253 253 var 254 254 I: TIndex; … … 353 353 end; 354 354 355 function TGList<TItem>.EqualTo(List: TGList ): Boolean;355 function TGList<TItem>.EqualTo(List: TGList<TItem>): Boolean; 356 356 var 357 357 I: TIndex; … … 453 453 end; 454 454 455 procedure TGList<TItem>.AddList(List: TGList );455 procedure TGList<TItem>.AddList(List: TGList<TItem>); 456 456 var 457 457 I: TIndex; … … 514 514 end; 515 515 516 { T GListObject }517 518 procedure T GListObject<TItem>.Assign(Source: TGList<TItem>);516 { TListObject } 517 518 procedure TListObject<TItem>.Assign(Source: TGList<TItem>); 519 519 begin 520 520 Clear; … … 523 523 end; 524 524 525 procedure T GListObject<TItem>.Put(Index: Integer; const AValue: TItem);525 procedure TListObject<TItem>.Put(Index: Integer; const AValue: TItem); 526 526 begin 527 527 if OwnsObjects then FItems[Index].Free; … … 529 529 end; 530 530 531 procedure T GListObject<TItem>.Delete(Index: Integer);531 procedure TListObject<TItem>.Delete(Index: Integer); 532 532 begin 533 533 if OwnsObjects then FItems[Index].Free; … … 535 535 end; 536 536 537 procedure T GListObject<TItem>.Clear;537 procedure TListObject<TItem>.Clear; 538 538 var 539 539 I: Integer; … … 549 549 end; 550 550 551 constructor T GListObject<TItem>.Create;551 constructor TListObject<TItem>.Create; 552 552 begin 553 553 inherited; … … 555 555 end; 556 556 557 destructor T GListObject<TItem>.Destroy;557 destructor TListObject<TItem>.Destroy; 558 558 begin 559 559 Clear; … … 561 561 end; 562 562 563 { T GListString }564 565 procedure T GListString<TItem>.Assign(Source: TGList<TItem>);563 { TListString } 564 565 procedure TListString<TItem>.Assign(Source: TGList<TItem>); 566 566 begin 567 567 Clear; … … 569 569 end; 570 570 571 procedure T GListString<TItem>.Delete(Index: Integer);571 procedure TListString<TItem>.Delete(Index: Integer); 572 572 begin 573 573 FItems[Index] := ''; … … 575 575 end; 576 576 577 procedure T GListString<TItem>.Clear;577 procedure TListString<TItem>.Clear; 578 578 var 579 579 I: Integer; … … 587 587 end; 588 588 589 constructor T GListString<TItem>.Create;589 constructor TListString<TItem>.Create; 590 590 begin 591 591 inherited; 592 592 end; 593 593 594 destructor T GListString<TItem>.Destroy;594 destructor TListString<TItem>.Destroy; 595 595 begin 596 596 Clear; -
Generics/NativeGenerics/Units/GenericQueue.pas
r132 r320 11 11 TGQueue<TItem> = class 12 12 private 13 type14 TGQueueList = TGList<TItem>;15 13 var 16 FList: TG QueueList;14 FList: TGList<TItem>; 17 15 public 18 16 procedure Enqueue(Value: TItem); … … 21 19 constructor Create; 22 20 destructor Destroy; override; 23 property List: TG QueueListread FList;21 property List: TGList<TItem> read FList; 24 22 end; 25 23 … … 40 38 constructor TGQueue<TItem>.Create; 41 39 begin 42 FList := TGList .Create;40 FList := TGList<TItem>.Create; 43 41 end; 44 42 -
Generics/NativeGenerics/Units/GenericSet.pas
r132 r320 11 11 TGSet<TItem> = class 12 12 private 13 type14 TGSetList = TGList<TItem>;15 13 var 16 FList: TG SetList;14 FList: TGList<TItem>; 17 15 public 18 16 function IsIn(Item: TItem): Boolean; 19 17 constructor Create; 20 18 destructor Destroy; override; 21 property List: TG SetListread FList;19 property List: TGList<TItem> read FList; 22 20 end; 23 21 … … 33 31 constructor TGSet<TItem>.Create; 34 32 begin 35 FList := TGList .Create;33 FList := TGList<TItem>.Create; 36 34 end; 37 35 -
Generics/NativeGenerics/Units/GenericStack.pas
r132 r320 11 11 TGStack<TItem> = class 12 12 private 13 type14 TGStackList = TGList<TItem>;15 13 var 16 FList: TG StackList;14 FList: TGList<TItem>; 17 15 public 18 16 procedure Push(Value: TItem); … … 20 18 constructor Create; 21 19 destructor Destroy; override; 22 property List: TG StackListread FList;20 property List: TGList<TItem> read FList; 23 21 end; 24 22 … … 38 36 constructor TGStack<TItem>.Create; 39 37 begin 40 FList := TGList .Create;38 FList := TGList<TItem>.Create; 41 39 end; 42 40 -
Generics/NativeGenerics/Units/GenericStream.pas
r313 r320 1 1 unit GenericStream; 2 2 3 {$mode Delphi}{$H+}3 {$mode delphi}{$H+} 4 4 5 5 interface 6 6 7 7 uses 8 Classes, SysUtils;8 SysUtils, Classes, GenericList; 9 9 10 10 type 11 11 TGStream<TItem> = class 12 public 13 type 14 TIndex = NativeInt; 15 TItemArray = array of TItem; 16 TSeekOrigin = (soBeginning, soCurrent, soEnd); 17 private 18 procedure SetSize(AValue: TIndex); 19 function GetSize: TIndex; 20 procedure SetPosition(AValue: TIndex); 21 function GetPosition: TIndex; 22 public 23 procedure Assign(Source: TGStream<TItem>); virtual; 24 procedure Write(Item: TItem); virtual; abstract; 25 procedure WriteArray(Item: array of TItem); virtual; abstract; 26 function Read: TItem; virtual; abstract; 27 function ReadArray(Count: TIndex): TItemArray; virtual; abstract; 28 function Insert(Count: TIndex): TIndex; virtual; abstract; 29 function Remove(Count: TIndex): TIndex; virtual; abstract; 30 function Seek(Offset: TIndex; Origin: TSeekOrigin = soCurrent): 31 TIndex; virtual; abstract; 32 constructor Create; virtual; 33 property Position: TIndex read GetPosition write SetPosition; 34 property Size: TIndex read GetSize write SetSize; 35 end; 12 36 13 end;14 37 15 38 implementation 16 39 40 41 procedure TGStream<TItem>.Assign(Source: TGStream<TItem>); 42 begin 43 end; 44 45 procedure TGStream<TItem>.SetPosition(AValue: TIndex); 46 begin 47 Seek(AValue, soBeginning); 48 end; 49 50 function TGStream<TItem>.GetPosition: TIndex; 51 begin 52 Result := Seek(0, soCurrent); 53 end; 54 55 procedure TGStream<TItem>.SetSize(AValue: TIndex); 56 var 57 StreamSize: TIndex; 58 OldPosition: TIndex; 59 begin 60 OldPosition := Seek(0, soCurrent); 61 StreamSize := Size; 62 if AValue > StreamSize then begin 63 Seek(StreamSize, soBeginning); 64 Insert(AValue - StreamSize); 65 end else 66 if AValue < StreamSize then begin 67 Seek(AValue, soBeginning); 68 Remove(StreamSize - AValue); 69 end; 70 Position := OldPosition; 71 end; 72 73 function TGStream<TItem>.GetSize: TIndex; 74 var 75 OldPosition: Integer; 76 begin 77 OldPosition := Position; 78 Result := Seek(0, soEnd); 79 Position := OldPosition; 80 end; 81 82 constructor TGStream<TItem>.Create; 83 begin 84 inherited; 85 end; 86 17 87 end. 18
Note:
See TracChangeset
for help on using the changeset viewer.