what kind of search is recommended???
-
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
-
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
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
-
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
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????
-
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????
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
-
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
-
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
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