Results 1 to 16 of 16

Thread: hash_multimap

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,371
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: hash_multimap

    You can always use a standard hash and keep there not single items, but lists of items. Something like: std::hash_map<std::list<Item> >

    BTW. Are you sure hash_multimap is not available (I know it's not part of the standard, but for instance my system supports it)?
    http://www.sgi.com/tech/stl/hash_multimap.html

  2. #2
    Join Date
    Feb 2006
    Posts
    91
    Thanks
    4
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: hash_multimap


    BTW. Are you sure hash_multimap is not available (I know it's not part of the standard, but for instance my system supports it)?
    yes I think both g++ and VC++ has support for multimap but the usage varies. I needed something that would compile for both the compilers.
    However, map and multimap should suffice my needs at the moment with O(logn) time complexity. I had mistakenly taken the time complexity of STL's map as O(n)..I was so wrong.. O (log n) is still fast..
    Humans make mistake because there is really NO patch for HUMAN STUPIDITY

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,371
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: hash_multimap

    STL on Linux is different than STL on Windows - these are completely different implementations, so you'll have differences in all other classes as well (probably including std::vector). The API should be the same on both platforms.

  4. #4
    Join Date
    Feb 2006
    Posts
    91
    Thanks
    4
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: hash_multimap

    Wow, you are right. The API of both g++ and vc++ is same; just have to insert the required headers. I have the same program working for both g++ and vc++ 2005 right now.
    Here is the code:

    Qt Code:
    1. //VC++
    2. #include<iostream>
    3. #include<cstdio>
    4. #include<hash_map>
    5. using namespace std;
    6. using namespace stdext;
    7. int main(int argc,char** argv)
    8. {
    9. hash_map<int,int> mapping;
    10. hash_map<int,int>::const_iterator miter;
    11.  
    12. mapping.insert(pair<int,int>(1,100));
    13. mapping.insert(pair<int,int>(2,200));
    14. miter = mapping.find(1);
    15.  
    16. if(miter == mapping.end())
    17. cout << "Not found";
    18. else
    19. cout << miter->first << " = " << miter->second;
    20.  
    21.  
    22. getchar();
    23. return 0;
    24. }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. //g++
    2. #include<iostream>
    3. #include<cstdio>
    4. #include<ext/hash_map>
    5. using namespace std;
    6. using namespace __gnu_cxx;
    7. int main(int argc,char** argv)
    8. {
    9. hash_map<int,int> mapping;
    10. hash_map<int,int>::const_iterator miter;
    11.  
    12. mapping.insert(pair<int,int>(1,100));
    13. mapping.insert(pair<int,int>(2,200));
    14. miter = mapping.find(1);
    15.  
    16. if(miter == mapping.end())
    17. cout << "Not found";
    18. else
    19. cout << miter->first << " = " << miter->second;
    20.  
    21.  
    22. getchar();
    23. return 0;
    24. }
    To copy to clipboard, switch view to plain text mode 

    However I am running into some problem with hash_map<string,string> for both the compilers. I am sure there is some compare function that needs to be defined for strings or is there something already available ?
    Humans make mistake because there is really NO patch for HUMAN STUPIDITY

  5. #5
    Join Date
    Feb 2006
    Posts
    91
    Thanks
    4
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: hash_multimap

    BTW, how can I combine both these files into one so that both the compilers can compile it. Is there some flag that needs to be checked to find out if the compiler is VC++ or g++ ?
    Humans make mistake because there is really NO patch for HUMAN STUPIDITY

  6. #6
    Join Date
    Oct 2006
    Posts
    279
    Thanks
    6
    Thanked 40 Times in 39 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: hash_multimap

    Qt Code:
    1. #ifdef Q_CC_MSVC
    2. #include<hash_map>
    3. using namespace stdext;
    4. #endif
    5.  
    6. #ifdef Q_CC_GNU
    7. #include<ext/hash_map>
    8. using namespace __gnu_cxx;
    9. #endif
    To copy to clipboard, switch view to plain text mode 

  7. #7
    Join Date
    Feb 2006
    Posts
    91
    Thanks
    4
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: hash_multimap

    Quote Originally Posted by spud View Post
    Qt Code:
    1. #ifdef Q_CC_MSVC
    2. #include<hash_map>
    3. using namespace stdext;
    4. #endif
    5.  
    6. #ifdef Q_CC_GNU
    7. #include<ext/hash_map>
    8. using namespace __gnu_cxx;
    9. #endif
    To copy to clipboard, switch view to plain text mode 

    That certainly didn't work. Is that some QT preprocessor that does the same thing? I opened up the glut.h file and saw how they have done it so I got upto here.

    Qt Code:
    1. #include<iostream>
    2. #include<cstdio>
    3.  
    4. #if defined(__MINGW32__)
    5. #include<ext/hash_map>
    6. using namespace __gnu_cxx;
    7. #endif
    8.  
    9. #if defined(_MSC_VER)
    10. #include<hash_map>
    11. using namespace stdext;
    12. #endif
    13.  
    14. #include<iostream>
    15. #include<cstdio>
    16.  
    17. using namespace std;
    18.  
    19. int main(int argc,char** argv)
    20. {
    21. hash_map<int,int> mapping;
    22. hash_map<int,int>::const_iterator miter;
    23.  
    24. mapping.insert(pair<int,int>(1,100));
    25. mapping.insert(pair<int,int>(2,200));
    26. miter = mapping.find(1);
    27.  
    28. if(miter == mapping.end())
    29. cout << "Not found";
    30. else
    31. cout << miter->first << " = " << miter->second;
    32.  
    33.  
    34. getchar();
    35. return 0;
    36. }
    To copy to clipboard, switch view to plain text mode 
    The preprocessors have always confused me a bit. Is there a list of all the preprocessors that can be used (at least the more common ones ). Can anyone point to some good resource about types of general preprocessors or may be list some common ones out here ?
    Humans make mistake because there is really NO patch for HUMAN STUPIDITY

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.