Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   Multimap duplicates removal (http://www.go4expert.com/forums/multimap-duplicates-removal-t23650/)

heidik 23Oct2010 16:03

Multimap duplicates removal
 
Hello Everyone. Could anyone please help me solve this problem. I am actually new to using STL. I have been given a task of searching a file of over 60000 records. The data extracted from the file is stored in struct and that struct is in turn stored in vectors i-e a vector of struct having over 60000 struct elements. I have to look for duplicates in that vector of structs and storing those duplicates in another container so that the original vector is left with only those elements which have no duplicates. For example:

OrgVector = 1 2 3 4 1 5 6 2 4 7 9 10 1
DupVectpr = 1 1 1 2 2 4 4
and the original vector is now left with
OrgVector = 3 5 6 7 9 10

the struct is something like this

struct MyPred
{
int x, y, z;
};

then I have to find the difference between x and z for each struct element stored in the DupVector and will push_back the vector again to the original vector (from the DupVector) where the difference between x and z of its struct element would be the minimum. I have done the same thing with simple ints and even string type of vectors but am unable to do the same thing for vector of structs. And is there any fast way of searching 60000 records for duplicates because simple find/find_if would be too slow since they perform linear search. I tried multimaps where it returned all values against a single key and it was a really very quick search i-e I stored same numbers in multimap both as its key and value and the equal_range returned all values against a single key. E-g considering the above vector

Multimap Keys = 1 2 3 4 1 5 6 2 4 7 9 10 1
Multimap Values = 1 2 3 4 1 5 6 2 4 7 9 10 1

Values against key 1: 1 1 1
Values against key 2: 2 2
Values against key 4: 4 4

But again I could not do it with vectors of structs. Could anyone please help me do this assignment. Any help along with code would be greatly appreciated because it is basically the syntax that I am stuck in.


All times are GMT +5.5. The time now is 01:32.