472,805 Members | 3,559 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Compare Datasets or Arrays

I have two lists. These can be in either table form or array. That is, my
data is in a dataset which I can move to an array if need be. ListA is a
master list and it contains all items. ListB contains the same items but
not necessarily all the items. I need to know which items are missing.

I remember messing with a compare array function but now I can't seem to
find it anywhere. Ideas? I would rather NOT loop through each item in
ListA and check to see if it exists in ListB as the lists are HUGE!

I already have

For each item in ListA
For each item in ListB
If not A=B then record data
Next
Next

This takes about 45 minutes to run.
The compare function I remember using did the following:

ArrayA
1
2
3
4
5

ArrayB
2
3
4

Thus ArrayC
1
5
This would still work however a Dataset level function would work better and
moving the Datasets into arrays would take some time as well.
Thanks for any help or insight!
Nov 21 '05 #1
4 1937
Justin,

This is the most classic dataprocessing what already whas done on Hollerith
machines. It was called "matching" in that cardpunch concept. That is still
the fastest.

It is doing going foreward in the arrays by matching everytime the keys of
that, it assumes that both arrays are sorted on the key value.

When that is not the case than you can make first from arrayB a tempory
hashtable/sortedlist and than match the keys of arrayA if they are in that
and set than the values to true.

The hashtable/sortedlist gives than at the end the missing members.

I hope this helps?

Cor
Nov 21 '05 #2
guy
two suggestions
1/ compare the number of elements in each array first - you may not have to
do any comparing!

<<IF>> list1 is static and list2 is dynamic
2/ flag each element in list 1 when it is added to list 2, and deflag when
it is removed
that way you only have to check the flags in list1

hth

guy

"Justin Emlay" wrote:
I have two lists. These can be in either table form or array. That is, my
data is in a dataset which I can move to an array if need be. ListA is a
master list and it contains all items. ListB contains the same items but
not necessarily all the items. I need to know which items are missing.

I remember messing with a compare array function but now I can't seem to
find it anywhere. Ideas? I would rather NOT loop through each item in
ListA and check to see if it exists in ListB as the lists are HUGE!

I already have

For each item in ListA
For each item in ListB
If not A=B then record data
Next
Next

This takes about 45 minutes to run.
The compare function I remember using did the following:

ArrayA
1
2
3
4
5

ArrayB
2
3
4

Thus ArrayC
1
5
This would still work however a Dataset level function would work better and
moving the Datasets into arrays would take some time as well.
Thanks for any help or insight!

Nov 21 '05 #3
Justin,
If ListA & ListB are in a dataset I would leave them as DataTable. I would
make sure that each (ListB specifically) has a Primary Key.

You can then use something like:

Dim listA As New DataTable("listA")
listA.PrimaryKey = New DataColumn() {listA.Columns("key")}

Dim listB As New DataTable("listB")
listB.PrimaryKey = New DataColumn() {listB.Columns("key")}

For Each row As DataRow In listA.Rows
If Not listB.Rows.Contains(row!key) Then
' found missing row
End If
Next

The Contains method is overloaded for multiple value keys...

Alternatively you could define a DataView over listB with the fields you are
matching on.

Dim listA As New DataTable("listA")
Dim listB As New DataTable("listB")

Dim viewB As New DataView(listB)
viewB.Sort = "field1, field2, field3"

Dim keys(2) As Object
For Each row As DataRow In listA.Rows
keys(0) = row!field1
keys(1) = row!field2
keys(2) = row!field3
If viewB.Find(keys) = -1 Then
' found missing row
End If
Next

The Find method is overloaded for single value keys...

Hope this helps
Jay

"Justin Emlay" <JE****@NoSpam.com> wrote in message
news:Ox**************@tk2msftngp13.phx.gbl...
I have two lists. These can be in either table form or array. That is, my
data is in a dataset which I can move to an array if need be. ListA is a
master list and it contains all items. ListB contains the same items but
not necessarily all the items. I need to know which items are missing.

I remember messing with a compare array function but now I can't seem to
find it anywhere. Ideas? I would rather NOT loop through each item in
ListA and check to see if it exists in ListB as the lists are HUGE!

I already have

For each item in ListA
For each item in ListB
If not A=B then record data
Next
Next

This takes about 45 minutes to run.
The compare function I remember using did the following:

ArrayA
1
2
3
4
5

ArrayB
2
3
4

Thus ArrayC
1
5
This would still work however a Dataset level function would work better
and moving the Datasets into arrays would take some time as well.
Thanks for any help or insight!

Nov 21 '05 #4
Thanks, that helped a lot!
"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:Ow**************@TK2MSFTNGP15.phx.gbl...
Justin,
If ListA & ListB are in a dataset I would leave them as DataTable. I would
make sure that each (ListB specifically) has a Primary Key.

You can then use something like:

Dim listA As New DataTable("listA")
listA.PrimaryKey = New DataColumn() {listA.Columns("key")}

Dim listB As New DataTable("listB")
listB.PrimaryKey = New DataColumn() {listB.Columns("key")}

For Each row As DataRow In listA.Rows
If Not listB.Rows.Contains(row!key) Then
' found missing row
End If
Next

The Contains method is overloaded for multiple value keys...

Alternatively you could define a DataView over listB with the fields you
are matching on.

Dim listA As New DataTable("listA")
Dim listB As New DataTable("listB")

Dim viewB As New DataView(listB)
viewB.Sort = "field1, field2, field3"

Dim keys(2) As Object
For Each row As DataRow In listA.Rows
keys(0) = row!field1
keys(1) = row!field2
keys(2) = row!field3
If viewB.Find(keys) = -1 Then
' found missing row
End If
Next

The Find method is overloaded for single value keys...

Hope this helps
Jay

"Justin Emlay" <JE****@NoSpam.com> wrote in message
news:Ox**************@tk2msftngp13.phx.gbl...
I have two lists. These can be in either table form or array. That is,
my data is in a dataset which I can move to an array if need be. ListA is
a master list and it contains all items. ListB contains the same items
but not necessarily all the items. I need to know which items are
missing.

I remember messing with a compare array function but now I can't seem to
find it anywhere. Ideas? I would rather NOT loop through each item in
ListA and check to see if it exists in ListB as the lists are HUGE!

I already have

For each item in ListA
For each item in ListB
If not A=B then record data
Next
Next

This takes about 45 minutes to run.
The compare function I remember using did the following:

ArrayA
1
2
3
4
5

ArrayB
2
3
4

Thus ArrayC
1
5
This would still work however a Dataset level function would work better
and moving the Datasets into arrays would take some time as well.
Thanks for any help or insight!


Nov 21 '05 #5

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:...
45
by: cody | last post by:
I've seen an Introduction on ADO.NET with its Datasets on .NET TV and Iam now wondering how it is realized/used in real world applications. I don't believe that one would create a dataset and add...
0
by: Bj?rn Mor?n | last post by:
I am consuming a web service that returns arrays of classes which can contain other classes (a hierarchy of data). Is there a simple way to move the data into a typed DataSet without writing too...
2
by: codejockey | last post by:
I have a simple project that requires I take a set of data from an Excel spreadsheet, compare it to a table in SQL Server (where column names match), and if there are changes in the Excel sheet,...
0
by: codejockey | last post by:
Please forgive the repost, but I'm trying to avoid the hack I want to implement since I cant get this sample to work. Can anyone help? *********************** William: Thanks for the reply. I...
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...
0
by: Frank | last post by:
Hello, Developing an app where the user fills out a sometimes quite lengthy form of chkboxes, txtboxes, radbtns, etc. User responses are saved to a mySql db, which the user can later edit. When...
3
by: cj | last post by:
I've used datatables and datasets before. Datasets being able to hold more than one table and datatables being only one table. My mind keeps coming up with recordsets. I can't remember how they...
6
by: Al | last post by:
I'd like to know if there were any changes in the DataSet which was populated by reading XML file. 6 DataTables with data or just structure with no data inside of it. I think about this scenario:...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: lllomh | last post by:
How does React native implement an English player?
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

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.