Janilabo

Janilabo | TIA Matching Commands [SCAR Divi]

Dec 8th, 2012
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 3.70 KB | None | 0 0
  1. {==============================================================================]  
  2.   Explanation: Returns the count where TIA1[*] matches TIA2[*] (*=same position!)                  
  3. [==============================================================================}
  4. function TIAMatch(TIA1, TIA2: TIntArray): Integer;
  5. var
  6.   i, m: Integer;
  7. begin
  8.   m := Min(High(TIA1), High(TIA2));
  9.   if (m > -1) then
  10.     for i := 0 to m do
  11.       if (TIA1[i] = TIA2[i]) then
  12.         Inc(Result);
  13. end;
  14.  
  15. {==============================================================================]  
  16.   Explanation: Returns the positions where TIA1[*] matches TIA2[*] (*=same position!)                  
  17. [==============================================================================}
  18. function TIAMatches(TIA1, TIA2: TIntArray): TIntArray;
  19. var
  20.   i, m, r: Integer;
  21. begin
  22.   m := Min(High(TIA1), High(TIA2));
  23.   if (m > -1) then
  24.   begin  
  25.     SetLength(Result, (m + 1));
  26.     for i := 0 to m do
  27.       if (TIA1[i] = TIA2[i]) then
  28.       begin
  29.         Result[r] := i;
  30.         Inc(r);
  31.       end;
  32.     SetLength(Result, r);  
  33.   end;        
  34. end;
  35.  
  36. {==============================================================================]  
  37.   Explanation: Returns the count where TIA1[*] matches TIA2[*] (*=same position!)
  38.                If either TIA1[*] or TIA2[*] contains any value from specialMatches, it will be counted as match.                  
  39. [==============================================================================}
  40. function TIAMatchEx(TIA1, TIA2: TIntArray; specialMatches: TIntArray): Integer;
  41. var
  42.   i, m: Integer;
  43. begin
  44.   m := Min(High(TIA1), High(TIA2));
  45.   if (m > -1) then
  46.     for i := 0 to m do
  47.     case (TIA1[i] = TIA2[i]) of
  48.       True: Inc(Result);
  49.       False:
  50.       if (TIAContains(specialMatches, TIA1[i]) or TIAContains(specialMatches, TIA2[i])) then
  51.         Inc(Result);
  52.     end;        
  53. end;
  54.  
  55. {==============================================================================]  
  56.   Explanation: Returns the positions where TIA1[*] matches TIA2[*] (*=same position!)
  57.                If either TIA1[*] or TIA2[*] contains any value from specialMatches, it will be counted as match.                  
  58. [==============================================================================}
  59. function TIAMatchesEx(TIA1, TIA2: TIntArray; specialMatches: TIntArray): TIntArray;
  60. var
  61.   i, m, r: Integer;
  62. begin
  63.   m := Min(High(TIA1), High(TIA2));
  64.   if (m > -1) then                
  65.   begin
  66.     SetLength(Result, (m + 1));
  67.     for i := 0 to m do
  68.     case (TIA1[i] = TIA2[i]) of
  69.       True:
  70.       begin
  71.         Result[r] := i;
  72.         Inc(r);    
  73.       end;
  74.       False:
  75.       if (TIAContains(specialMatches, TIA1[i]) or TIAContains(specialMatches, TIA2[i])) then
  76.       begin
  77.         Result[r] := i;
  78.         Inc(r);    
  79.       end;
  80.     end;
  81.     SetLength(Result, r);
  82.   end;        
  83. end;
  84.  
  85. var
  86.   TIA, TIA1, TIA2: TIntArray;
  87.  
  88. begin
  89.   ClearDebug;
  90.   TIA1 := [0, 1, 2, 3, 4, 3, 2, 1, 0];
  91.   WriteLn('TIA1: ' + TIAToStr(TIA1) + ' [' + IntToStr(Length(TIA1)) + ' items]');
  92.   TIA2 := [1, 1, 2, 2, 3, 3, 2, 2, 1, 1, 0];                              
  93.   WriteLn('TIA2: ' + TIAToStr(TIA2) + ' [' + IntToStr(Length(TIA2)) + ' items]' + #13#10);
  94.   WriteLn('TIAMatch(TIA1, TIA2): ' + IntToStr(TIAMatch(TIA1, TIA2)));  
  95.   TIA := TIAMatches(TIA1, TIA2);
  96.   WriteLn('TIAMatches(TIA1, TIA2): ' + TIAToStr(TIA) + #13#10);
  97.   SetLength(TIA, 0);
  98.   WriteLn('TIAMatchEx(TIA1, TIA2, [4, 0]): ' + IntToStr(TIAMatchEx(TIA1, TIA2, [4, 0])));
  99.   TIA := TIAMatchesEx(TIA1, TIA2, [4, 0]);
  100.   WriteLn('TIAMatchesEx(TIA1, TIA2, [4, 0]): ' + TIAToStr(TIA));
  101.   SetLength(TIA, 0);                                      
  102.   SetLength(TIA1, 0);
  103.   SetLength(TIA2, 0);
  104. end.
Advertisement
Add Comment
Please, Sign In to add comment