468,290 Members | 2,097 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,290 developers. It's quick & easy.

Why "associative" in associative container?

set, map, multiset and multimap are all associative containers. But what
does the word "associative" have to do with these 4 containers?
Jun 25 '07 #1
5 1577
"desktop" <ff*@sss.comwrote in message
news:f5**********@news.net.uni-c.dk...
: set, map, multiset and multimap are all associative containers. But
: what does the word "associative" have to do with these 4 containers?

Good question :)

I think that the name comes from the fact that each element stored
within the container is "associated" with a key, from the element
can be retrieved.

Of course, set and multiset do not explicitly store additional data
along with the key itself - they're therefore a bit of a degenerate
case. Yet you will often seen std::set used with an element type that
stores more data than the key itself, and a custom Comparator.

--
http://ivan.vecerina.com/contact/?subject=NG_POST <- email contact form
Brainbench MVP for C++ <http://www.brainbench.com

Jun 25 '07 #2
Ivan Vecerina a écrit :
"desktop" <ff*@sss.comwrote in message
news:f5**********@news.net.uni-c.dk...
: set, map, multiset and multimap are all associative containers. But
: what does the word "associative" have to do with these 4 containers?

Good question :)

I think that the name comes from the fact that each element stored
within the container is "associated" with a key, from the element
can be retrieved.

Of course, set and multiset do not explicitly store additional data
along with the key itself - they're therefore a bit of a degenerate
case. Yet you will often seen std::set used with an element type that
stores more data than the key itself, and a custom Comparator.
In fact, for set and multiset, the element is the key itself. This is
why values are const in set and multiset. They are called Simple
Associative Containers.

For more information, see:
http://www.sgi.com/tech/stl/AssociativeContainer.html

Michael
Jun 25 '07 #3
desktop wrote:
set, map, multiset and multimap are all associative containers. But what
does the word "associative" have to do with these 4 containers?
Jun 25 '07 #4
"Michael DOUBEZ" <mi************@free.frwrote in message
news:46***********************@news.free.fr...
: Ivan Vecerina a écrit :
: "desktop" <ff*@sss.comwrote in message
: news:f5**********@news.net.uni-c.dk...
: : set, map, multiset and multimap are all associative containers.
But
: : what does the word "associative" have to do with these 4
containers?
: >
: Good question :)
: >
: I think that the name comes from the fact that each element stored
: within the container is "associated" with a key, from the element
: can be retrieved.
: >
: Of course, set and multiset do not explicitly store additional data
: along with the key itself - they're therefore a bit of a degenerate
: case. Yet you will often seen std::set used with an element type
that
: stores more data than the key itself, and a custom Comparator.
:
: In fact, for set and multiset, the element is the key itself. This is
: why values are const in set and multiset.

They are (now) required to be, athough this was not the case in the
original 1998 C++ standard, but was later debated and settled --
limiting some possible (-/mis/ab)uses of std::set and std::multiset.
For those interested:
http://www.open-std.org/jtc1/sc22/wg...fects.html#103

For instance, the current MSVC2005+SP1 still allows std::set key
modification...
--
http://ivan.vecerina.com/contact/?subject=NG_POST <- email contact form

Jun 25 '07 #5
On Jun 25, 10:26 am, desktop <f...@sss.comwrote:
set, map, multiset and multimap are all associative
containers. But what does the word "associative" have to do
with these 4 containers?
They are addressable (indexed) by content, and "associative" is
the standard technical word for that. (Long before the STL,
Perl and AWK referred to their arrays as "associative arrays".)
See e.g.: http://www.nist.gov/dads/HTML/assocarray.html.

--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

Jun 26 '07 #6

This discussion thread is closed

Replies have been disabled for this discussion.

By using this site, you agree to our Privacy Policy and Terms of Use.