Results 1 to 3 of 3

Thread: Vector Searching

Threaded View

  1. #1

    Thread Starter
    Frenzied Member Technocrat's Avatar
    Join Date
    Jan 2000
    Location
    I live in the 1s and 0s of everyones data streams
    Posts
    1,024

    Vector Searching

    I have the following structures:

    Code:
    struct UTM
    {
    	string sLID;
    	string sCanal;
    	string sStation;
    	string sOutlet;
    	string sService;
    	string sTypeCode;
    	string sSize;
    };
    
    struct LM
    {
    	string sLID;
    	string sStreetNumber;
    	string sStreet;
    	string sStreetSufix;
    };

    There are two vectors that uses those:
    vector<UTM> vecUTM105AP;
    vector<LM> vecLMBAREP;

    They both get filled using the same way as my other post . Everything in vecLMBAREP gets sorted by the sLid. Then I uses the following code to see if the vecUTM105AP sLID is in the vecLMBAREP vector.
    Code:
    struct IsSlidEqual
    {
        IsSlidEqual( const std::string &s ) : m_s(s) { }
        operator () ( const LM& obj )
        {
            return obj.sLID == m_s;
        }
    
    private:
        std::string m_s;
    };
    
    	vector<UTM>::iterator lst;
    	for (lst = vecUTM105AP.begin(); lst != vecUTM105AP.end(); lst++)
    	{
    		UTM* V;
    		V = (UTM*)(&(*lst));
    		vector<LM>::iterator it = std::find_if( vecLMBAREP.begin(), vecLMBAREP.end(), IsSlidEqual(V->sLID));
    
    		if ( it != vecLMBAREP.end())
    		{
    			iBC = atoi(V->sLID.c_str());
    		}
    This works, but the problem I have is it is slow. The vecUTM105AP vector is only ~7700 elements and the other is ~13,000 and it takes 3-4 minutes at least. Granted thats not bad considering but I am going to have another vector that is going to be 34,000 elements and waiting 10-20 minutes is going to suck. Is there a faster/better way to do this?
    Last edited by Technocrat; Mar 31st, 2003 at 07:50 PM.
    MSVS 6, .NET & .NET 2003 Pro
    I HATE MSDN with .NET & .NET 2003!!!

    Check out my sites:
    http://www.filthyhands.com
    http://www.techno-coding.com


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width