ºÝºÝߣ

ºÝºÝߣShare a Scribd company logo
Boost.multi_index

              ???
     Twitter : @jacking75
 E-mail : jacking75@gmail.com

                  ?? : ??? ?? ??? ??
                  ?? : ???
multi_index
 multi : ???
 index : ??
class Character
{                       Key
   INT32 m_nCharID;       Key
   wstring m_strName;

     INT16 nLevel;
     INT32 nMoney;
     .....
};
std::map<INT32, Character> m_CharSetByCharID
std::map<wstring, Character> m_CharSetByName


m_CharSetByCharID.insert
m_CharSetByName.insert


m_CharSetByName.erase
m_CharSetByCharID.erase
struct Character          std::map<INT32, Character> m_CharSetByCharID
{
   INT32 nCharID;         std::map<wstring, Character> m_CharSetByName
   wstring strName;

     INT16 nLevel;        m_CharSetByCharID.insert
     INT32 nMoney;        m_CharSetByName.insert
     .....
};
                          m_CharSetByName.erase
                          m_CharSetByCharID.erase




         Key? 2???? ? ? ??? ??? ????

         ??? m_CharSetByCharID ? m_CharSetByName ?
         ??? ??? ???, ?? ??? ??? ???
SDC 3rd ???? - Boost.multi_index ????
multi_index
SDC 3rd ???? - Boost.multi_index ????
Boost.multi_index
??? ??                      ??? ID? ??

                                                                            ??? ???? ??
// ????? ?? ??
typedef boost::multi_index::member<Character, int, &Character::m_nCharID> IDX_CHARID;
typedef boost::multi_index::member<Character, std::wstring, &Character::m_strName> IDX_NAME;

// ??? ??? ??
typedef struct indices : public boost::multi_index::indexed_by
             <
                           boost::multi_index::hashed_unique<IDX_CHARID>
                           , boost::multi_index::hashed_unique<IDX_NAME>
             >
{
             enum INDEX
             {
                           IDX_UNIQUE_CHARID                      =0
                           , IDX_UNIQUE_NAME
                           , IDX_END
             };
} INDICES;
???? ??


                  type                         specifier
                                        ordered_unique
                              ordered
                                        ordered_non_unique
  key-based
                                        hashed_unique
                              hashed
                                        hashed_non_unique
                                        sequenced
              non key-based
                                        random_access
??? ??


                       ??             ??              ??
 ordered_unique       O(log N)        O(1)        set, multiset,
 ordered_non_unique                              map, multimap
 hashed_unique          O(1)          O(1)       unordered_set,
 hashed_non_unique                               unordered_map
 sequenced              O(1)          O(1)             list
 random_access          O(1)     O(?? ?? ?? ?)       vector
????
<boost/multi_index_container.hpp>              multi_index_container? ????
                                              ???

                                               set?? map? ?? ???? ???? ????
<boost/multi_index/ordered_index.hpp>
                                               ordered_unique, ordered_non_unique

                                               ?? ?? ?? ???? ????
<boost/multi_index/hashed_index.hpp>
                                               hashed_unique, hashed_non_unique

                                               list? ?? ?? ?? ???? ???? ????
<boost/multi_index/sequenced_index.hpp>
                                               sequenced

                                               vector? ?? ?? ??? ??? ???? ????
<boost/multi_index/random_access_index.hpp>
                                               random_access

                                          ?? ??

<boost/multi_index/key_extractors.hpp>         ??? ?? ?? ??? ????

<boost/multi_index/identity.hpp>               ??? ???(????)?? ???? ?? ??

<boost/multi_index/member>                     ??? ?? ??? ???? ??? ??

<boost/multi_index/mem_fun.hpp>                ??? ?? ??? ???? ??? ??

<boost/multi_index/global_fun.hpp>             ?? ??? ???? ??? ??

<boost/multi_index/composite_key.hpp>          ??? ???? ???? ?? ??
template<
   typename Value,
   typename
IndexSpecifierList=indexed_by<ordered_unique<identity<Value> > >,
   typename Allocator=std::allocator<Value>
>
class multi_index_container;
Key ??


?   identity
?   member
?   const_mem_fun
?   mem_fun
?   global_fun
?   composite_key
Demo
? Tutorial 1
  std::list && std::multiset

? Tutorial 2
  std::vector && std::multiset

? Tutorial 3
  ??? UP!
? Tutorial 4
  ?? ??? ?? ??

? Tutorial 5
  ?? ??? ?? && ?? ?? ? && ?? ? &&
  bound

? Tutorial 6
  ?? ??? ?? && std::multiset && std::map
? Tutorial 7
  replace

? Tutorial 8
  modify

? Tutorial 9
  member_offset
SDC 3rd ???? - Boost.multi_index ????
?? ??
http://www.boost.org/doc/libs/1_47_0/libs/multi_index/doc/

?? ??
(??)http://www24.atwiki.jp/reisiki/pages/59.html

More Related Content

SDC 3rd ???? - Boost.multi_index ????

  • 1. Boost.multi_index ??? Twitter : @jacking75 E-mail : jacking75@gmail.com ?? : ??? ?? ??? ?? ?? : ???
  • 2. multi_index multi : ??? index : ??
  • 3. class Character { Key INT32 m_nCharID; Key wstring m_strName; INT16 nLevel; INT32 nMoney; ..... };
  • 4. std::map<INT32, Character> m_CharSetByCharID std::map<wstring, Character> m_CharSetByName m_CharSetByCharID.insert m_CharSetByName.insert m_CharSetByName.erase m_CharSetByCharID.erase
  • 5. struct Character std::map<INT32, Character> m_CharSetByCharID { INT32 nCharID; std::map<wstring, Character> m_CharSetByName wstring strName; INT16 nLevel; m_CharSetByCharID.insert INT32 nMoney; m_CharSetByName.insert ..... }; m_CharSetByName.erase m_CharSetByCharID.erase Key? 2???? ? ? ??? ??? ???? ??? m_CharSetByCharID ? m_CharSetByName ? ??? ??? ???, ?? ??? ??? ???
  • 10. ??? ?? ??? ID? ?? ??? ???? ?? // ????? ?? ?? typedef boost::multi_index::member<Character, int, &Character::m_nCharID> IDX_CHARID; typedef boost::multi_index::member<Character, std::wstring, &Character::m_strName> IDX_NAME; // ??? ??? ?? typedef struct indices : public boost::multi_index::indexed_by < boost::multi_index::hashed_unique<IDX_CHARID> , boost::multi_index::hashed_unique<IDX_NAME> > { enum INDEX { IDX_UNIQUE_CHARID =0 , IDX_UNIQUE_NAME , IDX_END }; } INDICES;
  • 11. ???? ?? type specifier ordered_unique ordered ordered_non_unique key-based hashed_unique hashed hashed_non_unique sequenced non key-based random_access
  • 12. ??? ?? ?? ?? ?? ordered_unique O(log N) O(1) set, multiset, ordered_non_unique map, multimap hashed_unique O(1) O(1) unordered_set, hashed_non_unique unordered_map sequenced O(1) O(1) list random_access O(1) O(?? ?? ?? ?) vector
  • 13. ???? <boost/multi_index_container.hpp> multi_index_container? ???? ??? set?? map? ?? ???? ???? ???? <boost/multi_index/ordered_index.hpp> ordered_unique, ordered_non_unique ?? ?? ?? ???? ???? <boost/multi_index/hashed_index.hpp> hashed_unique, hashed_non_unique list? ?? ?? ?? ???? ???? ???? <boost/multi_index/sequenced_index.hpp> sequenced vector? ?? ?? ??? ??? ???? ???? <boost/multi_index/random_access_index.hpp> random_access ?? ?? <boost/multi_index/key_extractors.hpp> ??? ?? ?? ??? ???? <boost/multi_index/identity.hpp> ??? ???(????)?? ???? ?? ?? <boost/multi_index/member> ??? ?? ??? ???? ??? ?? <boost/multi_index/mem_fun.hpp> ??? ?? ??? ???? ??? ?? <boost/multi_index/global_fun.hpp> ?? ??? ???? ??? ?? <boost/multi_index/composite_key.hpp> ??? ???? ???? ?? ??
  • 14. template< typename Value, typename IndexSpecifierList=indexed_by<ordered_unique<identity<Value> > >, typename Allocator=std::allocator<Value> > class multi_index_container;
  • 15. Key ?? ? identity ? member ? const_mem_fun ? mem_fun ? global_fun ? composite_key
  • 16. Demo
  • 17. ? Tutorial 1 std::list && std::multiset ? Tutorial 2 std::vector && std::multiset ? Tutorial 3 ??? UP!
  • 18. ? Tutorial 4 ?? ??? ?? ?? ? Tutorial 5 ?? ??? ?? && ?? ?? ? && ?? ? && bound ? Tutorial 6 ?? ??? ?? && std::multiset && std::map
  • 19. ? Tutorial 7 replace ? Tutorial 8 modify ? Tutorial 9 member_offset