Thread: alternative map class template

  1. #1
    Registered User
    Join Date
    May 2012
    Posts
    2

    alternative map class template

    Hi, i'm looking for an alternative, not so complex (very simple) version of the std::map (map - C++ Reference) class template. (for study) Can somebody point me to the right direction? Thanks in advance, pumi

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Well you could try implementing your own version.

    Start with
    Code:
    struct elem { int key, int value };
    vector<elem> map;
    It won't be as efficient as the standard implementation, but you should be able to explore all the concepts (and implement the API).
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    May 2012
    Posts
    2
    thank you, i'm sure it won't be as efficient do you know any "already ready" alternatives?

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    I thought you wanted a "very simple" one to "study"?

    "efficient" implementations are always going to be "complicated" and not something you could "study" in a short time frame.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  5. #5
    [](){}(); manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    *nullptr
    Posts
    2,657
    AFAIK
    std::map is a binary search tree abstracted away under that nice interface.
    If you're familiar with trees, implementing one yourself would be educational.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 3
    Last Post: 01-30-2011, 04:28 PM
  2. Template class nested in template class
    By yahn in forum C++ Programming
    Replies: 7
    Last Post: 04-18-2009, 11:40 AM
  3. Replies: 4
    Last Post: 11-01-2006, 02:23 PM
  4. Template <class T1, class T2, class T3> error LNK2019
    By JonAntoine in forum C++ Programming
    Replies: 9
    Last Post: 10-11-2004, 12:25 PM