Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. what kind of search is recommended???

what kind of search is recommended???

Scheduled Pinned Locked Moved C / C++ / MFC
c++tutorialquestionhardware
6 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    pblais
    wrote on last edited by
    #1

    I have to do what, seems to me, is a binary search. I have different hardware modules "out on the buss" each with its own unique 17 character ascii serial number. Initially, I don't know each's serial number and until I do, I can't communicate with them. I am going to scale down my example to 3 modules each with a 4 character wide alphanumeric (in real life each character can be any of the printable ascii characters)serial number. Here would be the 3 units and their serial numbers.. Module # Serial # 1 ABG5 2 ABN4 3 BFT9 The way the hardware and software interface works is like this. If I ask for any serial number starting with 'A', I will get a reply.. But I don't know how many yet. If I ask for any serial number starting with 'B', the same holds true. If I ask for any serial number starting with any other character other than 'A' or 'B', I don't get "a hit". Now, I can eliminate any serial numbers that don't start with the letters 'A' or 'B' Now, I ask for serial numbers starting with 'AA' through 'AZ...A9' and get "hits" for 'AB' only. I also run through any serial numbers starting with 'BA' through 'BZ...B9' and get one "hit" for 'BF' This time, I eliminate anything that doesn't start with 'AB' or 'BF' Each time I get "a hit" I don't know how many. Until I "drill" my way down through all four characters. At some point I will have only "one hit" for each of the serial numbers. Nowwwwwwwwwwwwwwwwwwwwww.... How can I do this in Visual C++????? As I mentioned above, I think this would be a binary search. But I am having a hard time figuring out how to "keep score" of the "non-hits" so that I don't waste time trying those on future iterations. Keeping in mind that each serial number is 17 characters wide and can be made up of any of the 95 printable ascii characters Are there any code snippets that I can "stitch" together to do this.... Thank you in advance Pierre

    W P 2 Replies Last reply
    0
    • P pblais

      I have to do what, seems to me, is a binary search. I have different hardware modules "out on the buss" each with its own unique 17 character ascii serial number. Initially, I don't know each's serial number and until I do, I can't communicate with them. I am going to scale down my example to 3 modules each with a 4 character wide alphanumeric (in real life each character can be any of the printable ascii characters)serial number. Here would be the 3 units and their serial numbers.. Module # Serial # 1 ABG5 2 ABN4 3 BFT9 The way the hardware and software interface works is like this. If I ask for any serial number starting with 'A', I will get a reply.. But I don't know how many yet. If I ask for any serial number starting with 'B', the same holds true. If I ask for any serial number starting with any other character other than 'A' or 'B', I don't get "a hit". Now, I can eliminate any serial numbers that don't start with the letters 'A' or 'B' Now, I ask for serial numbers starting with 'AA' through 'AZ...A9' and get "hits" for 'AB' only. I also run through any serial numbers starting with 'BA' through 'BZ...B9' and get one "hit" for 'BF' This time, I eliminate anything that doesn't start with 'AB' or 'BF' Each time I get "a hit" I don't know how many. Until I "drill" my way down through all four characters. At some point I will have only "one hit" for each of the serial numbers. Nowwwwwwwwwwwwwwwwwwwwww.... How can I do this in Visual C++????? As I mentioned above, I think this would be a binary search. But I am having a hard time figuring out how to "keep score" of the "non-hits" so that I don't waste time trying those on future iterations. Keeping in mind that each serial number is 17 characters wide and can be made up of any of the 95 printable ascii characters Are there any code snippets that I can "stitch" together to do this.... Thank you in advance Pierre

      W Offline
      W Offline
      Waldermort
      wrote on last edited by
      #2

      Sounds to me like a binary tree would do what you want. Once you have found the first node, starting with the letter "A", use that node then to find the next highest, either "B" or "AD".

      Waldermort

      P 1 Reply Last reply
      0
      • W Waldermort

        Sounds to me like a binary tree would do what you want. Once you have found the first node, starting with the letter "A", use that node then to find the next highest, either "B" or "AD".

        Waldermort

        P Offline
        P Offline
        pblais
        wrote on last edited by
        #3

        WalderMort wrote:

        Sounds to me like a binary tree would do what you want. Once you have found the first node, starting with the letter "A", use that node then to find the next highest, either "B" or "AD".

        The more I look at this the more I am no so sure that this is a binary-tree search. A binary-tree search implies that the tree exists and you are searching through it. In my application, I don't think the tree exists. I am creating it right????

        W 1 Reply Last reply
        0
        • P pblais

          WalderMort wrote:

          Sounds to me like a binary tree would do what you want. Once you have found the first node, starting with the letter "A", use that node then to find the next highest, either "B" or "AD".

          The more I look at this the more I am no so sure that this is a binary-tree search. A binary-tree search implies that the tree exists and you are searching through it. In my application, I don't think the tree exists. I am creating it right????

          W Offline
          W Offline
          Waldermort
          wrote on last edited by
          #4

          I re-read you origional post and realized that my reply may have been a little wrong. From what I understand you are applying a brute force attack on the driver to gather the serial numbers? I would suggest you create a function which given a string will append the characters A-9 and call your driver. If you get a hit, call your function again with the new string ( complete with appended character ). This is a similar way to how files are found on a drive. Something like this: void RecurseSearch( LPTSTR szID ) { TCHAR szSearch[ 128 ]; // append the characters one at a time ( do this in a loop ) _tcscpy( szSearch, szID ); _tcscat( szID, "A" ); // check if its a hit if ( SomeUnknowFunction( szIdSearch ) ) { // Call again until max length is achieved and it's a hit RecurseSearch( szSearch ); } }

          Waldermort

          P 1 Reply Last reply
          0
          • W Waldermort

            I re-read you origional post and realized that my reply may have been a little wrong. From what I understand you are applying a brute force attack on the driver to gather the serial numbers? I would suggest you create a function which given a string will append the characters A-9 and call your driver. If you get a hit, call your function again with the new string ( complete with appended character ). This is a similar way to how files are found on a drive. Something like this: void RecurseSearch( LPTSTR szID ) { TCHAR szSearch[ 128 ]; // append the characters one at a time ( do this in a loop ) _tcscpy( szSearch, szID ); _tcscat( szID, "A" ); // check if its a hit if ( SomeUnknowFunction( szIdSearch ) ) { // Call again until max length is achieved and it's a hit RecurseSearch( szSearch ); } }

            Waldermort

            P Offline
            P Offline
            pblais
            wrote on last edited by
            #5

            Exactly what I am looking for... Something that "finds" filenames YESSSSSSSSSS

            1 Reply Last reply
            0
            • P pblais

              I have to do what, seems to me, is a binary search. I have different hardware modules "out on the buss" each with its own unique 17 character ascii serial number. Initially, I don't know each's serial number and until I do, I can't communicate with them. I am going to scale down my example to 3 modules each with a 4 character wide alphanumeric (in real life each character can be any of the printable ascii characters)serial number. Here would be the 3 units and their serial numbers.. Module # Serial # 1 ABG5 2 ABN4 3 BFT9 The way the hardware and software interface works is like this. If I ask for any serial number starting with 'A', I will get a reply.. But I don't know how many yet. If I ask for any serial number starting with 'B', the same holds true. If I ask for any serial number starting with any other character other than 'A' or 'B', I don't get "a hit". Now, I can eliminate any serial numbers that don't start with the letters 'A' or 'B' Now, I ask for serial numbers starting with 'AA' through 'AZ...A9' and get "hits" for 'AB' only. I also run through any serial numbers starting with 'BA' through 'BZ...B9' and get one "hit" for 'BF' This time, I eliminate anything that doesn't start with 'AB' or 'BF' Each time I get "a hit" I don't know how many. Until I "drill" my way down through all four characters. At some point I will have only "one hit" for each of the serial numbers. Nowwwwwwwwwwwwwwwwwwwwww.... How can I do this in Visual C++????? As I mentioned above, I think this would be a binary search. But I am having a hard time figuring out how to "keep score" of the "non-hits" so that I don't waste time trying those on future iterations. Keeping in mind that each serial number is 17 characters wide and can be made up of any of the 95 printable ascii characters Are there any code snippets that I can "stitch" together to do this.... Thank you in advance Pierre

              P Offline
              P Offline
              pblais
              wrote on last edited by
              #6

              Welllllllllll I got side-tracked and now I am finally getting back to this. I was able to use a kind-of brute force recursive search. Using my example, it goes through and finds ABG5. I have also figured out a way to keep track of that. My question now is, how can I have it remember to go back and continue searching from ABxx to find ABN4 and eventually BFT9? Thanks in advance Pierre

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups