By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,665 Members | 1,761 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,665 IT Pros & Developers. It's quick & easy.

Compare Datasets or Arrays

P: n/a
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
Share this Question
Share on Google+
4 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.