Why "associative" in associative container?

D

desktop

set, map, multiset and multimap are all associative containers. But what
does the word "associative" have to do with these 4 containers?
 
I

Ivan Vecerina

: 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.
 
M

Michael DOUBEZ

Ivan Vecerina a écrit :
: 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
 
R

Ron Natalie

desktop said:
set, map, multiset and multimap are all associative containers. But what
does the word "associative" have to do with these 4 containers?
 
I

Ivan Vecerina

: Ivan Vecerina a écrit :
: > : > : 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/wg21/docs/lwg-defects.html#103

For instance, the current MSVC2005+SP1 still allows std::set key
modification...
 
J

James Kanze

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,731
Messages
2,569,432
Members
44,832
Latest member
GlennSmall

Latest Threads

Top