MultiMap removing duplicates

Pages: 1... 3456
Hellooo Galik

I'm in office now and I couldnt complete modifying your code according to the one they are working on here because something has gone wrong with this application at some client site and they have asked me to find out the reason.

I will go through your code because like you said I must learn and will add more comments to it for my own understanding specially about the syntax at few points.

You don't want them thinking you are more capable than you are but let them know that you are pro-actively learning what you need to know.


You are right and that's a very good idea :)

Also, don't forget the technique I used to overwrite the original vector. That will save memory and speed things up a little. But if you do apply that to your routine be careful how you do it because its more dangerous. The main thing you might forget is resizing your original vector at the end because it will have shrunk. In order to do that your struct needs a default constructor (even though it won't be invoked).


Noted :)


1
2
3
4
while (true)
{
  A BIG "THANK YOU" :)
}

Hello and How do u do Galik

I modified your code and it worked fine except for one thing i-e for example (this how it is actually stored in the file)


1) if the end date/time is 01-06-2010 and time is 12:19am and the start date/time is 31-05-2010 (previous date) and time is 11:59pm
2) duplicate: if the end date/time is 01-06-2010 and time is 12:33am and the start date/time is 31-05-2010 (previous date) and time is 11:59pm
3) duplicate: if the end date/time is 01-06-2010 and time is 12:10am and the start date/time is 31-05-2010 (previous date) and time is 11:59pm


then the closest one should be the third one because I need the smallest time difference where as the program outputs the second one. I think it is because the DAY has CHANGED. Could you please see.
I don't understand. I thought they were only duplicates if the end date/times were identical. But in your example the end date/times are all different?
I think I am again out of my mind. SORRY. I sent this msg just before I was leaving office :P. Your code is working fine :). This is the actual data that I am working on in office. Could you please have a look at it.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <ctime>
#include <iomanip>
#include <cstdlib>

using namespace std;

bool get_time(const std::string& s, time_t& time)
{
tm date;
date.tm_isdst = 0;
std::istringstream iss(s);
std::string line;
char c;
if(!(iss >> date.tm_year >> c)) return false;
if(!(iss >> date.tm_mon >> c)) return false;
if(!(iss >> date.tm_mday >> c)) return false;
if(!(iss >> date.tm_hour >> c)) return false;
if(!(iss >> date.tm_min >> c)) return false;
if(!(iss >> date.tm_sec)) return false;
date.tm_year -= 1900;
time = mktime(&date);

return true;
}

bool time_diff(const std::string& a, const std::string& z, time_t& diff)
{
time_t atime;
time_t ztime;
if(get_time(a, atime) && get_time(z, ztime))
{
diff = std::abs(ztime - atime);
return true;
}
return false;
}

struct Breach
    {
          string trdr;        /*!< Trader itm */
          string sendt;       /*!< Time of message transmission */  
          string com;         /*!< Commodity */
          string exp;         /*!< Expiry */

          string contract;    /*!< Contract type */
          string acc;         /*!< Account Ref */
          string sok;         /*!< Site Order Key */
          string exid;        /*!< Execution Id */

          string fil;         /*!< Order Fill info */
          string soid;        /*!< Secondary Order Id */
          string bs;          /*!< Buy Sell */
          string exprice;     /*!< Exercise Price */

          string price;       /*!< Price */
          string vol;         /*!< Volume */
          string lfprice;     /*!< Last Fill Price */
          string gmt;         /*!< Transaction time (GMT TimeStamp) */

        Breach()
        {}

        Breach(const std::string& _trdr, const std::string& _sendt, const std::string& _com, const std::string& _exp,
            const std::string& _contract, const std::string& _acc, const std::string& _sok, const std::string& _exid,
            const std::string& _fil, const std::string& _soid, const std::string& _bs, const std::string& _exprice,
            const std::string& _price, const std::string& _vol, const std::string& _lfprice, const std::string& _gmt): 
        trdr(_trdr), sendt(_sendt), com(_com), exp(_exp), contract(_contract), acc(_acc), sok(_sok), exid(_exid), 
        fil(_fil), soid(_soid), bs(_bs), exprice(_exprice), price(_price), vol(_vol), lfprice(_lfprice), gmt(_gmt) {}
    
        bool operator==(const Breach& p) const
        {
            //return x == p.x && y == p.y && z == p.z; // a == p.a &&
            return trdr == p.trdr && com == p.com && exp == p.exp && contract == p.contract && acc == p.acc
                     && sok == p.sok && exid == p.exid && fil == p.fil && soid == p.soid
                     && bs == p.bs && exprice == p.exprice && price == p.price && vol == p.vol
                    && lfprice == p.lfprice && gmt == p.gmt;
        }

        bool operator<(const Breach& p) const
        {
            //if(a < p.a) return true;
            //if(a > p.a) return false;
            if(trdr < p.trdr) return true;
            if(trdr > p.trdr) return false;
            if(com < p.com) return true;
            if(com > p.com) return false;
            if(exp < p.exp) return true;
            if(exp > p.exp) return false;
            if(contract < p.contract) return true;
            if(contract > p.contract) return false;
            if(acc < p.acc) return true;
            if(acc > p.acc) return false;
            if(sok < p.sok) return true;
            if(sok > p.sok) return false;
            if(exid < p.exid) return true;
            if(exid > p.exid) return false;
            if(fil < p.fil) return true;
            if(fil > p.fil) return false;
            if(soid < p.soid) return true;
            if(soid > p.soid) return false;
            if(bs < p.bs) return true;
            if(bs > p.bs) return false;
            if(exprice < p.exprice) return true;
            if(exprice > p.exprice) return false;
            if(price < p.price) return true;
            if(price > p.price) return false;
            if(vol < p.vol) return true;
            if(vol > p.vol) return false;
            if(lfprice < p.lfprice) return true;
            if(lfprice > p.lfprice) return false;
            if(gmt < p.gmt) return true;
            if(gmt > p.gmt) return false;        

            return false;
        }
    };
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99

int main()
{
std::vector<Breach>* vPred = new std::vector<Breach>;
    vPred->push_back(Breach("GRC", "01.06.2010 00:19:00.562", "GE", "FUT", "XGGRC", "0G4LHZ013", "14ijpol1vsu7l7", "Fill", "0000D9DB", "201009","2", "B","00000", "99.155","99.155 ","31.05.2010 23:01:00.562"));
    vPred->push_back(Breach("GRC", "01.06.2010 00:33:00.562", "GE", "FUT", "XGGRC", "0G4LHZ013", "14ijpol1vsu7l7", "Fill", "0000D9DB", "201009","2", "B","00000", "99.155","99.155 ","31.05.2010 23:01:00.562"));
    vPred->push_back(Breach("GRC", "01.06.2010 00:10:00.562", "GE", "FUT", "XGGRC", "0G4LHZ013", "14ijpol1vsu7l7", "Fill", "0000D9DB", "201009","2", "B","00000", "99.155","99.155 ","31.05.2010 23:01:00.562"));

    vPred->push_back(Breach("XBY", "03.06.2010 00:10:00.562", "ZM", "FUT", "XGXBY", "0G4LHZ013", "142th059zagt", "Fill", "0001J8CN", "201109","1", "B","00000", "95.155","95.155 ","03.06.2010 00:07:00.562"));
    vPred->push_back(Breach("XBY", "03.06.2010 00:06:00.562", "ZM", "FUT", "XGXBY", "0G4LHZ013", "142th059zagt", "Fill", "0001J8CN", "201109","1", "B","00000", "95.155","95.155 ","03.06.2010 00:07:00.562"));

    vPred->push_back(Breach("CCH", "02.06.2010 00:06:00.562", "KH", "FUT", "XGCCH", "0G4LHZ013", "w74yk1o01l4v", "Fill", "0001KKDX", "201012","3", "S","00000", "95.155","95.155 ","02.06.2010 00:07:00.562"));

    vPred->push_back(Breach("HKG", "04.06.2010 00:06:00.562", "GH", "FUT", "ABCDE", "0G4LHZ013", "1xc1va81dsd5n3", "Fill", "0001J8CR", "201105","1", "S","00000", "95.155","95.155 ","04.06.2010 00:07:00.562"));

    vPred->push_back(Breach("SKD", "05.06.2010 00:06:00.562", "KL", "FUT", "MNOPQ", "0G4LHZ013", "hs1tnl1i0r4h5", "Fill", "0001KKE2", "201101","1", "B","00000", "95.155","95.155 ","05.06.2010 00:07:00.562"));

// The values need to be in order for equal_range() to work
std::sort(vPred->begin(), vPred->end());

    std::vector<Breach> uPred; // values that were always unique
    std::vector<Breach>* dPred = new std::vector<Breach>; // values that were duplicated

    std::pair<std::vector<Breach>::iterator, std::vector<Breach>::iterator> ret;

    for(std::vector<Breach>::iterator i = vPred->begin(); i != vPred->end(); i = ret.second)
    {
        ret = std::equal_range(i, vPred->end(), *i);

        if(ret.second - ret.first != 1) // duplicates
        {
            time_t diff; // general diff register
            time_t min_diff; // register smallest difference in time
            std::vector<Breach>::iterator min_iter; // register corresponding iterator
            std::vector<Breach>::iterator j; // range iterator

            // initialise min register to the first difference
            // in our range
            time_diff(ret.first->sendt, ret.first->gmt, min_diff);

            // iterate over the range of duplicates finding a
            // the smallest difference as we go and noting the
            // corresponding iterator
            for(min_iter = j = ret.first; j != ret.second; ++j)
            {
                // get difference
                time_diff(j->sendt, j->gmt, diff);

                // is it smaller than our current minimum?
                if(diff < min_diff)
                {
                    min_diff = diff; // keep it as our new minimum
                    min_iter = j; // remember the iterator to the smallest difference so far
                }
            }
            // push the value recorded to be smallest onto our vector
            dPred->push_back(*min_iter);
        }
        else if(ret.second - ret.first == 1)
        {
            uPred.push_back(*i);
        }
    }
    cout << "dPred Size = " << dPred->size() << endl;
    std::cout << "===================\n";
    std::cout << "vPred: Sorted input\n";
    std::cout << "===================\n";
    for(std::vector<Breach>::iterator i = vPred->begin(); i != vPred->end(); ++i)
    {
        std::cout << "[" << i->sendt << ", " << i->trdr << ", " << i->com << ", " << i->exp << ", " << i->contract << ", " 
        << i->acc << ", " << i->sok << ", " << i->exid << ", " << i->fil << ", " << i->soid << ", " << i->bs << ", "  
        << i->exprice << ", " << i->price << ", " << i->vol << ", " << i->lfprice << ", " << i->gmt << "]" << endl;
    }
    cout << endl;

    std::cout << "===========================================\n";
    std::cout << "dPred: Only the values that were duplicated\n";
    std::cout << "===========================================\n";
    for(std::vector<Breach>::iterator i = dPred->begin(); i != dPred->end(); ++i)
    {
        std::cout << "[" << i->sendt << ", " << i->trdr << ", " << i->com << ", " << i->exp << ", " << i->contract << ", " 
        << i->acc << ", " << i->sok << ", " << i->exid << ", " << i->fil << ", " << i->soid << ", " << i->bs << ", "  
        << i->exprice << ", " << i->price << ", " << i->vol << ", " << i->lfprice << ", " << i->gmt << "]" << endl;
    }
    cout << endl;

    std::cout << "=======================================\n";
    std::cout << "uPred: Only the values that were unique\n";
    std::cout << "=======================================\n";
    for(std::vector<Breach>::iterator i = uPred.begin(); i != uPred.end(); ++i)
    {
        std::cout << "[" << i->sendt << ", " << i->trdr << ", " << i->com << ", " << i->exp << ", " << i->contract << ", " 
        << i->acc << ", " << i->sok << ", " << i->exid << ", " << i->fil << ", " << i->soid << ", " << i->bs << ", "  
        << i->exprice << ", " << i->price << ", " << i->vol << ", " << i->lfprice << ", " << i->gmt << "]" << endl;
    }

    delete vPred;
    delete dPred;
}
You just need to change the order you read the date components in. Unless you need to be accurate to the three decimal places in the second?

Ignoring the 3 decimal places in the second this code should work:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
bool get_time(const std::string& s, time_t& time)
{
// dd.mm.yyyy hh:mm:ss.sss
tm date;
date.tm_isdst = 0;
std::istringstream iss(s);
std::string line;
char c;
if(!(iss >> date.tm_mday >> c)) return false;
if(!(iss >> date.tm_mon >> c)) return false;
if(!(iss >> date.tm_year >> c)) return false;
if(!(iss >> date.tm_hour >> c)) return false;
if(!(iss >> date.tm_min >> c)) return false;
if(!(iss >> date.tm_sec >> c)) return false;
date.tm_mon -= 1; // needs to be 0-11 (not 1-12)
date.tm_year -= 1900;
time = mktime(&date);

return true;
}
Last edited on
You are a GENIUS :D. That's exactly it. East and West Galik is the best :D.
1
2
3
4
while (1)
{
        THANK YOU :)
}
Hello and Good Morning Galik. Please dont get angry with me ;'(. I made changes to the code here in office but it still is giving me the same result.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <ctime>
#include <iomanip>
#include <cstdlib>

using namespace std;

bool get_time(const std::string& s, time_t& time)
{
	// dd.mm.yyyy hh:mm:ss.sss
	tm date;
	date.tm_isdst = 0;
	std::istringstream iss(s);
	std::string line;
	char c;
	if(!(iss >> date.tm_mday >> c)) return false;
	if(!(iss >> date.tm_mon >> c)) return false;
	if(!(iss >> date.tm_year >> c)) return false;
	if(!(iss >> date.tm_hour >> c)) return false;
	if(!(iss >> date.tm_min >> c)) return false;
	if(!(iss >> date.tm_sec >> c)) return false;
	date.tm_mon -= 1; // needs to be 0-11 (not 1-12)
	date.tm_year -= 1900;
	time = mktime(&date);

	return true;
}

bool time_diff(const std::string& a, const std::string& z, time_t& diff)
{
time_t atime;
time_t ztime;
if(get_time(a, atime) && get_time(z, ztime))
{
diff = std::abs(ztime - atime);
return true;
}
return false;
}

struct Breach
	{
		  string trdr;        /*!< Trader itm */
		  string sendt;       /*!< Time of message transmission */  
		  string com;         /*!< Commodity */
		  string exp;         /*!< Expiry */

		  string contract;    /*!< Contract type */
		  string acc;         /*!< Account Ref */
		  string sok;         /*!< Site Order Key */
		  string exid;        /*!< Execution Id */

		  string fil;         /*!< Order Fill info */
		  string soid;        /*!< Secondary Order Id */
		  string bs;          /*!< Buy Sell */
		  string exprice;     /*!< Exercise Price */

		  string price;       /*!< Price */
		  string vol;         /*!< Volume */
		  string lfprice;     /*!< Last Fill Price */
		  string gmt;         /*!< Transaction time (GMT TimeStamp) */

		Breach()
		{}

		Breach(const std::string& _sendt, const std::string& _trdr, const std::string& _com, const std::string& _exp,
			const std::string& _contract, const std::string& _acc, const std::string& _sok, const std::string& _exid,
			const std::string& _fil, const std::string& _soid, const std::string& _bs, const std::string& _exprice,
			const std::string& _price, const std::string& _vol, const std::string& _lfprice, const std::string& _gmt): 
		sendt(_sendt), trdr(_trdr), com(_com), exp(_exp), contract(_contract), acc(_acc), sok(_sok), exid(_exid), 
		fil(_fil), soid(_soid), bs(_bs), exprice(_exprice), price(_price), vol(_vol), lfprice(_lfprice), gmt(_gmt) {}
	
		bool operator==(const Breach& p) const
		{
			//return x == p.x && y == p.y && z == p.z; // a == p.a &&
			return trdr == p.trdr && com == p.com && exp == p.exp && contract == p.contract && acc == p.acc
					 && sok == p.sok && exid == p.exid && fil == p.fil && soid == p.soid
					 && bs == p.bs && exprice == p.exprice && price == p.price && vol == p.vol
					&& lfprice == p.lfprice && gmt == p.gmt;
		}

		bool operator<(const Breach& p) const
		{
			if(trdr < p.trdr) return true;
			if(trdr > p.trdr) return false;
			if(com < p.com) return true;
			if(com > p.com) return false;
			if(exp < p.exp) return true;
			if(exp > p.exp) return false;
			if(contract < p.contract) return true;
			if(contract > p.contract) return false;
			if(acc < p.acc) return true;
			if(acc > p.acc) return false;
			if(sok < p.sok) return true;
			if(sok > p.sok) return false;
			if(exid < p.exid) return true;
			if(exid > p.exid) return false;
			if(fil < p.fil) return true;
			if(fil > p.fil) return false;
			if(soid < p.soid) return true;
			if(soid > p.soid) return false;
			if(bs < p.bs) return true;
			if(bs > p.bs) return false;
			if(exprice < p.exprice) return true;
			if(exprice > p.exprice) return false;
			if(price < p.price) return true;
			if(price > p.price) return false;
			if(vol < p.vol) return true;
			if(vol > p.vol) return false;
			if(lfprice < p.lfprice) return true;
			if(lfprice > p.lfprice) return false;
			if(gmt < p.gmt) return true;
			if(gmt > p.gmt) return false;		

			return false;
		}
	};
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
int main()
{

	std::vector<Breach>* vPred = new std::vector<Breach>;

	vPred->push_back(Breach("20100601-00:19:00.562", "ABCRDIIGYGRC", "GE", "201009", "FUT", "XGGRC", "0G4LHZ013", "14ijpol1vsu7l7", "Fill", "0000D9DB", "2", "00000", "99.155", "1", "99.155 ","20100531-23:01:00.562"));
	vPred->push_back(Breach("20100601-00:33:00.562", "ABCRDIIGYGRC", "GE", "201009", "FUT", "XGGRC", "0G4LHZ013", "14ijpol1vsu7l7", "Fill", "0000D9DB", "2", "00000", "99.155", "1","99.155 ","20100531-23:01:00.562"));
	vPred->push_back(Breach("20100601-00:10:00.562", "ABCRDIIGYGRC", "GE", "201009", "FUT", "XGGRC", "0G4LHZ013", "14ijpol1vsu7l7", "Fill", "0000D9DB", "2", "00000", "99.155", "1","99.155 ","20100531-23:01:00.562"));

	vPred->push_back(Breach("20100603-00:10:00.562", "ABCRDIIGYXBY", "ZM", "201109", "FUT", "XGXBY", "0G4LHZ013", "142th059zagt", "Fill", "0001J8CN", "1", "00000", "95.155", "2","95.155 ","20100603-00:07:00.562"));
	vPred->push_back(Breach("20100603-00:08:00.562", "ABCRDIIGYXBY", "ZM", "201109", "FUT", "XGXBY", "0G4LHZ013", "142th059zagt", "Fill", "0001J8CN", "1", "00000", "95.155", "2","95.155 ","20100603-00:07:00.562"));

	vPred->push_back(Breach("20100602-00:06:00.562", "ABCRDIIGYCCH", "KH", "201012", "FUT", "XGCCH", "0G4LHZ013", "w74yk1o01l4v", "Fill", "0001KKDX", "3", "00000", "95.155", "2","95.155 ","20100602-00:07:00.562"));

	vPred->push_back(Breach("20100604-00:06:00.562", "ABCRDIIGYHKG", "GH", "201105", "FUT", "ABCDE", "0G4LHZ013", "1xc1va81dsd5n3", "Fill", "0001J8CR", "1","00000", "95.155", "2","95.155 ","20100604-00:07:00.562"));

	vPred->push_back(Breach("20100605-00:06:00.562", "ABCRDIIGYSKD", "KL", "201101", "FUT", "MNOPQ", "0G4LHZ013", "hs1tnl1i0r4h5", "Fill", "0001KKE2", "1", "00000", "95.155", "1","95.155 ","20100605-00:07:00.562"));

// The values need to be in order for equal_range() to work
std::sort(vPred->begin(), vPred->end());

	std::vector<Breach> uPred; // values that were always unique
	std::vector<Breach>* dPred = new std::vector<Breach>; // values that were duplicated

	std::pair<std::vector<Breach>::iterator, std::vector<Breach>::iterator> ret;

	for(std::vector<Breach>::iterator i = vPred->begin(); i != vPred->end(); i = ret.second)
	{
		ret = std::equal_range(i, vPred->end(), *i);

		if(ret.second - ret.first != 1) // duplicates
		{
			time_t diff; // general diff register
			time_t min_diff; // register smallest difference in time
			std::vector<Breach>::iterator min_iter; // register corresponding iterator
			std::vector<Breach>::iterator j; // range iterator

			// initialise min register to the first difference
			// in our range
			time_diff(ret.first->sendt, ret.first->gmt, min_diff);

			// iterate over the range of duplicates finding a
			// the smallest difference as we go and noting the
			// corresponding iterator
			for(min_iter = j = ret.first; j != ret.second; ++j)
			{
				// get difference
				time_diff(j->sendt, j->gmt, diff);

				// is it smaller than our current minimum?
				if(diff < min_diff)
				{
					min_diff = diff; // keep it as our new minimum
					min_iter = j; // remember the iterator to the smallest difference so far
				}
			}
			// push the value recorded to be smallest onto our vector
			dPred->push_back(*min_iter);
		}
		else if(ret.second - ret.first == 1)
		{
			uPred.push_back(*i);
		}
	}
	cout << "dPred Size = " << dPred->size() << endl;
	std::cout << "===================\n";
	std::cout << "vPred: Sorted input\n";
	std::cout << "===================\n";
	for(std::vector<Breach>::iterator i = vPred->begin(); i != vPred->end(); ++i)
	{
		std::cout << "[" << i->sendt << ", " << i->trdr << ", " << i->com << ", " << i->exp << ", " << i->contract << ", " 
		<< i->acc << ", " << i->sok << ", " << i->exid << ", " << i->fil << ", " << i->soid << ", " << i->bs << ", "  
		<< i->exprice << ", " << i->price << ", " << i->vol << ", " << i->lfprice << ", " << i->gmt << "]" << endl;
	}
	cout << endl;

	std::cout << "===========================================\n";
	std::cout << "dPred: Only the values that were duplicated\n";
	std::cout << "===========================================\n";
	for(std::vector<Breach>::iterator i = dPred->begin(); i != dPred->end(); ++i)
	{
		std::cout << "[" << i->sendt << ", " << i->trdr << ", " << i->com << ", " << i->exp << ", " << i->contract << ", " 
		<< i->acc << ", " << i->sok << ", " << i->exid << ", " << i->fil << ", " << i->soid << ", " << i->bs << ", "  
		<< i->exprice << ", " << i->price << ", " << i->vol << ", " << i->lfprice << ", " << i->gmt << "]" << endl;
	}
	cout << endl;

	std::cout << "=======================================\n";
	std::cout << "uPred: Only the values that were unique\n";
	std::cout << "=======================================\n";
	for(std::vector<Breach>::iterator i = uPred.begin(); i != uPred.end(); ++i)
	{
		std::cout << "[" << i->sendt << ", " << i->trdr << ", " << i->com << ", " << i->exp << ", " << i->contract << ", " 
		<< i->acc << ", " << i->sok << ", " << i->exid << ", " << i->fil << ", " << i->soid << ", " << i->bs << ", "  
		<< i->exprice << ", " << i->price << ", " << i->vol << ", " << i->lfprice << ", " << i->gmt << "]" << endl;
	}

	delete vPred;
	delete dPred;
}
Output


===================
vPred: Sorted input
===================
[20100602-00:06:00.562, ABCRDIIGYCCH, KH, 201012, FUT, XGCCH, 0G4LHZ013, w74yk1o01l4v, Fill, 0001KKDX, 3, 00000, 95.155, 2, 95.155 , 20100602-00:07:00.562]
[20100601-00:19:00.562, ABCRDIIGYGRC, GE, 201009, FUT, XGGRC, 0G4LHZ013, 14ijpol1vsu7l7, Fill, 0000D9DB, 2, 00000, 99.155, 1, 99.155 , 20100531-23:01:00.562]
[20100601-00:33:00.562, ABCRDIIGYGRC, GE, 201009, FUT, XGGRC, 0G4LHZ013, 14ijpol1vsu7l7, Fill, 0000D9DB, 2, 00000, 99.155, 1, 99.155 , 20100531-23:01:00.562]
[20100601-00:10:00.562, ABCRDIIGYGRC, GE, 201009, FUT, XGGRC, 0G4LHZ013, 14ijpol1vsu7l7, Fill, 0000D9DB, 2, 00000, 99.155, 1, 99.155 , 20100531-23:01:00.562]
[20100604-00:06:00.562, ABCRDIIGYHKG, GH, 201105, FUT, ABCDE, 0G4LHZ013, 1xc1va81dsd5n3, Fill, 0001J8CR, 1, 00000, 95.155, 2, 95.155 , 20100604-00:07:00.562]
[20100605-00:06:00.562, ABCRDIIGYSKD, KL, 201101, FUT, MNOPQ, 0G4LHZ013, hs1tnl1i0r4h5, Fill, 0001KKE2, 1, 00000, 95.155, 1, 95.155 , 20100605-00:07:00.562]
[20100603-00:10:00.562, ABCRDIIGYXBY, ZM, 201109, FUT, XGXBY, 0G4LHZ013, 142th059zagt, Fill, 0001J8CN, 1, 00000, 95.155, 2, 95.155 , 20100603-00:07:00.562]
[20100603-00:08:00.562, ABCRDIIGYXBY, ZM, 201109, FUT, XGXBY, 0G4LHZ013, 142th059zagt, Fill, 0001J8CN, 1, 00000, 95.155, 2, 95.155 , 20100603-00:07:00.562]

===========================================
dPred: Only the values that were duplicated
===========================================
[20100601-00:19:00.562, ABCRDIIGYGRC, GE, 201009, FUT, XGGRC, 0G4LHZ013, 14ijpol1vsu7l7, Fill, 0000D9DB, 2, 00000, 99.155, 1, 99.155 , 20100531-23:01:00.562]
[20100603-00:10:00.562, ABCRDIIGYXBY, ZM, 201109, FUT, XGXBY, 0G4LHZ013, 142th059zagt, Fill, 0001J8CN, 1, 00000, 95.155, 2, 95.155 , 20100603-00:07:00.562]

=======================================
uPred: Only the values that were unique
=======================================
[20100602-00:06:00.562, ABCRDIIGYCCH, KH, 201012, FUT, XGCCH, 0G4LHZ013, w74yk1o01l4v, Fill, 0001KKDX, 3, 00000, 95.155, 2, 95.155 , 20100602-00:07:00.562]
[20100604-00:06:00.562, ABCRDIIGYHKG, GH, 201105, FUT, ABCDE, 0G4LHZ013, 1xc1va81dsd5n3, Fill, 0001J8CR, 1, 00000, 95.155, 2, 95.155 , 20100604-00:07:00.562]
[20100605-00:06:00.562, ABCRDIIGYSKD, KL, 201101, FUT, MNOPQ, 0G4LHZ013, hs1tnl1i0r4h5, Fill, 0001KKE2, 1, 00000, 95.155, 1, 95.155 , 20100605-00:07:00.562]

You do realise that the format of the data has changed? This has happened twice now. You can't write the program if the format of the data keeps changing. They need to precisely specify what the format is and if the data is coming in several different formats then you need to know all of them in advance :o)
This is the format that's stored in the file that I am reading from.

20100531-23:53:12.346 :-P
Well, if you change the format of your date/time then you need to change how you read it in from the string:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
bool get_time(const std::string& s, time_t& time)
{
	// yyyymmdd-hh:mm:ss.sss
	tm date;
	date.tm_isdst = 0;
	std::istringstream iss(s);
	std::string line;
	char c;

	// Read date as a whole string up to '-' (yyyymmdd)
	if(!(std::getline(iss, line, '-') >> c)) return false;
	if(line.size() != 8) return false; // illegal data should be 8 characters

	// pick out pieces of date
	if(!(std::istringstream(line.substr(0, 4)) >> date.tm_year)) return false;
	if(!(std::istringstream(line.substr(4, 2)) >> date.tm_mon)) return false;
	if(!(std::istringstream(line.substr(6, 2)) >> date.tm_mday)) return false;

	// read time
	if(!(iss >> date.tm_hour >> c)) return false;
	if(!(iss >> date.tm_min >> c)) return false;
	if(!(iss >> date.tm_sec >> c)) return false;

	// adjust to struct tm spec bounds
	date.tm_mon -= 1; // needs to be 0-11 (not 1-12)
	date.tm_year -= 1900;
	time = mktime(&date);

	return true;
}
I think it is comparing only the first and second duplicates. In this case start/end time of first duplicate is

20100601-00:01:00.562 and the end time is 20100531-23:53:12.346

start/end time of the second duplicate is

20100601-00:30:00.562, and the end time is 20100531-23:53:12.346

start/end time of the third duplicate is

20100601-00:00:00.562 and the end time is 20100531-23:53:12.346

And the output is:


===================
vPred: Sorted input
===================
[20100601-00:01:00.562, TTORDIIGYIGY, ZW, 201007, FUT, XGIGY, 082X5C003, 1yprzag67hz6x, Fill, 000136XB, 2, 00000, 458.5, 1, 458.5, 20100531-23:53:12.346]
[20100601-00:30:00.562, TTORDIIGYIGY, ZW, 201007, FUT, XGIGY, 082X5C003, 1yprzag67hz6x, Fill, 000136XB, 2, 00000, 458.5, 1, 458.5, 20100531-23:53:12.346]

[20100601-00:00:00.562, UVWRDIIGYIGY, ZW, 201007, FUT, XGIGY, 082X5C003, 1yprzag67hz6x, Fill, 000136XB, 2, 00000, 458.5, 1, 458.5, 20100531-23:53:12.346]

===========================================
dPred: Only the values that were duplicated
===========================================

[20100601-00:01:00.562, TTORDIIGYIGY, ZW, 201007, FUT, XGIGY, 082X5C003, 1yprzag67hz6x, Fill, 000136XB, 2, 00000, 458.5, 1, 458.5, 20100531-23:53:12.346]



And when I rearrange the duplicates (on the basis of time) like:


===================
vPred: Sorted input
===================

[20100601-00:01:00.562, TTORDIIGYIGY, ZW, 201007, FUT, XGIGY, 082X5C003, 1yprzag67hz6x, Fill, 000136XB, 2, 00000, 458.5, 1, 458.5, 20100531-23:53:12.346]

[20100601-00:00:00.562, UVWRDIIGYIGY, ZW, 201007, FUT, XGIGY, 082X5C003, 1yprzag67hz6x, Fill, 000136XB, 2, 00000, 458.5, 1, 458.5, 20100531-23:53:12.346]

[20100601-00:30:00.562, TTORDIIGYIGY, ZW, 201007, FUT, XGIGY, 082X5C003, 1yprzag67hz6x, Fill, 000136XB, 2, 00000, 458.5, 1, 458.5, 20100531-23:53:12.346]

===========================================
dPred: Only the values that were duplicated
===========================================
[code]
[20100601-00:00:00.562, TTORDIIGYIGY, ZW, 201007, FUT, XGIGY, 082X5C003, 1yprzag67hz6x, Fill, 000136XB, 2, 00000, 458.5, 1, 458.5, 20100531-23:53:12.346]
[/code]


Am I right???

I am sorry, I dont want to disturb you, please help when you have time.
I can't repeat your problem here. Can you supply more data. Some data from before these values and some data after. It might be a roll-on problem from previous data?

================
Data Read from FIle:
================
TTORDIIGYIGY 20100601-00:30:00.562 ZW FUT XGIGY 082X5C003 1yprzag67hz6x Fill 000136XB 201007 1 2 00000 458.5 458.5 20100531-23:53:12.346 
TTORDIIGYIGY 20100601-00:01:00.562 ZW FUT XGIGY 082X5C003 1yprzag67hz6x Fill 000136XB 201007 1 2 00000 458.5 458.5 20100531-23:53:12.346 
XYZRDIIGYIGY 20100601-00:12:00.562 ZW FUT HKGHJ 082X5C003 1yprzag67hz6x Fill 000136XB 201007 1 2 00000 458.5 458.5 20100601-23:15:12.346 
XYZRDIIGYIGY 20100601-00:11:00.562 ZW FUT HKGHJ 082X5C003 1yprzag67hz6x Fill 000136XB 201007 1 2 00000 458.5 458.5 20100531-23:15:12.346 
ABCRDIIGYIGY 20100601-00:55:00.562 ZW FUT LMNOP 082X5C003 1yprzag67hz6x Fill 000136XB 201007 1 2 00000 458.5 458.5 20100601-23:13:12.346 
ABCRDIIGYIGY 20100601-00:33:00.562 ZW FUT LMNOP 082X5C003 1yprzag67hz6x Fill 000136XB 201007 1 2 00000 458.5 458.5 20100601-23:13:12.346 
OPQRDIIGYIGY 20100601-00:00:00.562 ZW FUT ABCDE 082X5C003 1yprzag67hz6x Fill 000136XB 201007 1 2 00000 458.5 458.5 20100531-23:29:12.346 
RSTRDIIGYIGY 20100601-00:00:00.562 ZW FUT ABCDE 082X5C003 1yprzag67hz6x Fill 000136XB 201007 1 2 00000 458.5 458.5 20100531-23:53:12.346 
UVWRDIIGYIGY 20100601-00:00:00.562 ZW FUT XGIGY 082X5C003 1yprzag67hz6x Fill 000136XB 201007 1 2 00000 458.5 458.5 20100531-23:53:12.346 
LMNRDIIGYIGY 20100601-00:00:00.562 ZW FUT OPQRZ 082X5C003 1yprzag67hz6x Fill 000136XB 201007 1 2 00000 458.5 458.5 20100531-23:53:12.346 
dPred Size = 2
===================
vPred: Sorted input
===================
[20100601-00:55:00.562, ABCRDIIGYIGY, ZW, 201007, FUT, LMNOP, 082X5C003, 1yprzag67hz6x, Fill, 000136XB, 2, 00000, 458.5, 1, 458.5, 20100601-23:13:12.346]
[20100601-00:33:00.562, ABCRDIIGYIGY, ZW, 201007, FUT, LMNOP, 082X5C003, 1yprzag67hz6x, Fill, 000136XB, 2, 00000, 458.5, 1, 458.5, 20100601-23:13:12.346]

[20100601-00:00:00.562, LMNRDIIGYIGY, ZW, 201007, FUT, OPQRZ, 082X5C003, 1yprzag67hz6x, Fill, 000136XB, 2, 00000, 458.5, 1, 458.5, 20100531-23:53:12.346]
[20100601-00:00:00.562, OPQRDIIGYIGY, ZW, 201007, FUT, ABCDE, 082X5C003, 1yprzag67hz6x, Fill, 000136XB, 2, 00000, 458.5, 1, 458.5, 20100531-23:29:12.346]
[20100601-00:00:00.562, RSTRDIIGYIGY, ZW, 201007, FUT, ABCDE, 082X5C003, 1yprzag67hz6x, Fill, 000136XB, 2, 00000, 458.5, 1, 458.5, 20100531-23:53:12.346]

[20100601-00:30:00.562, TTORDIIGYIGY, ZW, 201007, FUT, XGIGY, 082X5C003, 1yprzag67hz6x, Fill, 000136XB, 2, 00000, 458.5, 1, 458.5, 20100531-23:53:12.346]
[20100601-00:01:00.562, TTORDIIGYIGY, ZW, 201007, FUT, XGIGY, 082X5C003, 1yprzag67hz6x, Fill, 000136XB, 2, 00000, 458.5, 1, 458.5, 20100531-23:53:12.346]
[20100601-00:00:00.562, UVWRDIIGYIGY, ZW, 201007, FUT, XGIGY, 082X5C003, 1yprzag67hz6x, Fill, 000136XB, 2, 00000, 458.5, 1, 458.5, 20100531-23:53:12.346]

[20100601-00:11:00.562, XYZRDIIGYIGY, ZW, 201007, FUT, HKGHJ, 082X5C003, 1yprzag67hz6x, Fill, 000136XB, 2, 00000, 458.5, 1, 458.5, 20100531-23:15:12.346]
[20100601-00:12:00.562, XYZRDIIGYIGY, ZW, 201007, FUT, HKGHJ, 082X5C003, 1yprzag67hz6x, Fill, 000136XB, 2, 00000, 458.5, 1, 458.5, 20100601-23:15:12.346]

===========================================
dPred: Only the values that were duplicated
===========================================
[20100601-00:55:00.562, ABCRDIIGYIGY, ZW, 201007, FUT, LMNOP, 082X5C003, 1yprzag67hz6x, Fill, 000136XB, 2, 00000, 458.5, 1, 458.5, 20100601-23:13:12.346]
[20100601-00:01:00.562, TTORDIIGYIGY, ZW, 201007, FUT, XGIGY, 082X5C003, 1yprzag67hz6x, Fill, 000136XB, 2, 00000, 458.5, 1, 458.5, 20100531-23:53:12.346]

=======================================
uPred: Only the values that were unique
=======================================
[20100601-00:00:00.562, LMNRDIIGYIGY, ZW, 201007, FUT, OPQRZ, 082X5C003, 1yprzag67hz6x, Fill, 000136XB, 2, 00000, 458.5, 1, 458.5, 20100531-23:53:12.346]
[20100601-00:00:00.562, OPQRDIIGYIGY, ZW, 201007, FUT, ABCDE, 082X5C003, 1yprzag67hz6x, Fill, 000136XB, 2, 00000, 458.5, 1, 458.5, 20100531-23:29:12.346]
[20100601-00:00:00.562, RSTRDIIGYIGY, ZW, 201007, FUT, ABCDE, 082X5C003, 1yprzag67hz6x, Fill, 000136XB, 2, 00000, 458.5, 1, 458.5, 20100531-23:53:12.346]
[20100601-00:00:00.562, UVWRDIIGYIGY, ZW, 201007, FUT, XGIGY, 082X5C003, 1yprzag67hz6x, Fill, 000136XB, 2, 00000, 458.5, 1, 458.5, 20100531-23:53:12.346]
[20100601-00:11:00.562, XYZRDIIGYIGY, ZW, 201007, FUT, HKGHJ, 082X5C003, 1yprzag67hz6x, Fill, 000136XB, 2, 00000, 458.5, 1, 458.5, 20100531-23:15:12.346]
[20100601-00:12:00.562, XYZRDIIGYIGY, ZW, 201007, FUT, HKGHJ, 082X5C003, 1yprzag67hz6x, Fill, 000136XB, 2, 00000, 458.5, 1, 458.5, 20100601-23:15:12.346]

This is ver strange. The version I have is giving the right answer as far as I can tell. I am posting it here for you to see if there are any differences in your code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134

#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <ctime>
#include <iomanip>
#include <cstdlib>

using namespace std;

bool get_time(const std::string& s, time_t& time)
{
	// yyyymmdd-hh:mm:ss.sss
	tm date;
	date.tm_isdst = 0;
	std::istringstream iss(s);
	std::string line;
	char c;

	// Read date as a whole string up to '-' (yyyymmdd)
	if(!(std::getline(iss, line, '-') >> c)) return false;
	if(line.size() != 8) return false; // illegal data should be 8 characters

	// pick out pieces of date
	if(!(std::istringstream(line.substr(0, 4)) >> date.tm_year)) return false;
	if(!(std::istringstream(line.substr(4, 2)) >> date.tm_mon)) return false;
	if(!(std::istringstream(line.substr(6, 2)) >> date.tm_mday)) return false;

	// read time
	if(!(iss >> date.tm_hour >> c)) return false;
	if(!(iss >> date.tm_min >> c)) return false;
	if(!(iss >> date.tm_sec >> c)) return false;

	// adjust to struct tm spec bounds
	date.tm_mon -= 1; // needs to be 0-11 (not 1-12)
	date.tm_year -= 1900;
	time = mktime(&date);

	return true;
}

bool time_diff(const std::string& a, const std::string& z, time_t& diff)
{
time_t atime;
time_t ztime;
if(get_time(a, atime) && get_time(z, ztime))
{
diff = std::abs(ztime - atime);
return true;
}
return false;
}

struct Breach
	{
		  string trdr;        /*!< Trader itm */
		  string sendt;       /*!< Time of message transmission */
		  string com;         /*!< Commodity */
		  string exp;         /*!< Expiry */

		  string contract;    /*!< Contract type */
		  string acc;         /*!< Account Ref */
		  string sok;         /*!< Site Order Key */
		  string exid;        /*!< Execution Id */

		  string fil;         /*!< Order Fill info */
		  string soid;        /*!< Secondary Order Id */
		  string bs;          /*!< Buy Sell */
		  string exprice;     /*!< Exercise Price */

		  string price;       /*!< Price */
		  string vol;         /*!< Volume */
		  string lfprice;     /*!< Last Fill Price */
		  string gmt;         /*!< Transaction time (GMT TimeStamp) */

		Breach()
		{}

		Breach(const std::string& _sendt, const std::string& _trdr, const std::string& _com, const std::string& _exp,
			const std::string& _contract, const std::string& _acc, const std::string& _sok, const std::string& _exid,
			const std::string& _fil, const std::string& _soid, const std::string& _bs, const std::string& _exprice,
			const std::string& _price, const std::string& _vol, const std::string& _lfprice, const std::string& _gmt):
		sendt(_sendt), trdr(_trdr), com(_com), exp(_exp), contract(_contract), acc(_acc), sok(_sok), exid(_exid),
		fil(_fil), soid(_soid), bs(_bs), exprice(_exprice), price(_price), vol(_vol), lfprice(_lfprice), gmt(_gmt) {}

		bool operator==(const Breach& p) const
		{
			//return x == p.x && y == p.y && z == p.z; // a == p.a &&
			return trdr == p.trdr && com == p.com && exp == p.exp && contract == p.contract && acc == p.acc
					 && sok == p.sok && exid == p.exid && fil == p.fil && soid == p.soid
					 && bs == p.bs && exprice == p.exprice && price == p.price && vol == p.vol
					&& lfprice == p.lfprice && gmt == p.gmt;
		}

		bool operator<(const Breach& p) const
		{
			if(trdr < p.trdr) return true;
			if(trdr > p.trdr) return false;
			if(com < p.com) return true;
			if(com > p.com) return false;
			if(exp < p.exp) return true;
			if(exp > p.exp) return false;
			if(contract < p.contract) return true;
			if(contract > p.contract) return false;
			if(acc < p.acc) return true;
			if(acc > p.acc) return false;
			if(sok < p.sok) return true;
			if(sok > p.sok) return false;
			if(exid < p.exid) return true;
			if(exid > p.exid) return false;
			if(fil < p.fil) return true;
			if(fil > p.fil) return false;
			if(soid < p.soid) return true;
			if(soid > p.soid) return false;
			if(bs < p.bs) return true;
			if(bs > p.bs) return false;
			if(exprice < p.exprice) return true;
			if(exprice > p.exprice) return false;
			if(price < p.price) return true;
			if(price > p.price) return false;
			if(vol < p.vol) return true;
			if(vol > p.vol) return false;
			if(lfprice < p.lfprice) return true;
			if(lfprice > p.lfprice) return false;
			if(gmt < p.gmt) return true;
			if(gmt > p.gmt) return false;

			return false;
		}
	};

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
int main()
{

	std::vector<Breach>* vPred = new std::vector<Breach>;

	vPred->push_back(Breach("20100601-00:30:00.562", "X", "", "", "", "", "", "", "", "", "", "", "", "", ""
		,"20100531-23:53:12.346"));
	vPred->push_back(Breach("20100601-00:01:00.562", "X", "", "", "", "", "", "", "", "", "", "", "", "", ""
		,"20100531-23:53:12.346"));
	vPred->push_back(Breach("20100601-00:12:00.562", "H", "", "", "", "", "", "", "", "", "", "", "", "", ""
		,"20100601-23:15:12.346"));
	vPred->push_back(Breach("20100601-00:11:00.562", "H", "", "", "", "", "", "", "", "", "", "", "", "", ""
		,"20100531-23:15:12.346"));
	vPred->push_back(Breach("20100601-00:55:00.562", "L", "", "", "", "", "", "", "", "", "", "", "", "", ""
		,"20100601-23:13:12.346"));
	vPred->push_back(Breach("20100601-00:33:00.562", "L", "", "", "", "", "", "", "", "", "", "", "", "", ""
		,"20100601-23:13:12.346"));
	vPred->push_back(Breach("20100601-00:00:00.562", "A", "", "", "", "", "", "", "", "", "", "", "", "", ""
		,"20100531-23:29:12.346"));
	vPred->push_back(Breach("20100601-00:00:00.562", "A", "", "", "", "", "", "", "", "", "", "", "", "", ""
		,"20100531-23:53:12.346"));
	vPred->push_back(Breach("20100601-00:00:00.562", "X", "", "", "", "", "", "", "", "", "", "", "", "", ""
		,"20100531-23:53:12.346"));
	vPred->push_back(Breach("20100601-00:00:00.562", "O", "", "", "", "", "", "", "", "", "", "", "", "", ""
		,"20100531-23:53:12.346"));
	/*

TTORDIIGYIGY 20100601-00:30:00.562 ZW FUT XGIGY 082X5C003 1yprzag67hz6x Fill 000136XB 201007 1 2 00000 458.5 458.5
20100531-23:53:12.346
TTORDIIGYIGY 20100601-00:01:00.562 ZW FUT XGIGY 082X5C003 1yprzag67hz6x Fill 000136XB 201007 1 2 00000 458.5 458.5
20100531-23:53:12.346
XYZRDIIGYIGY 20100601-00:12:00.562 ZW FUT HKGHJ 082X5C003 1yprzag67hz6x Fill 000136XB 201007 1 2 00000 458.5 458.5
20100601-23:15:12.346
XYZRDIIGYIGY 20100601-00:11:00.562 ZW FUT HKGHJ 082X5C003 1yprzag67hz6x Fill 000136XB 201007 1 2 00000 458.5 458.5
20100531-23:15:12.346
ABCRDIIGYIGY 20100601-00:55:00.562 ZW FUT LMNOP 082X5C003 1yprzag67hz6x Fill 000136XB 201007 1 2 00000 458.5 458.5
20100601-23:13:12.346
ABCRDIIGYIGY 20100601-00:33:00.562 ZW FUT LMNOP 082X5C003 1yprzag67hz6x Fill 000136XB 201007 1 2 00000 458.5 458.5
20100601-23:13:12.346
OPQRDIIGYIGY 20100601-00:00:00.562 ZW FUT ABCDE 082X5C003 1yprzag67hz6x Fill 000136XB 201007 1 2 00000 458.5 458.5
20100531-23:29:12.346
RSTRDIIGYIGY 20100601-00:00:00.562 ZW FUT ABCDE 082X5C003 1yprzag67hz6x Fill 000136XB 201007 1 2 00000 458.5 458.5
20100531-23:53:12.346
UVWRDIIGYIGY 20100601-00:00:00.562 ZW FUT XGIGY 082X5C003 1yprzag67hz6x Fill 000136XB 201007 1 2 00000 458.5 458.5
20100531-23:53:12.346
LMNRDIIGYIGY 20100601-00:00:00.562 ZW FUT OPQRZ 082X5C003 1yprzag67hz6x Fill 000136XB 201007 1 2 00000 458.5 458.5
20100531-23:53:12.346
	 */

// The values need to be in order for equal_range() to work
std::sort(vPred->begin(), vPred->end());

	std::vector<Breach> uPred; // values that were always unique
	std::vector<Breach>* dPred = new std::vector<Breach>; // values that were duplicated

	std::pair<std::vector<Breach>::iterator, std::vector<Breach>::iterator> ret;

	for(std::vector<Breach>::iterator i = vPred->begin(); i != vPred->end(); i = ret.second)
	{
		ret = std::equal_range(i, vPred->end(), *i);

		if(ret.second - ret.first != 1) // duplicates
		{
			time_t diff; // general diff register
			time_t min_diff; // register smallest difference in time
			std::vector<Breach>::iterator min_iter; // register corresponding iterator
			std::vector<Breach>::iterator j; // range iterator

			// initialise min register to the first difference
			// in our range
			time_diff(ret.first->sendt, ret.first->gmt, min_diff);

			// iterate over the range of duplicates finding a
			// the smallest difference as we go and noting the
			// corresponding iterator
			for(min_iter = j = ret.first; j != ret.second; ++j)
			{
				// get difference
				time_diff(j->sendt, j->gmt, diff);

				// is it smaller than our current minimum?
				if(diff < min_diff)
				{
					min_diff = diff; // keep it as our new minimum
					min_iter = j; // remember the iterator to the smallest difference so far
				}
			}
			// push the value recorded to be smallest onto our vector
			dPred->push_back(*min_iter);
		}
		else if(ret.second - ret.first == 1)
		{
			uPred.push_back(*i);
		}
	}
	cout << "dPred Size = " << dPred->size() << endl;
	std::cout << "===================\n";
	std::cout << "vPred: Sorted input\n";
	std::cout << "===================\n";
	for(std::vector<Breach>::iterator i = vPred->begin(); i != vPred->end(); ++i)
	{
		std::cout << "[" << i->sendt << ", " << i->trdr << ", "/* << i->com << ", " << i->exp << ", " << i->contract << ", "
		<< i->acc << ", " << i->sok << ", " << i->exid << ", " << i->fil << ", " << i->soid << ", " << i->bs << ", "
		<< i->exprice << ", " << i->price << ", " << i->vol << ", "*/ << i->lfprice << ", " << i->gmt << "]" << endl;
	}
	cout << endl;

	std::cout << "===========================================\n";
	std::cout << "dPred: Only the values that were duplicated\n";
	std::cout << "===========================================\n";
	for(std::vector<Breach>::iterator i = dPred->begin(); i != dPred->end(); ++i)
	{
		std::cout << "[" << i->sendt << ", " << i->trdr << ", "/* << i->com << ", " << i->exp << ", " << i->contract << ", "
		<< i->acc << ", " << i->sok << ", " << i->exid << ", " << i->fil << ", " << i->soid << ", " << i->bs << ", "
		<< i->exprice << ", " << i->price << ", " << i->vol << ", "*/ << i->lfprice << ", " << i->gmt << "]" << endl;
	}
	cout << endl;

	std::cout << "=======================================\n";
	std::cout << "uPred: Only the values that were unique\n";
	std::cout << "=======================================\n";
	for(std::vector<Breach>::iterator i = uPred.begin(); i != uPred.end(); ++i)
	{
		std::cout << "[" << i->sendt << ", " << i->trdr << ", "/* << i->com << ", " << i->exp << ", " << i->contract << ", "
		<< i->acc << ", " << i->sok << ", " << i->exid << ", " << i->fil << ", " << i->soid << ", " << i->bs << ", "
		<< i->exprice << ", " << i->price << ", " << i->vol << ", "*/ << i->lfprice << ", " << i->gmt << "]" << endl;
	}

	delete vPred;
	delete dPred;
}
Pages: 1... 3456