473,385 Members | 1,869 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,385 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 1972
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:...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.