Skip to content

Commit

Permalink
Cleaned up type functions a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
Zyt3x committed May 24, 2015
1 parent 5cb4ffc commit 35c3404
Show file tree
Hide file tree
Showing 5 changed files with 119 additions and 221 deletions.
50 changes: 16 additions & 34 deletions lib/utilities/types/extendedarrays.simba
Expand Up @@ -18,7 +18,7 @@ TExtendedArray.addIndex

procedure TExtendedArray.addIndex(const ext : Extended; const index : Integer);

Used to add a value to a TExtendedArray at a chosen index larger than the array's lowest index.
Used to add a value to a TExtendedArray at a chosen index.

.. note::

Expand All @@ -32,19 +32,8 @@ Example:

*)
procedure TExtendedArray.addIndex(const ext : Extended; const index : Integer);
var
I : Integer;
begin
if not inRange(index, low(self), length(self)) then
begin
WriteLn('ERROR: addIndex: index larger than array length.');
Exit;
end;

setLength(self, length(self)+1);
for I := high(self)-1 downto index do
self[I+1] := self[I];
self[index] := ext;
insert(ext, self, index);
end;

(*
Expand All @@ -55,7 +44,7 @@ TExtendedArray.deleteIndex

procedure TExtendedArray.deleteIndex(const index : Integer);

Used to delete a value of a TExtendedArray at a chosen index larger than the array's lowest index.
Used to delete a value of a TExtendedArray at a chosen index.

.. note::

Expand All @@ -69,18 +58,14 @@ Example:

*)
procedure TExtendedArray.deleteIndex(const index : Integer);
var
I : Integer;
begin
if not inRange(index, low(self), high(self)) then
begin
WriteLn('ERROR: deleteIndex: index larger than array length.');
WriteLn('ERROR: deleteIndex: index out of bounds.');
Exit;
end;

for I := index to high(self)-1 do
self[I] := self[I+1];
setLength(self, length(self)-1);
delete(self, index, 1);
end;

(*
Expand All @@ -106,7 +91,7 @@ Example:
*)
procedure TExtendedArray.append(const ext : Extended);
begin
self.addIndex(ext, length(self));
insert(ext, self, length(self));
end;

(*
Expand Down Expand Up @@ -134,8 +119,8 @@ procedure TExtendedArray.combine(const arr : TExtendedArray);
var
I : Integer;
begin
for I := 0 to high(arr) do
self.append(arr[I]);
for I := high(arr) downto 0 do
insert(arr[I], self);
end;

(*
Expand Down Expand Up @@ -166,10 +151,7 @@ begin
result := -1;
for I := 0 to high(self) do
if self[I] = ext then
begin
result := I;
exit;
end;
exit(I);
end;

(*
Expand Down Expand Up @@ -223,9 +205,9 @@ function TExtendedArray.include(const arr : TExtendedArray) : TExtendedArray;
var
I : Integer;
begin
for I := 0 to high(arr) do
for I := high(arr) downto 0 do
if self.isInArray(arr[I]) then
result.append(arr[I]);
insert(arr[I], result);
end;

(*
Expand Down Expand Up @@ -253,9 +235,9 @@ function TExtendedArray.exclude(const arr : TExtendedArray) : TExtendedArray;
var
I : Integer;
begin
for I := 0 to high(arr) do
for I := high(arr) downto 0 do
if not self.isInArray(arr[I]) then
result.append(arr[I]);
insert(arr[I], result);
end;

(*
Expand Down Expand Up @@ -314,9 +296,9 @@ var
I : Integer;
arr : TExtendedArray;
begin
for I := 0 to high(self) do
for I := high(self) downto 0 do
if not arr.isInArray(self[I]) then
arr.append(self[I]);
insert(self[I], arr);
self := arr;
end;

Expand Down Expand Up @@ -347,7 +329,7 @@ var
arr : TExtendedArray;
begin
for I := high(self) downto 0 do
arr.append(self[I]);
insert(self[I], arr);
self := arr;
end;

Expand Down
47 changes: 14 additions & 33 deletions lib/utilities/types/integerarrays.simba
Expand Up @@ -18,7 +18,7 @@ TIntegerArray.addIndex

procedure TIntegerArray.addIndex(const int : Integer; const index : Integer);

Used to add a value to a TIntegerArray at a chosen index larger than the array's lowest index.
Used to add a value to a TIntegerArray at a chosen index.

.. note::

Expand All @@ -32,19 +32,8 @@ Example:

*)
procedure TIntegerArray.addIndex(const int : Integer; const index : Integer);
var
I : Integer;
begin
if not inRange(index, low(self), length(self)) then
begin
WriteLn('ERROR: addIndex: index larger than array length.');
Exit;
end;

setLength(self, length(self)+1);
for I := high(self)-1 downto index do
self[I+1] := self[I];
self[index] := int;
insert(int, self, index);
end;

(*
Expand All @@ -55,7 +44,7 @@ TIntegerArray.deleteIndex

procedure TIntegerArray.deleteIndex(const index : Integer);

Used to delete a value of a TIntegerArray at a chosen index larger than the array's lowest index.
Used to delete a value of a TIntegerArray at a chosen index.

.. note::

Expand All @@ -74,13 +63,11 @@ var
begin
if not inRange(index, low(self), high(self)) then
begin
WriteLn('ERROR: deleteIndex: index larger than array length.');
WriteLn('ERROR: deleteIndex: index out of bounds.');
Exit;
end;

for I := index to high(self)-1 do
self[I] := self[I+1];
setLength(self, length(self)-1);
delete(self, index, 1);
end;

(*
Expand All @@ -106,7 +93,7 @@ Example:
*)
procedure TIntegerArray.append(const int : Integer);
begin
self.addIndex(int, length(self));
insert(int, self, length(self));
end;

(*
Expand All @@ -131,8 +118,6 @@ Example:

*)
procedure TIntegerArray.combine(const arr : TIntegerArray);
var
I : Integer;
begin
combineIntArrayWrap(self, arr, self);
end;
Expand Down Expand Up @@ -214,9 +199,9 @@ function TIntegerArray.include(const arr : TIntegerArray) : TIntegerArray;
var
I : Integer;
begin
for I := 0 to high(arr) do
for I := high(arr) downto 0 do
if self.isInArray(arr[I]) then
result.append(arr[I]);
insert(arr[I], result);
end;

(*
Expand Down Expand Up @@ -244,9 +229,9 @@ function TIntegerArray.exclude(const arr : TIntegerArray) : TIntegerArray;
var
I : Integer;
begin
for I := 0 to high(arr) do
for I := high(arr) downto 0 do
if not self.isInArray(arr[I]) then
result.append(arr[I]);
insert(arr[I], result);
end;

(*
Expand All @@ -271,12 +256,8 @@ Example:

*)
procedure TIntegerArray.swap(var arr : TIntegerArray);
var
arr2 : TIntegerArray;
begin
arr2 := self;
self := arr;
arr := arr2;
System.swap(self, arr);
end;

(*
Expand Down Expand Up @@ -305,9 +286,9 @@ var
I : Integer;
arr : TIntegerArray;
begin
for I := 0 to high(self) do
for I := high(self) downto 0 do
if not arr.isInArray(self[I]) then
arr.append(self[I]);
insert(self[I], arr);
self := arr;
end;

Expand Down Expand Up @@ -469,7 +450,7 @@ var
begin
setLength(result, length(self));
for I := 0 to high(self) do
result[I] := self[I] * 1.0;
result[I] := self[I];
end;

(*
Expand Down
43 changes: 15 additions & 28 deletions lib/utilities/types/stringarrays.simba
Expand Up @@ -18,7 +18,7 @@ TStringArray.addIndex

procedure TStringArray.addIndex(const str : String; const index : Integer);

Used to add a value to a TStringArray at a chosen index larger than the array's lowest index.
Used to add a value to a TStringArray at a chosen index.

.. note::

Expand All @@ -32,19 +32,8 @@ Example:

*)
procedure TStringArray.addIndex(const str : String; const index : Integer);
var
I : Integer;
begin
if not inRange(index, low(self), length(self)) then
begin
WriteLn('ERROR: addIndex: index larger than array length.');
Exit;
end;

setLength(self, length(self)+1);
for I := high(self)-1 downto index do
self[I+1] := self[I];
self[index] := str;
insert(str, self, index);
end;

(*
Expand All @@ -55,7 +44,7 @@ TStringArray.deleteIndex

procedure TStringArray.deleteIndex(const index : Integer);

Used to delete a value of a TStringArray at a chosen index larger than the array's lowest index.
Used to delete a value of a TStringArray at a chosen index.

.. note::

Expand All @@ -74,13 +63,11 @@ var
begin
if not inRange(index, low(self), high(self)) then
begin
WriteLn('ERROR: deleteIndex: index larger than array length.');
WriteLn('ERROR: deleteIndex: index out of bounds.');
Exit;
end;

for I := index to high(self)-1 do
self[I] := self[I+1];
setLength(self, length(self)-1);
delete(self, index, 1);
end;

(*
Expand All @@ -106,7 +93,7 @@ Example:
*)
procedure TStringArray.append(const str : String);
begin
self.addIndex(str, length(self));
insert(str, self, length(self));
end;

(*
Expand Down Expand Up @@ -135,7 +122,7 @@ var
I : Integer;
begin
for I := 0 to high(arr) do
self.append(arr[I]);
insert(arr[I], self, length(self));
end;

(*
Expand Down Expand Up @@ -223,9 +210,9 @@ function TStringArray.include(const arr : TStringArray) : TStringArray;
var
I : Integer;
begin
for I := 0 to high(arr) do
for I := high(arr) downto 0 do
if self.isInArray(arr[I]) then
result.append(arr[I]);
insert(arr[I], result);
end;

(*
Expand Down Expand Up @@ -253,9 +240,9 @@ function TStringArray.exclude(const arr : TStringArray) : TStringArray;
var
I : Integer;
begin
for I := 0 to high(arr) do
for I := high(arr) downto 0 do
if not self.isInArray(arr[I]) then
result.append(arr[I]);
insert(arr[I], result);
end;

(*
Expand Down Expand Up @@ -314,9 +301,9 @@ var
I : Integer;
arr : TStringArray;
begin
for I := 0 to high(self) do
for I := high(self) downto 0 do
if not arr.isInArray(self[I]) then
arr.append(self[I]);
insert(self[I], arr);
self := arr;
end;

Expand Down Expand Up @@ -346,8 +333,8 @@ var
I : Integer;
arr : TStringArray;
begin
for I := high(self) downto 0 do
arr.append(self[I]);
for I := 0 to high(self) do
insert(self[I], arr);
self := arr;
end;

Expand Down

0 comments on commit 35c3404

Please sign in to comment.