I have two ways to get a bunch of data. Data is stored in a sorted vector<map<string, int> > .
I want to determine if there are inconsistencies between these two vectors.
What I'm doing now (pseudo-code):
for i in 0... min(length(vector1), length(vector2)): for (k, v) in vector1[i]: if v != vector2[i][k]: // report that k is bad for index i, // with vector1 having v, vector2 having vector2[i][k] for i in 0... min(length(vector1), length(vector2)): for (k, v) in vector2[i]: if v != vector1[i][k]: // report that k is bad for index i, // with vector2 having v, vector1 having vector1[i][k]
This works in general, but breaks horribly if vector1 has a, b, c, d and vector2 has a, b, b1, c, d (it reports a fault for b1 , c and d ). I am following an algorithm that tells me that there is an extra entry in vector2 compared to vector1 .
I think I want to do something when I came across inconsistency records, I look at the following records in the second vector, and if a match is found before the end of the second vector, keep index i record found in the second vector and go to match the next entry in the first vector, starting with vector2[i+1] .
Is there an easier way to do this? Some kind of standard algorithm that I have not come across?
I work in C ++, so C ++ solutions are welcome, but solutions in any language or pseudo-code will also be great.
Example
For arbitrary map objects: a , b , c , d , e , f and g ;
With vector1 : a , b , d , e , f
and vector2 : a , c , e , f
I need an algorithm that tells me:
Extra b at index 1 of vector1 and vector2 c != vector1 d .
or (I would see this as an effective equivalent result)
vector1 b != vector2 c and optional d at index 2 of vector1
Edit
I ended up using std::set_difference and then did some matching on the differences between both sets to determine which entries were similar but different, and which had entries completely missing from another vector.