Thread: Unsorted Map and Multimap :: STL

  1. #1
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348

    Unsorted Map and Multimap :: STL

    Hi.

    Is it possible to have an unsorted map and/or multimap STL container? The map is an extremely useful STL container because of its key and value feature. I need to set a map container to not sort its keys, i.e. insert them if they do not exist, but in a queue fashion as in FIFO.

    Thanks,
    Kuphryn

  2. #2
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    Well since you can have your own comparitive function I'm thinking it may be possible. It may be considered a "hack" but I may have something. Let me mess around with it for a minute and I'll post it if I get it working. If not, I'll go and hide in the shadows.

    EDIT: Yeah its looking pretty rough. On second thought I do not think it is possible simply by the nature in which STL stores its data. It puts everything into a RED/BLACK tree. This is by definition a binary search tree. Also, R/B trees are used to represent 2-3-4 trees. This having been said, I don't think it would hold up under a FIFO data structure. I think you would be best off writing your own hash-table to tailor to your needs. Perhaps it is possible with the STL but I do not know how. Sorry.
    Last edited by MrWizard; 12-21-2002 at 04:23 PM.

  3. #3
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793
    If what you are really looking for is a queue, then create a class and inherit from std::queue...the queue can hold the pairs you want.....and you can create functions in your class to give you the functionality you want

  4. #4
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348
    Okay. Thanks.

    Tim Smith and Christian Graus mentioned something about std:air and containers suchs as a deque.

    http://www.codeproject.com/script/co...486#xx372483xx

    I did not know std:air can work in other STL containers besides the map.

    Kuphryn

  5. #5
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    pairs meet the requirements for all containers not just maps. If a map doesnt suit your needs then use something else. deque and vector are my favorite containers because they have random access iterators and so allow you to use all the algorithms.
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  6. #6
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348
    Okay. Thanks.

    Kuphryn

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Map
    By dpp in forum C++ Programming
    Replies: 4
    Last Post: 05-22-2009, 11:29 PM
  2. Problems defining classes
    By esmeco in forum C++ Programming
    Replies: 47
    Last Post: 10-24-2007, 01:13 PM
  3. STL multimap error
    By 7stud in forum C++ Programming
    Replies: 12
    Last Post: 11-23-2005, 12:48 AM
  4. Hash_map, STL maps query
    By alvifarooq in forum C++ Programming
    Replies: 15
    Last Post: 06-07-2005, 09:07 AM
  5. STL thread safety
    By Hunter2 in forum C++ Programming
    Replies: 4
    Last Post: 10-06-2004, 08:09 PM