Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Join Date: May 2006, Posts: 10 Reputation: HAOBBOY is an unknown quantity at this point (<10) Stopping Sorting Feature of Maps

Reply
Thread Tools

Join Date: May 2006, Posts: 10 Reputation: HAOBBOY is an unknown quantity at this point (<10) Stopping Sorting Feature of Maps

 
 
HAOBBoy@gmail.com
Guest
Posts: n/a
 
      05-16-2006
Hello

I am using a MAP as an associative array. The map automatically sorts
by key. How can I stop this feature. I will may value as FIFO. I mean
if I have the keys

Key=value

SSN=000-00-0000
Name=JAA
Age=66

When I iterate through the map I don't want may data to print as

Age
NAME
SSN

I want it to be as is:
SSN
NAME
AGE

 
Reply With Quote
 
 
 
 
Mark P
Guest
Posts: n/a
 
      05-16-2006
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> Hello
>
> I am using a MAP as an associative array. The map automatically sorts
> by key. How can I stop this feature. I will may value as FIFO.


You can't. That's what a map does. If you don't want this feature, use
something that isn't sorted. std:vector and std::list would each work
find for your apparent purposes. You'll need to make your own datatype
to hold the key-value pairings.

Mark


> I mean
> if I have the keys
>
> Key=value
>
> SSN=000-00-0000
> Name=JAA
> Age=66
>
> When I iterate through the map I don't want may data to print as
>
> Age
> NAME
> SSN
>
> I want it to be as is:
> SSN
> NAME
> AGE
>

 
Reply With Quote
 
 
 
 
Earl Purple
Guest
Posts: n/a
 
      05-17-2006

Mark P wrote:
> (E-Mail Removed) wrote:


> > Hello
> >
> > I am using a MAP as an associative array. The map automatically sorts
> > by key. How can I stop this feature. I will may value as FIFO.

>
> You can't. That's what a map does. If you don't want this feature, use
> something that isn't sorted. std:vector and std::list would each work
> find for your apparent purposes. You'll need to make your own datatype
> to hold the key-value pairings.
>
> Mark


To maintain order and also have a fast lookup, you need to create an
index and there is a boost library that will do that, although if you
just want one index, it's easy enough to implement your own.

Just have the vector in the regular order, and a map from keys to the
addresses of elements in the vector (safe as long as the vector is
built once then subsequently only referenced). Alternatively you can
have map from key to the position (index) within the vector. (map<K,
std::vector<T>::size_type > where T is your type and K is your key
type).

 
Reply With Quote
 
Earl Purple
Guest
Posts: n/a
 
      05-17-2006

(E-Mail Removed) wrote:
> Hello
>

You seem to have copied and pasted the title of this post from
codeguru.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Share-Point-2010 ,Share-Point -2010 Training , Share-point-2010Hyderabad , Share-point-2010 Institute Saraswati lakki ASP .Net 0 01-06-2012 06:39 AM
MSN maps vs. Google maps Ralph Fox NZ Computing 0 07-30-2007 10:30 AM
Scenario 5: IS-IS routing on Frame Relay Multi-point and Point-to-Point David Sudjiman Cisco 0 06-08-2006 09:11 AM
STL: Map of maps possible, but no multi-map of maps? Workarounds? Marcus C++ 2 12-09-2005 06:34 AM
std::maps within std::maps -- optimisation Simon Elliott C++ 4 03-10-2005 10:11 AM



Advertisments