Efficient datatable searching

Hi,

I have some dataTables that have names listed with various other pieces of data that's linked to each name. At the moment there's around 1500 lines of data which will increase as the year goes on.

Some of these names are listed once. Others are listed dozens of times.

I'm after an efficient way to count how many times (occurrences) a name occurs in the datatable. For example:
Smith 3
Jones 10
Peters 1
.... as so on. This information will then be placed into another table like a summary of sorts.

I could do a simple loop such as this:

1
2
3
4
5
6
7
int occurrences = 0;

for(int i=0; i<dt->Rows->Coung; ++i)
{
if(Convert::ToString(dt->Rows[i]["Name"]) == "Smith")
occurrences++;	
}


But given the amount of names to sort through, the 'load' time for this is too long. I need a way to minimise processing time. Would a vector / map or something similar be useful?

Any thoughts? Thanks
Would a vector / map or something similar be useful?


The data is stored already in a DataTable so converting it all and copying might take quite a bit of time.

You could try to set the RowFilter in the DatatTable - like:

dt->DefaultView->RowFilter = "Name = 'Smith'";

The number should be dt->DefaultView->Count;

Difficult to say if it is effcient enough without code and data to compile.
Topic archived. No new replies allowed.