Skip to content

Commit

Permalink
fix: more array methods and small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Torwent committed Oct 2, 2024
1 parent f4fa1c8 commit fb0590b
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 23 deletions.
46 changes: 26 additions & 20 deletions utils/items.simba
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,6 @@ begin
end;


function TRSItemArray.Intersection(other: TRSItemArray): TRSItemArray; constref;
var
i: Int32;
begin
for i := 0 to High(other) do
if Self.Find(other[i]) > -1 then
Result += other[i];
end;


procedure TRSItemArray.Insert(const value: String; index: Int32);
var
l: UInt32;
Expand Down Expand Up @@ -230,7 +220,7 @@ var
unique: TRSItemArray;
begin
for i := 0 to High(Self) do
if (ToStr(Self[i]) <> '') and (unique.Find(Self[i]) = -1) then
if unique.Find(Self[i]) = -1 then
unique += Self[i];
Self := unique;
end;
Expand All @@ -241,28 +231,44 @@ begin
Result.ClearDuplicates();
end;


function TRSItemArray.Count(const value: TRSItem): Int32;
var
i: Int32;
begin
for i := 0 to High(Self) do
if Self[i] = value then
Inc(Result);
end;


function TRSItemArray.Intersection(other: TRSItemArray): TRSItemArray; constref;
var
i: Int32;
begin
for i := 0 to High(other) do
if Self.Find(other[i]) > -1 then
Result += other[i];
end;

function TRSItemArray.Difference(other: TRSItemArray): TRSItemArray; constref;
var
item: TRSItem;
begin
for item in Self do
if Other.Find(item) = -1 then
if other.Find(item) = -1 then
Result += item;

for item in Other do
for item in other do
if Self.Find(item) = -1 then
Result += item;

Result.ClearDuplicates();
end;
end;

function TRSItemArray.Count(const value: TRSItem): Int32;
var
i: Int32;
function TRSItemArray.SymmetricDifference(other: TRSItemArray): TRSItemArray; constref;
begin
for i := 0 to High(Self) do
if Self[i] = value then
Inc(Result);
Result := Self.Difference(other) + other.Difference(Self);
end;


Expand Down
4 changes: 2 additions & 2 deletions utils/math/integerarrays.simba
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ var
i: Int64;
begin
for i in Self do
if Other.Find(i) = -1 then
if other.Find(i) = -1 then
Result += i;

for i in Other do
for i in other do
if Self.Find(i) = -1 then
Result += i;

Expand Down
34 changes: 33 additions & 1 deletion utils/stringarrays.simba
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,9 @@ var
unique: TStringArray;
begin
for i := 0 to High(Self) do
if (Self[i] <> '') and (unique.Find(Self[i]) = -1) then
if unique.Find(Self[i]) = -1 then
unique += Self[i];

Self := unique;
end;

Expand Down Expand Up @@ -278,6 +279,37 @@ begin
end;


function TStringArray.Intersection(other: TStringArray): TStringArray; constref;
var
i: Int32;
begin
for i := 0 to High(other) do
if Self.Find(other[i]) > -1 then
Result += other[i];
end;

function TStringArray.Difference(other: TStringArray): TStringArray; constref;
var
item: String;
begin
for item in Self do
if other.Find(item) = -1 then
Result += item;

for item in other do
if Self.Find(item) = -1 then
Result += item;

Result.ClearDuplicates();
end;

function TStringArray.SymmetricDifference(other: TStringArray): TStringArray; constref;
begin
Result := Self.Difference(other) + other.Difference(Self);
end;



function TStringArray.RandomValue(): String; constref;
begin
if Self <> [] then
Expand Down

0 comments on commit fb0590b

Please sign in to comment.