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. Managed C++/CLI
  4. Fatest Way Around

Fatest Way Around

Scheduled Pinned Locked Moved Managed C++/CLI
helpquestiondatabasetutorial
11 Posts 2 Posters 31 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.
  • S Sidney

    Hi everyone, I need advice regardin my problem, here's my problem: I have a Text File(serves as my database) with 3 colums fixed length, example Name Address Age AAA 123 Anywhere 12 BBB .... ... Joseph 345 Somewhere 15 Rosie 098 Cool DC 20 I need to search this Text File, in the real world this Text File migh contain 1 Million records as soon as we populate our database. My question is... what is the fastest way to search for a particular string in this text file. Note: I only search for the name, If I find the name... I need to get the enrite line and process it. I will really appreciate any help that you can give me. Thanks/Regards Sidney

    A Offline
    A Offline
    Alexandru Savescu
    wrote on last edited by
    #2

    I will give you a fast, but memeory consuming solution. Use a std::map to store the name as keys and you make a struct to store the address. Read the whole file and fill the map. Then, when you search the name you will use std::map::find that will do a binary search. At the end of the program you iterate through the map and write it to the file. If you have multiple entries with the same name you may consider multimap. Since you post it to the Manage C++ you may also consider hash_map. Best regards, Alexandru Savescu

    S 2 Replies Last reply
    0
    • S Sidney

      Thanks Alexandru! I'll see if I can do this, do you have sample code that used STL Map? if you have would you be so kind to share it with me? And by the way just for info... the fields are of Fixed length, example Field Name Position Length Fld1 1 10 Fld2 11 21 etc... Thanks/Regards Sidney

      A Offline
      A Offline
      Alexandru Savescu
      wrote on last edited by
      #3

      You can look at the article on CP about STL here. Also you can read MSDN (the one that comes with .NET is nicer than the VC6.0's one), or the SGI documentation. Best regards, Alexandru Savescu

      S 1 Reply Last reply
      0
      • A Alexandru Savescu

        I will give you a fast, but memeory consuming solution. Use a std::map to store the name as keys and you make a struct to store the address. Read the whole file and fill the map. Then, when you search the name you will use std::map::find that will do a binary search. At the end of the program you iterate through the map and write it to the file. If you have multiple entries with the same name you may consider multimap. Since you post it to the Manage C++ you may also consider hash_map. Best regards, Alexandru Savescu

        S Offline
        S Offline
        Sidney
        wrote on last edited by
        #4

        Thanks Alexandru! I'll see if I can do this, do you have sample code that used STL Map? if you have would you be so kind to share it with me? And by the way just for info... the fields are of Fixed length, example Field Name Position Length Fld1 1 10 Fld2 11 21 etc... Thanks/Regards Sidney

        A 1 Reply Last reply
        0
        • A Alexandru Savescu

          I will give you a fast, but memeory consuming solution. Use a std::map to store the name as keys and you make a struct to store the address. Read the whole file and fill the map. Then, when you search the name you will use std::map::find that will do a binary search. At the end of the program you iterate through the map and write it to the file. If you have multiple entries with the same name you may consider multimap. Since you post it to the Manage C++ you may also consider hash_map. Best regards, Alexandru Savescu

          S Offline
          S Offline
          Sidney
          wrote on last edited by
          #5

          And also, I just want to make it clear... if I have same name in my name field I can use the STD::MAP? if so how can I use the multimap? and is Hash_map fast too? can I also have more info about it? Thanks/Regards Sidney

          1 Reply Last reply
          0
          • S Sidney

            Hi everyone, I need advice regardin my problem, here's my problem: I have a Text File(serves as my database) with 3 colums fixed length, example Name Address Age AAA 123 Anywhere 12 BBB .... ... Joseph 345 Somewhere 15 Rosie 098 Cool DC 20 I need to search this Text File, in the real world this Text File migh contain 1 Million records as soon as we populate our database. My question is... what is the fastest way to search for a particular string in this text file. Note: I only search for the name, If I find the name... I need to get the enrite line and process it. I will really appreciate any help that you can give me. Thanks/Regards Sidney

            S Offline
            S Offline
            Sidney
            wrote on last edited by
            #6

            Hi everyone, i tried to use the multimap(STL) but I got an error "fatal error: Cannot open include file: 'multimap' C++" I alread installed the all the files that I got from sgi... STL Version 3.3, I installed it in "C:\Program Files\Microsoft Visual Studio\VC98\Include" What could be the problem? Thanks/Regards Sidney

            A 1 Reply Last reply
            0
            • A Alexandru Savescu

              You can look at the article on CP about STL here. Also you can read MSDN (the one that comes with .NET is nicer than the VC6.0's one), or the SGI documentation. Best regards, Alexandru Savescu

              S Offline
              S Offline
              Sidney
              wrote on last edited by
              #7

              Hi Alexandru, I get an error in my code when I try to use the multimap, the error is "Cannot open include file: 'multimap' C++" can you help me? here's my code: #include #include #include using namespace std; struct ltstr { bool operator()(const char* s1, const char* s2) const { return strcmp(s1, s2) < 0; } }; int main() { multimap m; m.insert(pair("a", 1)); m.insert(pair("c", 2)); m.insert(pair("b", 3)); m.insert(pair("b", 4)); m.insert(pair("a", 5)); m.insert(pair("b", 6)); cout << "Number of elements with key a: " << m.count("a") << endl; cout << "Number of elements with key b: " << m.count("b") << endl; cout << "Number of elements with key c: " << m.count("c") << endl; cout << "Elements in m: " << endl; for (multimap::iterator it = m.begin(); it != m.end(); ++it) cout << " [" << (*it).first << ", " << (*it).second << "]" << endl; } Thanks/Regards Sidney

              A 1 Reply Last reply
              0
              • S Sidney

                Hi Alexandru, I get an error in my code when I try to use the multimap, the error is "Cannot open include file: 'multimap' C++" can you help me? here's my code: #include #include #include using namespace std; struct ltstr { bool operator()(const char* s1, const char* s2) const { return strcmp(s1, s2) < 0; } }; int main() { multimap m; m.insert(pair("a", 1)); m.insert(pair("c", 2)); m.insert(pair("b", 3)); m.insert(pair("b", 4)); m.insert(pair("a", 5)); m.insert(pair("b", 6)); cout << "Number of elements with key a: " << m.count("a") << endl; cout << "Number of elements with key b: " << m.count("b") << endl; cout << "Number of elements with key c: " << m.count("c") << endl; cout << "Elements in m: " << endl; for (multimap::iterator it = m.begin(); it != m.end(); ++it) cout << " [" << (*it).first << ", " << (*it).second << "]" << endl; } Thanks/Regards Sidney

                A Offline
                A Offline
                Alexandru Savescu
                wrote on last edited by
                #8

                Hello sidney The < and > tags were stripped by the html parser. Please send the code between <pre> and </pre> so I can see what you include and what include not. However this code sould work

                #include <multimap>
                using namespace std;
                ....

                Best regards, Alexandru Savescu

                S 1 Reply Last reply
                0
                • A Alexandru Savescu

                  Hello sidney The < and > tags were stripped by the html parser. Please send the code between <pre> and </pre> so I can see what you include and what include not. However this code sould work

                  #include <multimap>
                  using namespace std;
                  ....

                  Best regards, Alexandru Savescu

                  S Offline
                  S Offline
                  Sidney
                  wrote on last edited by
                  #9

                  Here's the code: #include #include #include using namespace std; struct ltstr { bool operator()(const char* s1, const char* s2) const { return strcmp(s1, s2) < 0; } }; int main() { multimap m; m.insert(pair("a", 1)); m.insert(pair("c", 2)); m.insert(pair("b", 3)); m.insert(pair("b", 4)); m.insert(pair("a", 5)); m.insert(pair("b", 6)); cout << "Number of elements with key a: " << m.count("a") << endl; cout << "Number of elements with key b: " << m.count("b") << endl; cout << "Number of elements with key c: " << m.count("c") << endl; cout << "Elements in m: " << endl; for (multimap::iterator it = m.begin(); it != m.end(); ++it) cout << " [" << (*it).first << ", " << (*it).second << "]" << endl; } Thanks/Regards Sidney

                  A 1 Reply Last reply
                  0
                  • S Sidney

                    Here's the code: #include #include #include using namespace std; struct ltstr { bool operator()(const char* s1, const char* s2) const { return strcmp(s1, s2) < 0; } }; int main() { multimap m; m.insert(pair("a", 1)); m.insert(pair("c", 2)); m.insert(pair("b", 3)); m.insert(pair("b", 4)); m.insert(pair("a", 5)); m.insert(pair("b", 6)); cout << "Number of elements with key a: " << m.count("a") << endl; cout << "Number of elements with key b: " << m.count("b") << endl; cout << "Number of elements with key c: " << m.count("c") << endl; cout << "Elements in m: " << endl; for (multimap::iterator it = m.begin(); it != m.end(); ++it) cout << " [" << (*it).first << ", " << (*it).second << "]" << endl; } Thanks/Regards Sidney

                    A Offline
                    A Offline
                    Alexandru Savescu
                    wrote on last edited by
                    #10

                    Well, the multimap header does not exists. Include and it will work; #include using namespace std; etc. Best regards, Alexandru Savescu

                    1 Reply Last reply
                    0
                    • S Sidney

                      Hi everyone, i tried to use the multimap(STL) but I got an error "fatal error: Cannot open include file: 'multimap' C++" I alread installed the all the files that I got from sgi... STL Version 3.3, I installed it in "C:\Program Files\Microsoft Visual Studio\VC98\Include" What could be the problem? Thanks/Regards Sidney

                      A Offline
                      A Offline
                      Alexandru Savescu
                      wrote on last edited by
                      #11

                      I think you need not replace the STL that comes with Visual C with the SGI implementation. Best regards, Alexandru Savescu

                      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