From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 4077 invoked by alias); 26 Jun 2006 17:53:49 -0000 Received: (qmail 4028 invoked by uid 22791); 26 Jun 2006 17:53:49 -0000 X-Spam-Check-By: sourceware.org Received: from maui.ebi.ac.uk (HELO maui.ebi.ac.uk) (193.62.196.100) by sourceware.org (qpsmtpd/0.31) with ESMTP; Mon, 26 Jun 2006 17:53:45 +0000 Received: from [172.22.100.132] (shoja.ebi.ac.uk [172.22.100.132]) by maui.ebi.ac.uk (8.11.7+Sun/8.11.7) with ESMTP id k5QHrg112340; Mon, 26 Jun 2006 18:53:42 +0100 (BST) Message-ID: <44A01F25.7090504@ebi.ac.uk> Date: Mon, 26 Jun 2006 17:53:00 -0000 From: Mohammad Shojatalab User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.2) Gecko/20040805 Netscape/7.2 MIME-Version: 1.0 To: Noel Yap CC: gcc-help@gcc.gnu.org Subject: Re: STL, hash_map is sorted !! References: <449FE034.4080408@ebi.ac.uk> <70d0a1130606260902j6e73ee25k66f7629e1222874d@mail.gmail.com> In-Reply-To: <70d0a1130606260902j6e73ee25k66f7629e1222874d@mail.gmail.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-EBI-Information: This email is scanned using www.mailscanner.info. X-EBI: Found to be clean X-EBI-SpamCheck: not spam, SpamAssassin (score=0, required 5) X-IsSubscribed: yes Mailing-List: contact gcc-help-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-help-owner@gcc.gnu.org X-SW-Source: 2006-06/txt/msg00228.txt.bz2 Thanks for your answers, Yes, Actually what I needed was std::vector< std::pair<> > Cheers Mo Noel Yap wrote: > By definition, hash_map is _not_ sorted and _not_ ordered. Your > example may have just lucked out. Try larger numbers. > > If you want to keep the order, use std::vector< std::pair<> > or > std::deque< std::pair<> >. If you know how many elements you'll have, > you can also try boost::array< std::pair<> >. > > HTH, > Noel > > On 6/26/06, Mohammad Shojatalab wrote: > >> Hi There, >> >> I am trying to make use of hash_map from STL, and I was assuming that >> hash_map doesn't sort the (key, value) pairs and keep the >> pairs in the order I inserted them into the hash_map. >> >> This is the simple program: >> >> #include >> >> using namespace std; >> using namespace __gnu_cxx; >> >> typedef vector cvCodes; >> typedef hash_multimap cvValues; >> >> int main() >> { >> cvCodes items; >> cvValues itemsvalues; >> cvValues::iterator pos; >> >> itemsvalues.insert(make_pair(3,"Z")); >> itemsvalues.insert(make_pair(1,"C")); >> itemsvalues.insert(make_pair(2,"A")); >> >> for (pos = itemsvalues.begin(); pos != itemsvalues.end(); pos++) >> cout << pos->first << " " << pos->second << endl; >> >> return 0; >> } >> >> I was expecting to see the following output: >> >> 3 Z >> 1 C >> 2 A >> >> but instead I get this one: >> >> 1 C >> 2 A >> 3 Z >> >> I need to use a container which keeps the order of thing as I insert >> them. >> >> Im using gcc version 4.0.2 20051125 (Red Hat 4.0.2-8) >> on Linux 2.6.14-1.1653_FC4smp >> >> I appreciate any help. >> >> Thanks >> Mohammad >> >> >>