473,770 Members | 5,136 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Fastest way to compare arrays

What is the fastest way to determine if two arrays that
contain ValueTypes are equal? For example, lets say I
have the following:

Dim pt1 as New Drawing.Point(1 , 2)
Dim pt2 as New Drawing.Point(2 , 3)
Dim pt3 as New Drawing.Point(3 , 4)
Dim pt4 as New Drawing.Point(4 , 5)

Dim A() as Drawing.Point = {pt1, pt2, pt3}
Dim B() as Drawing.Point = {pt1, pt2, pt3}
Dim C() as Drawing.Point = {pt2, pt3, pt4}
Dim D() as Drawing.Point = {pt3, pt2, pt1}

What is the fastest way to determine that B equals A but
that C and D do not equal A? The only way I know is to
loop through the arrays and test each member (e.g.,
Drawing.Point.o p_Equality(A(i) , B(i)), but it seems like
there must be a better way.

Thanks for any help!
Nov 20 '05 #1
3 21370
assuming { 1, 2, 3 } does not equal { 1, 3, 2 } (i.e. order matters in the
equality)
the only way to confirm to arrays are equal is to check every member...
however, you can note that two arrays are not equal as soon as two adjacent
members are not equal.

something like:

Function AreArraysEqual( ByRef one As Object(), ByRef two As Object()) As
Boolean

' check lengths are the same
If one.Length <> two.Length Then
Return False
End If

' check each element
For index As Integer = 0 To one.Length - 1
If (one.GetValue(i ndex) <> two.GetValue(in dex)) Then
Return False
End If
Next

Return True
End Function

"Lance" <zi***@hotmail. com> wrote in message
news:00******** *************** *****@phx.gbl.. .
What is the fastest way to determine if two arrays that
contain ValueTypes are equal? For example, lets say I
have the following:

Dim pt1 as New Drawing.Point(1 , 2)
Dim pt2 as New Drawing.Point(2 , 3)
Dim pt3 as New Drawing.Point(3 , 4)
Dim pt4 as New Drawing.Point(4 , 5)

Dim A() as Drawing.Point = {pt1, pt2, pt3}
Dim B() as Drawing.Point = {pt1, pt2, pt3}
Dim C() as Drawing.Point = {pt2, pt3, pt4}
Dim D() as Drawing.Point = {pt3, pt2, pt1}

What is the fastest way to determine that B equals A but
that C and D do not equal A? The only way I know is to
loop through the arrays and test each member (e.g.,
Drawing.Point.o p_Equality(A(i) , B(i)), but it seems like
there must be a better way.

Thanks for any help!
Nov 20 '05 #2
"Lance" <zi***@hotmail. com> schrieb
What is the fastest way to determine if two arrays that
contain ValueTypes are equal? For example, lets say I
have the following:

Dim pt1 as New Drawing.Point(1 , 2)
Dim pt2 as New Drawing.Point(2 , 3)
Dim pt3 as New Drawing.Point(3 , 4)
Dim pt4 as New Drawing.Point(4 , 5)

Dim A() as Drawing.Point = {pt1, pt2, pt3}
Dim B() as Drawing.Point = {pt1, pt2, pt3}
Dim C() as Drawing.Point = {pt2, pt3, pt4}
Dim D() as Drawing.Point = {pt3, pt2, pt1}

What is the fastest way to determine that B equals A but
that C and D do not equal A? The only way I know is to
loop through the arrays and test each member (e.g.,
Drawing.Point.o p_Equality(A(i) , B(i)), but it seems like
there must be a better way.
That's also the only way I know.
Thanks for any help!

--
Armin

Nov 20 '05 #3
Thanks to both of you for the feedback.
Nov 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
2713
by: Phil Powell | last post by:
/*-------------------------------------------------------------------------------------------------------------------------------- Parameters: $formField1: The name of the first array $formField2: The name of the second array $formField1CompareWith: String to use as my comparison basis for first array. Defaults to using $val unless it's 'key' $formField2CompareWith: String to use as my comparison basis for second array. Same default as...
2
6227
by: Mike | last post by:
Hi! I am trying to determine if the DataRow of one dataset contains the same data as the DataRow of another. I figured I can extract ItemArray's from each dataset and then compare them. 1) Is this the fastest way? I will have to loop through thousands of rows for what I am doing. 2) How can I compare arrays for Value Equality ? I do not think array's ..Equal method does Value Equality check. Based on what I understood, it does...
11
3619
by: hoopsho | last post by:
Hi Everyone, I am trying to write a program that does a few things very fast and with efficient use of memory... a) I need to parse a space-delimited file that is really large, upwards fo a million lines. b) I need to store the contents into a unique hash. c) I need to then sort the data on a specific field. d) I need to pull out certain fields and report them to the user.
2
11346
by: Tom | last post by:
What's the best way to compare two byte arrays? Right now I am converting them to base64 strings and comparing those, as so: 'result1 and result2 are two existing byte arrays that have been loaded Dim data64_1 As String = System.Convert.ToBase64String(result1, 0, result1.Length) Dim data64_2 As String = System.Convert.ToBase64String(result2, 0, result2.Length) Debug.WriteLine(IIf(data64_1 = data64_2, "Equals", "NOT Equals"))
30
9078
by: Chaos | last post by:
As my first attempt to loop through every pixel of an image, I used for thisY in range(0, thisHeight): for thisX in range(0, thisWidth): #Actions here for Pixel thisX, thisY But it takes 450-1000 milliseconds I want speeds less than 10 milliseconds
1
2431
by: Harry Haller | last post by:
What is the fastest way to search a client-side database? I have about 60-65 kb of data downloaded to the client which is present in 3 dynamically created list boxes. The boxes are filled from 3 string arrays, which are just lists of people or companies in alphabetic order. These names may have accented and umlauted characters (which are present as the plain ASCII - not as the entity &# character). The page is UTF-8 encoded. e.g. ...
6
50275
by: Klaas Vantournhout | last post by:
Hi, I have a question, which is just out of interest. What is the fastest way to do an odd/even check with c++ and if needed assembler. Assume n is an unsigned integer like type (unsigned int, unsigned long int), what is the fastest? using the modulo operator
24
2294
by: ThunderMusic | last post by:
Hi, The subject says it all... I want to use a byte and use it as byte* so I can increment the pointer to iterate through it. What is the fastest way of doing so in C#? Thanks ThunderMusic
17
3260
by: wswilson | last post by:
In python, I could write: a = 1 if a in : do something... In c (and many other languages):
0
9425
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10230
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10004
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9870
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8886
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6678
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3972
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3576
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2817
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.