Dan,
First, you don't want to mix types in an array. I noticed you have String and
Integer types.
If all 3 dimensions of your array reference a single item, then I might use an
array of a Structure with a fixed length string.
Second, do not perform multiple tests in a single line using the "And" operator.
VB must resolve all the expressions prior to evaluating your comparison test.
In cases where the first test fails, it will still perform the other two tests
along with all the unnecessary overhead.
VB.Net does include the "AndAlso" and "OrElse" operators which will provide a
"Short-Circuit" method of evaluation.
Meaning the first test to fail will cause the whole expression to fail, and
return False without evaluating the subsequent expressions.
IMHO, I prefer to break them into separate tests for readability.
In addition, it also allows you to perform other operations between tests, as in
the case of indexing.
Third, along with the second, perform your tests in the order which will most
likely give you a False first.
This will allow you to minimize the number of unnecessary comparisons.
Sometimes that fastest way to get to your desired item is to eliminate as many
of the items as quickly as possible that cannot fulfill your criteria.
Fourth, if you have a large number of elements in the array and you will be
accessing them a lot, then I recommend pre-sorting the array on an appropriate
key. You could also create Index arrays with pointers into the primary array and
use this to minimize the number of elements to test.
The best implementation of an Index, if even appropriate, would be dependant
upon the contents of the array and intended usage.
Hope this helps,
Gerald
Dan said:
I wonder if anyone has suggestions for reducing the amount of time it would
take to search my array using the function that I have written. I want to find
a position in the array of an item that matches on all three variables.
Suggestions?
Public Shared Function GetArrayPosition(ByVal ipRemoteEndPoint As String,
ByVal intEngine_Type As Integer, ByVal intEngine_ID As Integer)
For i As Integer = 0 To aryDevice.GetUpperBound(1)
If aryDevice(0, i) = ipRemoteEndPoint.ToString And aryDevice(1, i)
= intEngine_Type And aryDevice(2, i) = intEngine_ID Then