Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3311140
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T21:50:31+00:00 2026-05-17T21:50:31+00:00

I am trying to find the most efficient, optimized and fastest way to compare

  • 0

I am trying to find the most efficient, optimized and fastest way to compare to std vectors of CString. the strings in question are case-sensitive. I have tried using the == operator for the vector container but this sometimes return false positives. I mean for instance if one vector contains elements in the order (a,b,c) and the other has them in the order (b,c,a) the == operator will return false even thought they share the same data. Another thing is that it does not do case sensitive comparison.

I have thought of using a basic nested loops approach like this:

//Not Tested

BOOL bMatch = TRUE;
for(int i=0; i<Vec1.size();i++)
{
  if(!bMatch)
     break;
  int nComp=0;
  for(int j=0;j<Vec2.size();j++)
  {
     if(vec1[i].CompareNoCase(Vec2[j])==0)
        {
          //We have a match--check next item
          break;
        }
     else
        {
          nComp++;
          if(nComp == Vec2.size()-1)
             {
                 //Reached end of vector and no match found
                 //Vectors don't match
                 bMatch=FALSE;
             }
        }

  }
}

The above code is not tested and I am not sure if there is probably a better way to achieve such comparison without the need of using nested loops.

Would appreciate any advice or help…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T21:50:31+00:00Added an answer on May 17, 2026 at 9:50 pm

    if one vector contains elements in the order (a,b,c) and the other has them in the order (b,c,a) the == operator will return false even thought they share the same data.

    Simply insert the data into two containers where the order does not matter and compare those:

    std::vector<CString> vec1;
    std::vector<CString> vec2;
    
    // ...
    
    std::multiset<CString> set1(vec1.begin(), vec1.end());
    std::multiset<CString> set2(vec2.begin(), vec2.end());
    
    bool equal_data = (set1 == set2);
    

    If you want to ignore the case (which the code in your question seems to suggest), you can parameterize std::multiset and std::equal with an appropriate comparator:

    struct compareNoCase
    {
        bool operator()(const CString& a, const CString& b)
        {
            return a.CompareNoCase(b);
        }
    };
    
    std::vector<CString> vec1;
    std::vector<CString> vec2;
    
    // ...
    
    std::multiset<CString> set1(vec1.begin(), vec1.end(), compareNoCase());
    std::multiset<CString> set2(vec2.begin(), vec2.end(), compareNoCase());
    
    bool equal_data = std::equal(set1.begin(), set1.end(),
                                 set2.begin(),
                                 compareNoCase());
    

    The parameterization of std::multiset guarantees that “hello” and “HELLO” in the same vector are treated as one value, and the parameterization of std::equal guarantees this across the two vectors.

    And finally, if you know that no element occurs twice in the same vector, you can use set instead of multiset. Note that it’s probably better to work with a set or multiset right from the start.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to find the fastest/most efficient way to extract the average value from
I am trying to find the fastest and most efficient way to calculate slopes
I'm trying to find out the most efficient (best performance) way to check date
I'm trying to find the most efficient way to determine if a table row
I'm trying to find the most efficient way to alpha blend in SDL. I
I'm trying to find the most efficient way to get all objects from the
I am trying to find the most efficient way to get the most recent
I am trying to find the best way (most efficient way) to return large
I'm trying to develop a genetic algorithm that will find the most efficient way
I'm trying to find the most efficient way to do something and would appreciate

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.