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



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

LINK TO THIS PAGE  


rating :  0   |  0


  Page 1 of 1

1

 
Topic: DEVELOP > c-Plus-Plus
User: ""
Date: 16 May 2006 12:18:36 AM
Object: Join Date: May 2006, Posts: 10 Reputation: HAOBBOY is an unknown quantity at this point (<10) Stopping Sorting Feature of Maps
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
.

User: "Earl Purple"

Title: Re: Join Date: May 2006, Posts: 10 Reputation: HAOBBOY is an unknown quantity at this point (<10) Stopping Sorting Feature of Maps 17 May 2006 04:02:56 AM
wrote:

Hello

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

User: "Mark P"

Title: Re: Join Date: May 2006, Posts: 10 Reputation: HAOBBOY is an unknownquantity at this point (<10) Stopping Sorting Feature of Maps 16 May 2006 04:58:00 PM
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

.
User: "Earl Purple"

Title: Re: Join Date: May 2006, Posts: 10 Reputation: HAOBBOY is an unknown quantity at this point (<10) Stopping Sorting Feature of Maps 17 May 2006 03:35:37 AM
Mark P wrote:

HAOBBoy@gmail.com 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).
.



  Page 1 of 1

1

 


Related Articles
 

NEWER

pg.1232     pg.940     pg.716     pg.544     pg.412     pg.311     pg.234     pg.175     pg.130     pg.96     pg.70     pg.50     pg.35     pg.24     pg.16     pg.10     pg.6     pg.3     pg.1

OLDER