dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: Implement in c++, a static map table

  1. #1
    Join Date
    May 2015
    Posts
    220

    Implement in c++, a static map table

    Hi,

    I have a scenario where the

    Code:
    typedef struct
    {
       std::string sApn;
       ApnQosMapValue eApnQosMatch;
       u8 nQci;
    }ApnQosMap_t;
    This is a struct added by me to legacy code..Now I want to have a array of such structs. Here for a apn name, depending on enum value set in eApnQosMatch, we need to use the nQci from table or use some other value.

    Please could you kindly let me know the best way to implement this ? (whether to have a map based on Apn, and change the struct to have just eApnQosMatch and nQci ?

    thanks a lot
    ~p
    Last edited by pdk5; October 22nd, 2015 at 08:51 AM.

  2. #2
    Join Date
    May 2015
    Posts
    220

    Re: Implement in c++, a static map table

    Sorry, for asking this naive question..was not clear abt the requirements..now resolved it by using map and works fine..

  3. #3
    Join Date
    Jun 2015
    Posts
    208

    Re: Implement in c++, a static map table

    Quote Originally Posted by pdk5 View Post
    Sorry, for asking this naive question..was not clear abt the requirements..now resolved it by using map and works fine..
    It's not naive. Selecting the proper data structure is a big deal.

    If you've used an std::map then accesses will be O(log N) whereas if an std::unordered_map is used they will be O(1) just like array accesses. It may not matter this time but you should be aware of the performance difference.

    Also note that std::set (and std::unordered_set) can be used as "maps" too. I often find them simpler to apply.
    Last edited by tiliavirga; October 25th, 2015 at 01:54 AM.

  4. #4
    Join Date
    May 2015
    Posts
    220

    Re: Implement in c++, a static map table

    @ tiliavirga : Thanks a lot, I will keep this in mind

  5. #5
    Join Date
    Jun 2015
    Posts
    208

    Re: Implement in c++, a static map table

    Quote Originally Posted by tiliavirga View Post
    Also note that std::set (and std::unordered_set) can be used as "maps" too. I often find them simpler to apply.
    I've posted an example of this in another thread,

    http://forums.codeguru.com/showthrea...atic-to-vector

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)