Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

A More Efficient Search

search c++ string

  • Please log in to reply
19 replies to this topic

#13 Brandon W

Brandon W

    CC Mentor

  • Expert Member
  • PipPipPipPipPipPipPipPip
  • 2092 posts
  • Location:Ipswich, Australia
  • Programming Language:C, Java
  • Learning:Java, C++, JavaScript

Posted 11 July 2012 - 08:58 PM

Since you are using C++, I would highly recommend you consider using a 'vector' if you have the option to. Then, each time you find a MAC Address that you wish to store you can simply use the vector::push_back function.

#include <vector>

/* Now to initialise your vector */
std::vector <std::string> myVector;

/* Now when you find your MAC Address */
myVector.push_back(array[i]);

If you don't know much about vectors, I recommend looking at the reference here.


If you're forced to use an array, simply create a new array of a defined size or you can malloc/realloc a new array size using the malloc() and realloc() functions respectively to add new elements. You must also create a new variable to hold the index you're up to. A good example of the latter method can be found here.
  • 0
I've returned...

#14 dargueta

dargueta

    I chown trolls.

  • Moderator
  • 4854 posts
  • Programming Language:C, Java, C++, PHP, Python, JavaScript, Perl, Assembly, Bash, Others
  • Learning:Objective-C

Posted 12 July 2012 - 10:04 AM

What's the relation of the MAC address to the user field? Can one user have more than one MAC address, can one MAC address have more than one user, or is it a one-to-one mapping?
  • 0

sudo rm -rf / && echo $'Sanitize your inputs!'


#15 jasonalien

jasonalien

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 194 posts
  • Programming Language:C, Java, C++, C#, PHP, JavaScript
  • Learning:C, Java, C++, Objective-C, C#

Posted 12 July 2012 - 10:10 AM

one MAC address can have many user name.. But user name is not important. I'm trying to collect the signal strength which is at the right of the mac address. I have no work with other data
  • 0

#16 dargueta

dargueta

    I chown trolls.

  • Moderator
  • 4854 posts
  • Programming Language:C, Java, C++, PHP, Python, JavaScript, Perl, Assembly, Bash, Others
  • Learning:Objective-C

Posted 12 July 2012 - 01:00 PM

Oh, okay. For some reason I thought you were working with user names. So it's a one-to-one mapping, right?
  • 0

sudo rm -rf / && echo $'Sanitize your inputs!'


#17 jasonalien

jasonalien

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 194 posts
  • Programming Language:C, Java, C++, C#, PHP, JavaScript
  • Learning:C, Java, C++, Objective-C, C#

Posted 12 July 2012 - 01:03 PM

I don't know if it is one-to-one but one MAC address have many signal strengths
  • 0

#18 dargueta

dargueta

    I chown trolls.

  • Moderator
  • 4854 posts
  • Programming Language:C, Java, C++, PHP, Python, JavaScript, Perl, Assembly, Bash, Others
  • Learning:Objective-C

Posted 12 July 2012 - 01:09 PM

If that's the case then I recommend you use a map, and iterate through your gazillion MAC strings, blindly pulling out the MAC addresses and their strengths, then putting them into the map. Once you're done you can check directly in the map and find those strengths in log(n) time instead of doing a bunch of checks while going in the loop.

For example, if you're searching for 100 MAC addresses in 20,000 records, with your current method the worst-case scenario is 2,000,000 comparisons for insertion alone. If you use a map, the total comparisons including insertion and lookup is at worst 140,007.
  • 1

sudo rm -rf / && echo $'Sanitize your inputs!'


#19 jasonalien

jasonalien

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 194 posts
  • Programming Language:C, Java, C++, C#, PHP, JavaScript
  • Learning:C, Java, C++, Objective-C, C#

Posted 12 July 2012 - 01:13 PM

okey, I will try that.. Thank you.
  • 0

#20 notes

notes

    CC Resident

  • Advanced Member
  • PipPipPipPip
  • 88 posts
  • Location:Poland
  • Programming Language:C++
  • Learning:Java, C#

Posted 17 July 2012 - 07:00 AM

In programming string matching algorithms are very important. Once my teacher said that good programist should have knowledge of 3 disciplines :
1. Very good knowledge of language syntax.
2. Knowledge of object oriented programming (desing patterns )
3. And knowledge of algorithmics.
As i have seen you are using string declared methods for finding desired string. I couldn't find Big O notations of algorithm used there. But I encourage to read about string matching algorithms, that could speed up searching.
http://en.wikipedia....ching_algorithm
  • 1
Remebre about KISS & DRY





Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download