Why "associative" in associative container?

Discussion in 'C++' started by desktop, Jun 25, 2007.

  1. desktop

    desktop Guest

    set, map, multiset and multimap are all associative containers. But what
    does the word "associative" have to do with these 4 containers?
    desktop, Jun 25, 2007
    #1
    1. Advertising

  2. "desktop" <> wrote in message
    news:f5nu6p$2hv$-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
    Ivan Vecerina, Jun 25, 2007
    #2
    1. Advertising

  3. Ivan Vecerina a écrit :
    > "desktop" <> wrote in message
    > news:f5nu6p$2hv$-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
    Michael DOUBEZ, Jun 25, 2007
    #3
  4. desktop

    Ron Natalie Guest

    desktop wrote:
    > set, map, multiset and multimap are all associative containers. But what
    > does the word "associative" have to do with these 4 containers?
    Ron Natalie, Jun 25, 2007
    #4
  5. "Michael DOUBEZ" <> wrote in message
    news:467f9654$0$19195$...
    : Ivan Vecerina a écrit :
    : > "desktop" <> wrote in message
    : > news:f5nu6p$2hv$-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/wg21/docs/lwg-defects.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
    Ivan Vecerina, Jun 25, 2007
    #5
  6. desktop

    James Kanze Guest

    On Jun 25, 10:26 am, desktop <> wrote:
    > 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:
    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
    James Kanze, Jun 26, 2007
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. T.Meitz

    associative container

    T.Meitz, Feb 16, 2004, in forum: C++
    Replies:
    2
    Views:
    371
    T.Meitz
    Feb 17, 2004
  2. Matthias =?ISO-8859-1?Q?K=E4ppler?=

    Sortable associative container?

    Matthias =?ISO-8859-1?Q?K=E4ppler?=, Dec 1, 2004, in forum: C++
    Replies:
    7
    Views:
    513
    20thCenturyBoy
    Dec 3, 2004
  3. Mr. SweatyFinger
    Replies:
    2
    Views:
    1,804
    Smokey Grindel
    Dec 2, 2006
  4. aaragon
    Replies:
    21
    Views:
    664
    Diego Martins
    Oct 17, 2006
  5. jacob navia

    An associative container

    jacob navia, Nov 17, 2009, in forum: C Programming
    Replies:
    21
    Views:
    651
    Phil Carmody
    Nov 21, 2009
Loading...

Share This Page