473,406 Members | 2,217 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Compare large arrays

I have two large arrays. Is there a rapid method to comaprs the two
arrays and creat a third array of onlt thos items that the are in the
first array but not the second array. I do it manually now (compare
each item) but it takes forever
Jul 1 '07 #1
3 1996
Jo**@aol.com wrote:
I have two large arrays. Is there a rapid method to comaprs the two
arrays and creat a third array of onlt thos items that the are in the
first array but not the second array. I do it manually now (compare
each item) but it takes forever
If you sort the arrays, you can then loop through them parallelly and
easily pick out the differences.

--
Göran Andersson
_____
http://www.guffa.com
Jul 1 '07 #2

well i would do this with a hashtable

prepared a dirty quick example and this only takes seconds on my system
Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

' create 2 hughe arrays

Dim arrTestA(10000000) As Object

Dim arrTestB(10000000) As Object

For i As Integer = 0 To 10000000

arrTestA(i) = i

arrTestB(i) = 10500000 - i

Next

Dim arrTestC() As Object = ArrayDistinct(arrTestA, arrTestB)

MsgBox("ready")

End Sub

Public Function ArrayDistinct(ByVal ArrA() As Object, ByVal ArrB() As
Object) As Object()

Dim ht As New Hashtable(ArrA.Length)

For Each val As Object In ArrA

ht.Add(val, val)

Next

For Each val As Object In ArrB

If ht.ContainsKey(val) Then

ht.Remove(val)

End If

Next

Dim ret(ht.Count) As Object

Dim icount As Integer

For Each val As Object In ht.Values

ret(icount) = val

icount += 1

Next

Return ret

End Function

or is it not hughe enough :-)




<Jo**@aol.comschreef in bericht
news:0b********************************@4ax.com...
>I have two large arrays. Is there a rapid method to comaprs the two
arrays and creat a third array of onlt thos items that the are in the
first array but not the second array. I do it manually now (compare
each item) but it takes forever

Jul 1 '07 #3

before someone falls over the " distinct " name of the function before i
read the TS`s again and understood that he not wanted to distinct the
values
but wanted to have all values from Array A that were not in Array B

the function was mades as a distinct function ( difference is that both
values are then combined with there unique values )

Public Function ArrayDistinct(ByVal ArrA() As Object, ByVal ArrB() As
Object) As Object()

Dim ht As New Hashtable(ArrA.Length + 100) ' just a rough estimate

For Each val As Object In ArrA

ht.Add(val, val)

Next

For Each val As Object In ArrB

If Not ht.ContainsKey(val) Then

ht.Add(val, val)

End If

Next

Dim ret(ht.Count) As Object

Dim icount As Integer

For Each val As Object In ht.Values

ret(icount) = val

icount += 1

Next

Return ret

End Function
happy coding

Michel


<Jo**@aol.comschreef in bericht
news:0b********************************@4ax.com...
>I have two large arrays. Is there a rapid method to comaprs the two
arrays and creat a third array of onlt thos items that the are in the
first array but not the second array. I do it manually now (compare
each item) but it takes forever

Jul 1 '07 #4

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

Similar topics

0
by: Phil Powell | last post by:
/*-------------------------------------------------------------------------------------------------------------------------------- Parameters: $formField1: The name of the first array $formField2:...
13
by: MrCoder | last post by:
Hey guys, my first post on here so I'll just say "Hello everbody!" Ok heres my question for you lot. Is there a faster way to compare 1 byte array to another? This is my current code //...
8
by: Devrobcom | last post by:
Hi I have an array with 30 int and another array with 1000 int. If any of the 30 intergers can be found in the 1000 int array I shall return true. The contents of the arrays will also change over...
122
by: Einar | last post by:
Hi, I wonder if there is a nice bit twiddling hack to compare a large number of variables? If you first store them in an array, you can do: for (i = 0; i < n; i++) { if (array != value) {...
4
by: Gaby | last post by:
Hi all, What is the best way to compare 2 (large) ArrayLists filled with an object. Can you please help me? Gaby
2
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...
8
by: Turbot | last post by:
Hello, Anyone know how to compare two byte arrays without going through each item in the array. I actually want to compare two bitmap objects to see if they both contain the same picture bit...
2
by: Florian G. Pflug | last post by:
Hi Since sometime yesterday, my postgresql (7.4.5) reports "ERROR: cannot compare arrays of different element types", when I analyze a specific table in my database. Here is the tables...
5
by: Oleg Subachev | last post by:
Is there other way of comparing two byte arrays than iterating through the two and compare individual bytes ? Oleg Subachev
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
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...
0
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,...

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.