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
| 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).
.
|
|
|
|
|

|
Related Articles |
|
|