質問

if there a faster way to find a specific vector from list of vectors? I do vector comparison and that takes for ever to do and i have millions of records.

I'm using openmp

this is what i have so far

#pragma omp parallel for
                            for(int i=0;i<crossed.size();i++){
                                    #pragma omp flush (exit)
                                    if(!exit && (crossed[i]== vectors)){

                                            loop = i;
                                            found = true;
                                            exit = true;
                                            #pragma omp flush (exit)
                                    }
                            }

                            if(found == false){
                                    crossed.push_back(vectors);
                                    cross.push_back(0);
                            }
                            else{
                                    cross[loop] = cross[loop]+1;
                            }
役に立ちましたか?

解決

Yes, if you are willing to change your data structures a bit.

One easy way to speed up your comparisons is to use a checksum. I mean, literally check the sum. As you build the vectors, keep a running total of the sum of each one (as long as you are consistent with your data types, overflow doesn't matter). Then, instead of comparing the entire vectors, only compare the sums - then you only have compare the vectors if the sums match up.

To go even further, you can sort your vectors by checksum...This might only be worthwhile if you have a lot of vectors, since it reduces your checksum search from n to log(n)

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top