Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- library integer_;
- uses
- FastShareMem,
- SysUtils,
- Math;
- {$R *.res}
- type
- MSSL_TControlMethod = (cm_None, cm_Filter, cm_Extract);
- MSSL_TPartitionMethod = (pm_PartSize, pm_PartAmount);
- TIntegerArray = array of Integer;
- TIntArray = TIntegerArray;
- T2DIntegerArray = array of TIntegerArray;
- T2DIntArray = T2DIntegerArray;
- function TIAContains(TIA: TIntArray; x: Integer): Boolean;
- var
- h, i: Integer;
- begin
- h := High(TIA);
- for i := 0 to h do
- if (TIA[i] = x) then
- Break;
- Result := ((h > -1) and (i <= h));
- end;
- procedure TIARemoveEx(var TIA: TIntArray; x: Integer; all: Boolean);
- var
- h, i, d: Integer;
- begin
- h := High(TIA);
- if (h > -1) then
- begin
- case all of
- True:
- for i := h downto 0 do
- if (TIA[i] = x) then
- begin
- for d := i to (h - 1) do
- TIA[d] := TIA[(d + 1)];
- Dec(h);
- end;
- False:
- for i := 0 to h do
- if (TIA[i] = x) then
- begin
- for d := i to (h - 1) do
- TIA[d] := TIA[(d + 1)];
- Dec(h);
- Break;
- end;
- end;
- SetLength(TIA, (h + 1));
- end;
- end;
- {==============================================================================]
- Explanation: Returns a TIA that contains all the value from start value (aStart)
- to finishing value (aFinish)..
- [==============================================================================}
- function MSSL_TIAByRange(aStart, aFinish: Integer): TIntArray; stdcall;
- var
- i, s, f: Integer;
- begin
- if (aStart <> aFinish) then
- begin
- s := Integer(aStart);
- f := Integer(aFinish);
- SetLength(Result, (Abs(aStart - aFinish) + 1));
- case (aStart > aFinish) of
- True:
- for i := s downto f do
- Result[(s - i)] := i;
- False:
- for i := s to f do
- Result[(i - s)] := i;
- end;
- end else
- begin
- SetLength(Result, 1);
- Result[0] := Integer(aStart);
- end;
- end;
- {==============================================================================]
- Explanation: Returns a TIA that contains all the value from start value (aStart)
- to finishing value (aFinish)..
- Works with 2-bit method, that cuts loop in half.
- [==============================================================================}
- function MSSL_TIAByRange2bit(aStart, aFinish: Integer): TIntArray; stdcall;
- var
- g, l, i, s, f: Integer;
- begin
- if (aStart <> aFinish) then
- begin
- s := Integer(aStart);
- f := Integer(aFinish);
- l := (Abs(aStart - aFinish) + 1);
- SetLength(Result, l);
- g := ((l - 1) div 2);
- case (aStart < aFinish) of
- True:
- begin
- for i := 0 to g do
- begin
- Result[i] := (s + i);
- Result[((l - 1) - i)] := (f - i);
- end;
- if ((l mod 2) <> 0) then
- Result[i] := (s + i);
- end;
- False:
- begin
- for i := 0 to g do
- begin
- Result[i] := (s - i);
- Result[((l - 1) - i)] := (f + i);
- end;
- if ((l mod 2) <> 0) then
- Result[i] := (s - i);
- end;
- end;
- end else
- begin
- SetLength(Result, 1);
- Result[0] := Integer(aStart);
- end;
- end;
- {==============================================================================]
- Explanation: Returns array of x, count being the size of the result.
- [==============================================================================}
- function MSSL_TIAOfInteger(x, count: Integer): TIntArray; stdcall;
- var
- i: Integer;
- begin
- if (count > 0) then
- begin
- SetLength(Result, count);
- for i := 0 to (count - 1) do
- Result[i] := Integer(x);
- end else
- SetLength(Result, 0);
- end;
- {==============================================================================]
- Explanation: Converts integer value (int) to digits of it.
- Example: 1234 => 1,2,3,4
- [==============================================================================}
- function MSSL_IntDigits(int: Integer): TIntArray; stdcall;
- var
- s: string;
- l, i: Integer;
- begin
- s := IntToStr(Abs(int));
- l := Length(s);
- SetLength(Result, l);
- for i := 0 to (l - 1) do
- Result[i] := StrToInt(s[(i + 1)]);
- end;
- {==============================================================================]
- Explanation: Returns true if str is integer value.
- [==============================================================================}
- function MSSL_StrIsInt(str: string): Boolean; stdcall;
- begin
- try
- StrToInt(str);
- Result := True;
- except
- Result := False;
- end;
- end;
- {==============================================================================]
- Explanation: Sets minimum value (x) to val.
- [==============================================================================}
- procedure MSSL_IntSetMin(var val: Integer; x: Integer); stdcall;
- begin
- if (val < x) then
- val := Integer(x);
- end;
- {==============================================================================]
- Explanation: Sets maximum value (x) to val.
- [==============================================================================}
- procedure MSSL_IntSetMax(var val: Integer; x: Integer); stdcall;
- begin
- if (val > x) then
- val := Integer(x);
- end;
- {==============================================================================]
- Explanation: Sets val inside range (mn = minimum, mx = maximum)
- [==============================================================================}
- procedure MSSL_IntSetRange(var val: Integer; mn, mx: Integer); stdcall;
- var
- t: Integer;
- begin
- if (mn > mx) then
- begin
- t := mn;
- mn := mx;
- mx := t;
- end;
- if (mn <> mx) then
- begin
- if (val < mn) then
- val := Integer(mn);
- if (val > mx) then
- val := Integer(mx);
- end else
- if ((val < mn) or (val > mx)) then
- val := Integer(mn);
- end;
- {==============================================================================]
- Explanation: Sets minimum value (x) to TIA items.
- [==============================================================================}
- procedure MSSL_TIASetMin(var TIA: TIntArray; x: Integer); stdcall;
- var
- h, i: Integer;
- begin
- h := High(TIA);
- for i := 0 to h do
- if (TIA[i] < x) then
- TIA[i] := Integer(x);
- end;
- {==============================================================================]
- Explanation: Sets maximum value (x) to TIA items.
- [==============================================================================}
- procedure MSSL_TIASetMax(var TIA: TIntArray; x: Integer); stdcall;
- var
- h, i: Integer;
- begin
- h := High(TIA);
- for i := 0 to h do
- if (TIA[i] > x) then
- TIA[i] := Integer(x);
- end;
- {==============================================================================]
- Explanation: Sets TIA values inside range (mn = minimum, mx = maximum)
- [==============================================================================}
- procedure MSSL_TIASetRange(var TIA: TIntArray; mn, mx: Integer); stdcall;
- var
- h, i, t: Integer;
- begin
- if (mn > mx) then
- begin
- t := mn;
- mn := mx;
- mx := t;
- end;
- h := High(TIA);
- if (h > -1) then
- case (mn = mx) of
- True:
- for i := 0 to h do
- if ((TIA[i] < mn) or (TIA[i] > mx)) then
- TIA[i] := Integer(mn);
- False:
- for i := 0 to h do
- begin
- if (TIA[i] < mn) then
- TIA[i] := Integer(mn);
- if (TIA[i] > mx) then
- TIA[i] := Integer(mx);
- end;
- end;
- end;
- {==============================================================================]
- Explanation: Control's TIA by range. Contains actions for 2 methods: cm_Filter and cm_Extract.
- [==============================================================================}
- procedure MSSL_TIAControlByRange(var TIA: TIntArray; minimum, maximum: Integer; method: MSSL_TControlMethod); stdcall;
- var
- h, i, l, v: Integer;
- begin
- h := High(TIA);
- if ((minimum <= maximum) and (h > -1) and (method <> cm_None)) then
- case method of
- cm_Filter:
- for i := h downto 0 do
- if ((TIA[i] >= minimum) and (TIA[i] <= maximum)) then
- begin
- l := Length(TIA);
- for v := i to (l - 2) do
- TIA[v] := TIA[(v + 1)];
- SetLength(TIA, (l - 1));
- end;
- cm_Extract:
- for i := h downto 0 do
- if ((TIA[i] < minimum) or (TIA[i] > maximum)) then
- begin
- l := Length(TIA);
- for v := i to (l - 2) do
- TIA[v] := TIA[(v + 1)];
- SetLength(TIA, (l - 1));
- end;
- end;
- end;
- {==============================================================================]
- Explanation: Returns true if TIA is built ONLY with allowed values.
- [==============================================================================}
- function MSSL_TIABuiltWith(TIA, allowed: TIntArray): Boolean; stdcall;
- var
- h, l, i, v: Integer;
- begin
- Result := False;
- l := Length(TIA);
- h := High(allowed);
- if ((h > -1) and (l > 0)) then
- begin
- for i := 0 to h do
- begin
- for v := 0 to (l - 1) do
- if (TIA[v] = allowed[i]) then
- Break;
- if (v >= l) then
- Exit;
- end;
- Result := True;
- end;
- end;
- {==============================================================================]
- Explanation: Randomizes TIA.
- Example: [1, 2, 3] => [2, 3, 1]
- The higher count of shuffles is, the "stronger" randomization you'll get.
- [==============================================================================}
- procedure MSSL_TIARandomizeEx(var TIA: TIntArray; shuffles: Integer); stdcall;
- var
- a, b, l, i, t, v: Integer;
- begin
- l := Length(TIA);
- if ((l > 1) and (shuffles > 0)) then
- for t := 1 to shuffles do
- for i := 0 to (l - 1) do
- begin
- a := Random(l);
- b := Random(l);
- if (a <> b) then
- begin
- v := TIA[a];
- TIA[a] := TIA[b];
- TIA[b] := v;
- end;
- end;
- end;
- {==============================================================================]
- Explanation: Randomizes TIA.
- Example: [1, 2, 3] => [2, 3, 1]
- [==============================================================================}
- procedure MSSL_TIARandomize(var TIA: TIntArray); stdcall;
- begin
- MSSL_TIARandomizeEx(TIA, 1);
- end;
- {==============================================================================]
- Explanation: Deletes item with index (x) from TIA. Returns true with success.
- [==============================================================================}
- function MSSL_TIADelete(var TIA: TIntArray; x: Integer): Boolean; stdcall;
- var
- h, i, v: Integer;
- begin
- h := High(TIA);
- Result := ((x <= h) and (x > -1));
- if Result then
- begin
- for i := v to (h - 1) do
- TIA[i] := TIA[(i + 1)];
- SetLength(TIA, h);
- end;
- end;
- {==============================================================================]
- Explanation: Removes integers from TIA, x = array of indexes.
- [==============================================================================}
- procedure MSSL_TIARemove(var TIA: TIntArray; x: TIntArray); stdcall;
- var
- i, h, h2, v: Integer;
- begin
- h := High(TIA);
- h2 := High(x);
- if ((h > -1) and (h2 > -1)) then
- for i := 0 to h2 do
- if ((x[i] <= h) and (x[i] > -1)) then
- begin
- for v := x[i] to (h - 1) do
- TIA[v] := TIA[(v + 1)];
- SetLength(TIA, h);
- Dec(h);
- end;
- end;
- {==============================================================================]
- Explanation: Adds all addTIA items to TIA. Returns the highest index in the end.
- [==============================================================================}
- function MSSL_TIAAdd(var TIA: TIntArray; addTIA: TIntArray): Integer; stdcall;
- var
- h, l, i: Integer;
- begin
- h := High(addTIA);
- if (h > -1) then
- begin
- l := Length(TIA);
- SetLength(TIA, (l + (h + 1)));
- for i := 0 to h do
- TIA[(i + l)] := Integer(addTIA[i]);
- end;
- Result := High(TIA);
- end;
- {==============================================================================]
- Explanation: Returns all the TIA positions where x can be found.
- [==============================================================================}
- function MSSL_TIAPositions(TIA: TIntArray; x: Integer): TIntArray; stdcall;
- var
- i, h, r: Integer;
- begin
- h := High(TIA);
- if (h > -1) then
- begin
- SetLength(Result, (h + 1));
- for i := 0 to h do
- if (TIA[i] = x) then
- begin
- Result[r] := i;
- Inc(r);
- end;
- end;
- SetLength(Result, r);
- end;
- {==============================================================================]
- Explanation: Returns the TIA positions where index contains any integer from ints.
- NOTE: Doesn't return ALL indexes, like MSSL_TIAPositionsEx() does.
- [==============================================================================}
- function MSSL_TIAPositionsMulti(TIA, ints: TIntArray): TIntArray; stdcall;
- var
- a, b, i, h: Integer;
- begin
- h := High(ints);
- b := High(TIA);
- if ((b > -1) and (h > -1)) then
- begin
- SetLength(Result, (h + 1));
- for i := 0 to h do
- begin
- Result[i] := -1;
- for a := 0 to b do
- if (TIA[a] = ints[i]) then
- begin
- Result[i] := a;
- Break;
- end;
- end;
- end else
- SetLength(Result, 0);
- end;
- {==============================================================================]
- Explanation: Returns all the TIA positions where index contains any integer from ints.
- [==============================================================================}
- function MSSL_TIAPositionsEx(TIA, ints: TIntArray): TIntArray; stdcall;
- var
- i, h, r, l, v: Integer;
- begin
- h := High(TIA);
- l := Length(ints);
- if ((l > 0) and (h > -1)) then
- begin
- SetLength(Result, (h + 1));
- for i := 0 to h do
- begin
- for v := 0 to (l - 1) do
- if (ints[v] = TIA[i]) then
- Break;
- if (v < l) then
- begin
- Result[r] := i;
- Inc(r);
- end;
- end;
- end;
- SetLength(Result, r);
- end;
- {==============================================================================]
- Explanation: Copies TIA from pos1 to pos2.
- [==============================================================================}
- function MSSL_TIACopyEx(TIA: TIntArray; pos1, pos2: Integer): TIntArray; stdcall;
- var
- i, l: Integer;
- begin
- l := Length(TIA);
- if (l > 0) then
- begin
- MSSL_IntSetRange(pos1, 0, (l - 1));
- MSSL_IntSetRange(pos2, 0, (l - 1));
- case (pos1 <> pos2) of
- True:
- begin
- SetLength(Result, (Abs(pos1 - pos2) + 1));
- case (pos1 < pos2) of
- True:
- for i := pos1 to pos2 do
- Result[(i - pos1)] := Integer(TIA[i]);
- False:
- for i := pos1 downto pos2 do
- Result[(pos1 - i)] := Integer(TIA[i]);
- end;
- end;
- False:
- begin
- SetLength(Result, 1);
- Result[0] := Integer(TIA[pos1]);
- end;
- end;
- end else
- SetLength(Result, 0);
- end;
- {==============================================================================]
- Explanation: Moves oldIndex to newIndex in TIA. Returns true, if movement was succesfully done!
- [==============================================================================}
- function MSSL_TIAMove(var TIA: TIntArray; oldIndex, newIndex: Integer): Boolean; stdcall;
- var
- h, i, t: Integer;
- begin
- h := High(TIA);
- Result := ((h > 0) and (oldIndex <> newIndex) and InRange(oldIndex, 0, h) and InRange(newIndex, 0, h));
- if Result then
- case (oldIndex > newIndex) of
- True:
- for i := oldIndex downto (newIndex + 1) do
- begin
- t := TIA[i];
- TIA[i] := TIA[(i - 1)];
- TIA[(i - 1)] := t;
- end;
- False:
- for i := oldIndex to (newIndex - 1) do
- begin
- t := TIA[i];
- TIA[i] := TIA[(i + 1)];
- TIA[(i + 1)] := t;
- end;
- end;
- end;
- {==============================================================================]
- Explanation: Breaks TIA to parts (TIA => ATIA). Contains 2 methods:
- -pm_PartSize (Breaks TIA to ATIA by size of the parts) [x = size]
- -pm_PartAmount (Breaks TIA to ATIA by amount of the parts) [x = amount]
- [==============================================================================}
- function MSSL_TIAToParts(TIA: TIntArray; method: MSSL_TPartitionMethod; x: Integer): T2DIntArray; stdcall;
- var
- a, e, h, h2, i, i2, p, l, z: Integer;
- f: Boolean;
- begin
- h := High(TIA);
- case ((h > -1) and (x > 0)) of
- True:
- begin
- case method of
- pm_PartSize:
- if (x <= h) then
- begin
- Inc(h);
- p := (h div x);
- if ((p * x) < h) then
- Inc(p);
- SetLength(Result, p);
- for i := 0 to (p - 1) do
- for i2 := 0 to (x - 1) do
- begin
- SetLength(Result[i], x);
- if (a < h) then
- begin
- Result[i][i2] := Integer(TIA[a]);
- Inc(a);
- end else
- begin
- SetLength(Result[i], i2);
- Exit;
- end;
- end;
- end else
- f := True;
- pm_PartAmount:
- case (h <= 0) of
- False:
- begin
- if (h < (x - 1)) then
- x := (h + 1);
- p := Floor((h + 1) / x);
- if (p = 0) then
- p := 1;
- e := ((h + 1) - (p * x));
- if (e >= (h + 1)) then
- e := 0;
- SetLength(Result, x);
- for i := 0 to (x - 1) do
- begin
- if ((e >= (i + 1)) and (e > 0)) then
- SetLength(Result[i], (p + 1))
- else
- if (i <= h) then
- SetLength(Result[i], p);
- h2 := High(Result[i]);
- for i2 := 0 to h2 do
- begin
- Result[i][i2] := Integer(TIA[a]);
- Inc(a);
- end;
- end;
- end;
- True: f := True;
- end;
- end;
- if f then
- begin
- SetLength(Result, 1);
- l := Length(TIA);
- SetLength(Result[0], l);
- for z := 0 to (l - 1) do
- Result[0][z] := Integer(TIA[z]);
- end;
- end;
- False: SetLength(Result, 0);
- end;
- end;
- {==============================================================================]
- Explanation: Returns a TIA from start position, where step is the difference between each range value.
- Count is the size of the result..
- Examples: (3, -1, 3) => [3, 2, 1] and (0, 2, 4) => [0, 2, 4, 6]
- [==============================================================================}
- function MSSL_TIARangeFrom(start, step, count: Integer): TIntArray; stdcall;
- var
- i: Integer;
- begin
- case (count > 0) of
- True:
- begin
- SetLength(Result, count);
- for i := 0 to (count - 1) do
- Result[i] := (start + (i * step));
- end;
- False: SetLength(Result, 0);
- end;
- end;
- {==============================================================================]
- Explanation: Returns array of items from TIA by IDs.
- Stores invalid ID's [index positions] to iIDs.
- [==============================================================================}
- function MSSL_TIAGetEx(TIA, IDs: TIntArray; var iIDs: TIntArray): TIntArray; stdcall;
- var
- i, h, h2, iC, rC: Integer;
- begin
- SetLength(Result, 0);
- h := High(TIA);
- h2 := High(IDs);
- case ((h2 > -1) and (h > -1)) of
- True:
- begin
- SetLength(Result, (h2 + 1));
- SetLength(iIDs, (h2 + 1));
- for i := 0 to h2 do
- case ((IDs[i] <= h) and (IDs[i] > -1)) of
- True:
- begin
- Result[rC] := Integer(TIA[IDs[i]]);
- Inc(rC);
- end;
- False:
- begin
- iIDs[iC] := i;
- Inc(iC);
- end;
- end;
- SetLength(iIDs, iC);
- end;
- False:
- begin
- SetLength(iIDs, (h2 + 1));
- for i := 0 to h2 do
- iIDs[i] := Integer(IDs[i]);
- end;
- end;
- SetLength(Result, rC);
- end;
- {==============================================================================]
- Explanation: Returns item[s] from TIA by IDs. Ignores invalid ID's.
- [==============================================================================}
- function MSSL_TIAGet(TIA, IDs: TIntArray): TIntArray; stdcall;
- var
- i, h, h2, r: Integer;
- begin
- h := High(TIA);
- h2 := High(IDs);
- if ((h2 > -1) and (h > -1)) then
- begin
- SetLength(Result, (h2 + 1));
- for i := 0 to h2 do
- if ((IDs[i] <= h) and (IDs[i] > -1)) then
- begin
- Result[r] := Integer(TIA[IDs[i]]);
- Inc(r);
- end;
- end;
- SetLength(Result, r);
- end;
- {==============================================================================]
- Explanation: Removes integers by x from TIA.
- [==============================================================================}
- procedure MSSL_TIARemoveEx(var TIA: TIntArray; x: TIntArray); stdcall;
- var
- i: Integer;
- begin
- for i := High(x) downto 0 do
- begin
- TIARemoveEx(TIA, x[i], True);
- if (High(TIA) < 0) then
- Break;
- TIARemoveEx(x, x[i], True);
- end;
- end;
- {==============================================================================]
- Explanation: Copies source to target. If resetTarget is set to true,
- target will be cleared before the copying process.
- [==============================================================================}
- procedure MSSL_TIACopy(source: TIntArray; var target: TIntArray; resetTarget: Boolean); stdcall;
- var
- i, tAL, sAL: Integer;
- begin
- if resetTarget then
- SetLength(target, 0);
- tAL := Length(target);
- sAL := Length(source);
- SetLength(target, (tAL + sAL));
- for i := 0 to (sAL - 1) do
- target[(tAL + i)] := Integer(source[i]);
- end;
- {==============================================================================]
- Explanation: Moves source to target. If resetTarget is set to true,
- target will be cleared before the moving process.
- [==============================================================================}
- procedure MSSL_TIATransferEx(var source, target: TIntArray; resetTarget: Boolean); stdcall;
- begin
- MSSL_TIACopy(source, target, resetTarget);
- SetLength(source, 0);
- end;
- {==============================================================================]
- Explanation: Moves source to target.
- NOTE: Target wont get cleaned before moving source!
- [==============================================================================}
- procedure MSSL_TIATransfer(var source, target: TIntArray); stdcall;
- begin
- MSSL_TIACopy(source, target, False);
- SetLength(source, 0);
- end;
- {==============================================================================]
- Explanation: Plants/places ints to index position in TIA.
- Like TIAInsert(), with an exception that this inserts array of integers.
- Returns the highest index from TIA in the end.
- [==============================================================================}
- function MSSL_TIAPlant(var TIA: TIntArray; index: Integer; ints: TIntArray): Integer; stdcall;
- var
- i, l, h: Integer;
- begin
- h := High(ints);
- if (h > -1) then
- begin
- l := Length(TIA);
- SetLength(TIA, (l + (h + 1)));
- if (index < 0) then
- index := 0;
- if (index > l) then
- index := l;
- for i := (l + (h + 1) - 1) downto (index + (h + 1)) do
- TIA[i] := TIA[(i - (h + 1))];
- for i := 0 to h do
- TIA[(i + index)] := Integer(ints[i]);
- end;
- Result := High(TIA);
- end;
- {==============================================================================]
- Explanation: Returns integer (by pick_ID) from TIA and then deletes it from TIA.
- Result will be -1, if TIA is empty of pick_ID invalid.
- [==============================================================================}
- function MSSL_TIAPick(var TIA: TIntArray; pick_ID: Integer): Integer; stdcall;
- var
- h, i: Integer;
- begin
- h := High(TIA);
- if ((h > -1) and InRange(pick_ID, 0, h)) then
- begin
- Result := Integer(TIA[pick_ID]);
- for i := pick_ID to (h - 1) do
- TIA[i] := TIA[(i + 1)];
- SetLength(TIA, h);
- end else
- Result := -1;
- end;
- {==============================================================================]
- Explanation: Returns integers (by pick_IDs) from TIA and then deletes em. Ignores invalid indexes. DYNAMIC!
- [==============================================================================}
- function MSSL_TIAPickEx(var TIA: TIntArray; pick_IDs: TIntArray): TIntArray; stdcall;
- var
- h, h2, i, d, r: Integer;
- begin
- h2 := High(TIA);
- h := High(pick_IDs);
- if ((h2 > -1) and (h > -1)) then
- begin
- SetLength(Result, (h2 + 1));
- for i := 0 to h do
- if ((pick_IDs[i] <= h2) and (pick_IDs[i] > -1)) then
- begin
- Result[r] := Integer(TIA[pick_IDs[i]]);
- Inc(r);
- for d := pick_IDs[i] to (h2 - 1) do
- TIA[d] := TIA[(d + 1)];
- Dec(h2);
- if (h2 < 0) then
- Break;
- end;
- SetLength(TIA, h2);
- SetLength(Result, r);
- end else
- SetLength(Result, 0);
- end;
- {==============================================================================]
- Explanation: Returns the count where TIA1[*] matches TIA2[*] (*=same position!)
- If either TIA1[*] or TIA2[*] contains any value from specialMatches, it will be counted as match.
- [==============================================================================}
- function MSSL_TIAMatchEx(TIA1, TIA2, specialMatches: TIntArray): Integer; stdcall;
- var
- i, m: Integer;
- begin
- Result := 0;
- m := Min(High(TIA1), High(TIA2));
- for i := 0 to m do
- case (TIA1[i] = TIA2[i]) of
- True: Inc(Result);
- False:
- if (TIAContains(specialMatches, TIA1[i]) or TIAContains(specialMatches, TIA2[i])) then
- Inc(Result);
- end;
- end;
- {==============================================================================]
- Explanation: Returns the count where TIA1[*] matches TIA2[*] (*=same position!)
- If either TIA1[*] or TIA2[*] contains specialMatch value, it will be counted as match.
- [==============================================================================}
- function MSSL_TIAMatch2(TIA1, TIA2: TIntArray; specialMatch: Integer): Integer; stdcall;
- var
- i, m: Integer;
- begin
- Result := 0;
- m := Min(High(TIA1), High(TIA2));
- for i := 0 to m do
- case (TIA1[i] = TIA2[i]) of
- True: Inc(Result);
- False:
- if ((TIA1[i] = specialMatch) or (TIA2[i] = specialMatch)) then
- Inc(Result);
- end;
- end;
- {==============================================================================]
- Explanation: Returns the count where TIA1[*] matches TIA2[*] (*=same position!)
- [==============================================================================}
- function MSSL_TIAMatch(TIA1, TIA2: TIntArray): Integer; stdcall;
- var
- i, m: Integer;
- begin
- Result := 0;
- m := Min(High(TIA1), High(TIA2));
- for i := 0 to m do
- if (TIA1[i] = TIA2[i]) then
- Inc(Result);
- end;
- {==============================================================================]
- Explanation: Returns the positions where TIA1[*] matches TIA2[*] (*=same position!)
- If either TIA1[*] or TIA2[*] contains any value from specialMatches, it will be counted as match.
- [==============================================================================}
- function MSSL_TIAMatchesEx(TIA1, TIA2, specialMatches: TIntArray): TIntArray; stdcall;
- var
- i, m, r: Integer;
- begin
- m := Min(High(TIA1), High(TIA2));
- if (m > -1) then
- begin
- SetLength(Result, (m + 1));
- for i := 0 to m do
- case (TIA1[i] = TIA2[i]) of
- True:
- begin
- Result[r] := i;
- Inc(r);
- end;
- False:
- if (TIAContains(specialMatches, TIA1[i]) or TIAContains(specialMatches, TIA2[i])) then
- begin
- Result[r] := i;
- Inc(r);
- end;
- end;
- SetLength(Result, r);
- end else
- SetLength(Result, 0);
- end;
- {==============================================================================]
- Explanation: Returns the positions where TIA1[*] matches TIA2[*] (*=same position!)
- If either TIA1[*] or TIA2[*] contains specialMatch value, it will be counted as match.
- [==============================================================================}
- function MSSL_TIAMatches2(TIA1, TIA2: TIntArray; specialMatch: Integer): TIntArray; stdcall;
- var
- i, m, r: Integer;
- begin
- m := Min(High(TIA1), High(TIA2));
- if (m > -1) then
- begin
- SetLength(Result, (m + 1));
- for i := 0 to m do
- case (TIA1[i] = TIA2[i]) of
- True:
- begin
- Result[r] := i;
- Inc(r);
- end;
- False:
- if ((TIA1[i] = specialMatch) or (TIA2[i] = specialMatch)) then
- begin
- Result[r] := i;
- Inc(r);
- end;
- end;
- SetLength(Result, r);
- end else
- SetLength(Result, 0);
- end;
- {==============================================================================]
- Explanation: Returns the positions where TIA1[*] matches TIA2[*] (*=same position!)
- [==============================================================================}
- function MSSL_TIAMatches(TIA1, TIA2: TIntArray): TIntArray; stdcall;
- var
- i, m, r: Integer;
- begin
- m := Min(High(TIA1), High(TIA2));
- if (m > -1) then
- begin
- SetLength(Result, (m + 1));
- for i := 0 to m do
- if (TIA1[i] = TIA2[i]) then
- begin
- Result[r] := i;
- Inc(r);
- end;
- SetLength(Result, r);
- end else
- SetLength(Result, 0);
- end;
- {==============================================================================]
- Explanation: Returns the count of positions where TIA1[*] does not match TIA2[*].
- (* = same positions)
- [==============================================================================}
- function MSSL_TIAUnmatch(TIA1, TIA2: TIntArray): Integer; stdcall;
- var
- i, m: Integer;
- begin
- Result := 0;
- m := Min(High(TIA1), High(TIA2));
- for i := 0 to m do
- if (TIA1[i] <> TIA2[i]) then
- Inc(Result);
- end;
- {==============================================================================]
- Explanation: Returns all positions where TIA1[*] does not match TIA2[*].
- (* = same positions)
- [==============================================================================}
- function MSSL_TIAUnmatches(TIA1, TIA2: TIntArray): TIntArray; stdcall;
- var
- i, m, r: Integer;
- begin
- m := Min(High(TIA1), High(TIA2));
- if (m > -1) then
- begin
- SetLength(Result, (m + 1));
- for i := 0 to m do
- if (TIA1[i] <> TIA2[i]) then
- begin
- Result[r] := i;
- Inc(r);
- end;
- end;
- SetLength(Result, r);
- end;
- {==============================================================================]
- Explanation: Will return all the items that are unique in TIA.
- [==============================================================================}
- function MSSL_TIAGetUniques(TIA: TIntArray): TIntArray; stdcall;
- var
- h, i, i2, r: Integer;
- begin
- h := High(TIA);
- if (h < 1) then
- begin
- SetLength(Result, (h + 1));
- for i := 0 to h do
- Result[i] := Integer(TIA[i]);
- Exit;
- end;
- SetLength(Result, (h + 1));
- for i := 0 to h do
- begin
- for i2 := 0 to h do
- if (i2 <> i) then
- if (TIA[i] = TIA[i2]) then
- Break;
- if (i2 <= h) then
- Continue;
- Result[r] := Integer(TIA[i]);
- Inc(r);
- end;
- SetLength(Result, r);
- end;
- {==============================================================================]
- Explanation: Returns true if TIA is equal to TIA2.
- Ignores specialMatch value in both of the arrays
- (..that means, they are always counted as match!)
- [==============================================================================}
- function MSSL_TIAEquals(TIA1, TIA2: TIntArray; specialMatch: Integer): Boolean; stdcall;
- var
- h, i: Integer;
- begin
- Result := False;
- h := High(TIA1);
- if ((h > -1) and (h = High(TIA2))) then
- begin
- for i := 0 to h do
- if ((TIA1[i] <> specialMatch) and (TIA2[i] <> specialMatch) and (TIA1[i] <> TIA2[i])) then
- Break;
- Result := (i > h);
- end;
- end;
- {==============================================================================]
- Explanation: Returns true if TIA is equal to TIA2.
- Ignores values from specialMatches in both of the arrays
- (..that means, they are always counted as match!)
- [==============================================================================}
- function MSSL_TIAEqualsEx(TIA1, TIA2, specialMatches: TIntArray): Boolean; stdcall;
- var
- h, i: Integer;
- begin
- h := High(TIA1);
- if ((h > -1) and (h = High(TIA2))) then
- begin
- for i := 0 to h do
- if (not TIAContains(specialMatches, TIA1[i]) and not TIAContains(specialMatches, TIA2[i]) and (TIA1[i] <> TIA2[i])) then
- Break;
- Result := (i > h);
- end else
- Result := False;
- end;
- {==============================================================================]
- Explanation: Returns true if ALL values in arr are identical to each other.
- [==============================================================================}
- function MSSL_TIAAllValuesSame(arr: TIntArray): Boolean; stdcall;
- var
- h, i: Integer;
- begin
- h := High(arr);
- if (h < 1) then
- begin
- Result := (h = 0);
- Exit;
- end;
- Result := False;
- for i := 1 to h do
- if (arr[i] <> arr[0]) then
- Exit;
- Result := True;
- end;
- {==============================================================================]
- Explanation: Returns true if ALL values in arr are unique to each other.
- [==============================================================================}
- function MSSL_TIAAllValuesUnique(arr: TIntArray): Boolean; stdcall;
- var
- h, i, i2: Integer;
- begin
- h := High(arr);
- if (h < 1) then
- begin
- Result := (h = 0);
- Exit;
- end;
- Result := False;
- for i := 0 to (h - 1) do
- for i2 := (i + 1) to h do
- if (i <> i2) then
- begin
- Result := (arr[i] <> arr[i2]);
- if not Result then
- Exit;
- end;
- end;
- {==============================================================================]
- Explanation: Splits given TIntArray (TIA) into T2DIntArray by grouping together the integer values
- that are within a given difference range (minDifference, maxDifference) from each other.
- [==============================================================================}
- function MSSL_TIASplitEx(TIA: TIntArray; minDifference, maxDifference: Integer): T2DIntArray; stdcall;
- var
- a, b, h, l, i, r, d, t: Integer;
- begin
- h := High(TIA);
- if (h > -1) then
- begin
- SetLength(Result, (h + 1));
- SetLength(Result[0], 1);
- Result[0][0] := Integer(TIA[0]);
- if (h > 0) then
- begin
- r := 1;
- if (minDifference > maxDifference) then
- begin
- t := minDifference;
- minDifference := maxDifference;
- maxDifference := t;
- end;
- for i := 1 to h do
- begin
- for a := 0 to (r - 1) do
- begin
- l := Length(Result[a]);
- for b := 0 to (l - 1) do
- begin
- d := Abs(TIA[i] - Result[a][b]);
- if ((d >= minDifference) and (d <= maxDifference)) then
- begin
- SetLength(Result[a], (l + 1));
- Result[a][l] := Integer(TIA[i]);
- Break;
- end;
- end;
- if (b < l) then
- Break;
- end;
- if (a >= r) then
- begin
- SetLength(Result[r], 1);
- Result[r][0] := Integer(TIA[i]);
- Inc(r);
- end;
- end;
- end;
- end;
- SetLength(Result, r);
- end;
- {==============================================================================]
- Explanation: Splits given TIntArray (TIA) into T2DIntArray by grouping together the integer values
- that are within a given difference from each other.
- [==============================================================================}
- function MSSL_TIASplit(TIA: TIntArray; difference: Integer): T2DIntArray; stdcall;
- begin
- Result := MSSL_TIASplitEx(TIA, 0, difference);
- end;
- {==============================================================================]
- Explanation: Splits given TIntArray (TIA) into T2DIntArray by grouping together the integer values
- that are within a given difference range (minDifference, maxDifference) of the first integer value in the sub-array.
- [==============================================================================}
- function MSSL_TIAGroupEx(TIA: TIntArray; minDifference, maxDifference: Integer): T2DIntArray; stdcall;
- var
- a, h, l, i, r, d, t: Integer;
- begin
- h := High(TIA);
- if (h > -1) then
- begin
- SetLength(Result, (h + 1));
- SetLength(Result[0], 1);
- Result[0][0] := Integer(TIA[0]);
- if (h > 0) then
- begin
- r := 1;
- if (minDifference > maxDifference) then
- begin
- t := minDifference;
- minDifference := maxDifference;
- maxDifference := t;
- end;
- for i := 1 to h do
- begin
- for a := 0 to (r - 1) do
- begin
- d := Abs(TIA[i] - Result[a][0]);
- if ((d >= minDifference) and (d <= maxDifference)) then
- begin
- l := Length(Result[a]);
- SetLength(Result[a], (l + 1));
- Result[a][l] := Integer(TIA[i]);
- Break;
- end;
- end;
- if (a >= r) then
- begin
- SetLength(Result[r], 1);
- Result[r][0] := Integer(TIA[i]);
- Inc(r);
- end;
- end;
- end;
- end;
- SetLength(Result, r);
- end;
- {==============================================================================]
- Explanation: Splits given TIntArray (TIA) into T2DIntArray by grouping together the integer values
- that are within a given difference range of the first integer value in the sub-array.
- [==============================================================================}
- function MSSL_TIAGroup(TIA: TIntArray; difference: Integer): T2DIntArray; stdcall;
- begin
- Result := MSSL_TIAGroupEx(TIA, 0, difference);
- end;
- type
- TCommand = record
- procAddr: Pointer;
- procDef: string;
- end;
- var
- commands: array of TCommand;
- commandsLoaded: Boolean;
- procedure AddCommand(procAddr: Pointer; procDef: string);
- var
- l: Integer;
- begin
- l := Length(commands);
- SetLength(commands, (l + 1));
- commands[l].procAddr := procAddr;
- commands[l].procDef := procDef;
- end;
- procedure SetupCommands;
- begin
- AddCommand(@MSSL_TIAByRange, 'function MSSL_TIAByRange(aStart, aFinish: Integer): TIntArray;');
- AddCommand(@MSSL_TIAByRange2Bit, 'function MSSL_TIAByRange2Bit(aStart, aFinish: Integer): TIntArray;');
- AddCommand(@MSSL_TIAOfInteger, 'function MSSL_TIAOfInteger(x, count: Integer): TIntArray;');
- AddCommand(@MSSL_IntDigits, 'function MSSL_IntDigits(int: Integer): TIntArray;');
- AddCommand(@MSSL_StrIsInt, 'function MSSL_StrIsInt(str: string): Boolean;');
- AddCommand(@MSSL_IntSetMin, 'procedure MSSL_IntSetMin(var val: Integer; x: Integer);');
- AddCommand(@MSSL_IntSetMax, 'procedure MSSL_IntSetMax(var val: Integer; x: Integer);');
- AddCommand(@MSSL_IntSetRange, 'procedure MSSL_IntSetRange(var val: Integer; mn, mx: Integer);');
- AddCommand(@MSSL_TIASetMin, 'procedure MSSL_TIASetMin(var TIA: TIntArray; x: Integer);');
- AddCommand(@MSSL_TIASetMax, 'procedure MSSL_TIASetMax(var TIA: TIntArray; x: Integer);');
- AddCommand(@MSSL_TIASetRange, 'procedure MSSL_TIASetRange(var TIA: TIntArray; mn, mx: Integer);');
- AddCommand(@MSSL_TIAControlByRange, 'procedure MSSL_TIAControlByRange(var TIA: TIntArray; minimum, maximum: Integer; method: MSSL_TControlMethod);');
- AddCommand(@MSSL_TIABuiltWith, 'function MSSL_TIABuiltWith(TIA, allowed: TIntArray): Boolean;');
- AddCommand(@MSSL_TIARandomizeEx, 'procedure MSSL_TIARandomizeEx(var TIA: TIntArray; shuffles: Integer);');
- AddCommand(@MSSL_TIARandomize, 'procedure MSSL_TIARandomize(var TIA: TIntArray);');
- AddCommand(@MSSL_TIADelete, 'function MSSL_TIADelete(var TIA: TIntArray; x: Integer): Boolean;');
- AddCommand(@MSSL_TIARemove, 'procedure MSSL_TIARemove(var TIA: TIntArray; x: TIntArray);');
- AddCommand(@MSSL_TIAAdd, 'function MSSL_TIAAdd(var TIA: TIntArray; addTIA: TIntArray): Integer;');
- AddCommand(@MSSL_TIAPositions, 'function MSSL_TIAPositions(TIA: TIntArray; x: Integer): TIntArray;');
- AddCommand(@MSSL_TIAPositionsMulti, 'function MSSL_TIAPositionsMulti(TIA, ints: TIntArray): TIntArray;');
- AddCommand(@MSSL_TIAPositionsEx, 'function MSSL_TIAPositionsEx(TIA, ints: TIntArray): TIntArray;');
- AddCommand(@MSSL_TIACopyEx, 'function MSSL_TIACopyEx(TIA: TIntArray; pos1, pos2: Integer): TIntArray;');
- AddCommand(@MSSL_TIAMove, 'function MSSL_TIAMove(var TIA: TIntArray; oldIndex, newIndex: Integer): Boolean;');
- AddCommand(@MSSL_TIAToParts, 'function MSSL_TIAToParts(TIA: TIntArray; method: MSSL_TPartitionMethod; x: Integer): T2DIntArray;');
- AddCommand(@MSSL_TIARangeFrom, 'function MSSL_TIARangeFrom(start, step, count: Integer): TIntArray;');
- AddCommand(@MSSL_TIAGetEx, 'function MSSL_TIAGetEx(TIA, IDs: TIntArray; var iIDs: TIntArray): TIntArray;');
- AddCommand(@MSSL_TIAGet, 'function MSSL_TIAGet(TIA, IDs: TIntArray): TIntArray;');
- AddCommand(@MSSL_TIARemoveEx, 'procedure MSSL_TIARemoveEx(var TIA: TIntArray; x: TIntArray);');
- AddCommand(@MSSL_TIACopy, 'procedure MSSL_TIACopy(source: TIntArray; var target: TIntArray; resetTarget: Boolean);');
- AddCommand(@MSSL_TIATransferEx, 'procedure MSSL_TIATransferEx(var source, target: TIntArray; resetTarget: Boolean);');
- AddCommand(@MSSL_TIATransfer, 'procedure MSSL_TIATransfer(var source, target: TIntArray);');
- AddCommand(@MSSL_TIAPlant, 'function MSSL_TIAPlant(var TIA: TIntArray; index: Integer; ints: TIntArray): Integer;');
- AddCommand(@MSSL_TIAPick, 'function MSSL_TIAPick(var TIA: TIntArray; pick_ID: Integer): Integer;');
- AddCommand(@MSSL_TIAPickEx, 'function MSSL_TIAPickEx(var TIA: TIntArray; pick_IDs: TIntArray): TIntArray;');
- AddCommand(@MSSL_TIAMatchEx, 'function MSSL_TIAMatchEx(TIA1, TIA2, specialMatches: TIntArray): Integer;');
- AddCommand(@MSSL_TIAMatch2, 'function MSSL_TIAMatch2(TIA1, TIA2: TIntArray; specialMatch: Integer): Integer;');
- AddCommand(@MSSL_TIAMatch, 'function MSSL_TIAMatch(TIA1, TIA2: TIntArray): Integer;');
- AddCommand(@MSSL_TIAMatchesEx, 'function MSSL_TIAMatchesEx(TIA1, TIA2, specialMatches: TIntArray): TIntArray;');
- AddCommand(@MSSL_TIAMatches2, 'function MSSL_TIAMatches2(TIA1, TIA2: TIntArray; specialMatch: Integer): TIntArray;');
- AddCommand(@MSSL_TIAMatches, 'function MSSL_TIAMatches(TIA1, TIA2: TIntArray): TIntArray;');
- AddCommand(@MSSL_TIAUnmatch, 'function MSSL_TIAUnmatch(TIA1, TIA2: TIntArray): Integer;');
- AddCommand(@MSSL_TIAUnmatches, 'function MSSL_TIAUnmatches(TIA1, TIA2: TIntArray): TIntArray;');
- AddCommand(@MSSL_TIAGetUniques, 'function MSSL_TIAGetUniques(TIA: TIntArray): TIntArray;');
- AddCommand(@MSSL_TIAEquals, 'function MSSL_TIAEquals(TIA1, TIA2: TIntArray; specialMatch: Integer): Boolean;');
- AddCommand(@MSSL_TIAEqualsEx, 'function MSSL_TIAEqualsEx(TIA1, TIA2, specialMatches: TIntArray): Boolean;');
- AddCommand(@MSSL_TIAAllValuesSame, 'function MSSL_TIAAllValuesSame(arr: TIntArray): Boolean;');
- AddCommand(@MSSL_TIAAllValuesUnique, 'function MSSL_TIAAllValuesUnique(arr: TIntArray): Boolean;');
- AddCommand(@MSSL_TIASplitEx, 'function MSSL_TIASplitEx(TIA: TIntArray; minDifference, maxDifference: Integer): T2DIntArray;');
- AddCommand(@MSSL_TIASplit, 'function MSSL_TIASplit(TIA: TIntArray; difference: Integer): T2DIntArray;');
- AddCommand(@MSSL_TIAGroupEx, 'function MSSL_TIAGroupEx(TIA: TIntArray; minDifference, maxDifference: Integer): T2DIntArray;');
- AddCommand(@MSSL_TIAGroup, 'function MSSL_TIAGroup(TIA: TIntArray; difference: Integer): T2DIntArray;');
- commandsLoaded := True;
- end;
- procedure UnsetupCommands;
- begin
- SetLength(commands, 0);
- commandsLoaded := False;
- end;
- function GetFunctionCount(): Integer; stdcall;
- begin
- if not commandsLoaded then
- SetupCommands;
- Result := Length(commands);
- end;
- function GetFunctionInfo(x: Integer; var ProcAddr: Pointer; var ProcDef: PAnsiChar): Integer; stdcall;
- var
- command: TCommand;
- begin
- case ((x > -1) and InRange(x, Low(commands), High(commands))) of
- True:
- begin
- ProcAddr := commands[x].procAddr;
- StrPCopy(ProcDef, commands[x].procDef);
- Result := x;
- if (Result = High(commands)) then
- UnsetupCommands;
- end;
- False: Result := -1;
- end;
- end;
- exports GetFunctionCount;
- exports GetFunctionInfo;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement