SlideShare ist ein Scribd-Unternehmen logo
1 von 21
Downloaden Sie, um offline zu lesen
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 중
         한쪽만 추가를 하던가, 또는 한쪽만 삭제를 한다면
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
공식 문서
http://www.boost.org/doc/libs/1_47_0/libs/multi_index/doc/

핵심 정리
(일어)http://www24.atwiki.jp/reisiki/pages/59.html

Weitere ähnliche Inhalte

Was ist angesagt?

C++ 프로젝트에 단위 테스트 도입하기
C++ 프로젝트에 단위 테스트 도입하기C++ 프로젝트에 단위 테스트 도입하기
C++ 프로젝트에 단위 테스트 도입하기OnGameServer
 
C++20 the small things - Timur Doumler
C++20 the small things - Timur DoumlerC++20 the small things - Timur Doumler
C++20 the small things - Timur Doumlercorehard_by
 
인프콘 2022 - Rust 크로스 플랫폼 프로그래밍
인프콘 2022 - Rust 크로스 플랫폼 프로그래밍인프콘 2022 - Rust 크로스 플랫폼 프로그래밍
인프콘 2022 - Rust 크로스 플랫폼 프로그래밍Chris Ohk
 
[수정본] 우아한 객체지향
[수정본] 우아한 객체지향[수정본] 우아한 객체지향
[수정본] 우아한 객체지향Young-Ho Cho
 
Ksug2015 - JPA2, JPA 기초와매핑
Ksug2015 - JPA2, JPA 기초와매핑Ksug2015 - JPA2, JPA 기초와매핑
Ksug2015 - JPA2, JPA 기초와매핑Younghan Kim
 
DDD 구현기초 (거의 Final 버전)
DDD 구현기초 (거의 Final 버전)DDD 구현기초 (거의 Final 버전)
DDD 구현기초 (거의 Final 버전)beom kyun choi
 
PHPでマルチスレッド
PHPでマルチスレッドPHPでマルチスレッド
PHPでマルチスレッドkarky7
 
Writing php extensions in golang
Writing php extensions in golangWriting php extensions in golang
Writing php extensions in golangdo_aki
 
Google Mobile Vision과 OpenCV로 card.io를 확장한 범용 카드번호인식 개발
Google Mobile Vision과 OpenCV로 card.io를 확장한 범용 카드번호인식 개발Google Mobile Vision과 OpenCV로 card.io를 확장한 범용 카드번호인식 개발
Google Mobile Vision과 OpenCV로 card.io를 확장한 범용 카드번호인식 개발Hyukjae Jang
 
OAuth 2.0 Web Messaging Response Mode - OpenID Summit Tokyo 2015
OAuth 2.0 Web Messaging Response Mode - OpenID Summit Tokyo 2015OAuth 2.0 Web Messaging Response Mode - OpenID Summit Tokyo 2015
OAuth 2.0 Web Messaging Response Mode - OpenID Summit Tokyo 2015Toru Yamaguchi
 
multi-thread 어플리케이션에 대해 모든 개발자가 알아 두지 않으면 안 되는 것
multi-thread 어플리케이션에 대해 모든 개발자가 알아 두지 않으면 안 되는 것multi-thread 어플리케이션에 대해 모든 개발자가 알아 두지 않으면 안 되는 것
multi-thread 어플리케이션에 대해 모든 개발자가 알아 두지 않으면 안 되는 것흥배 최
 
Git을 조금 더 알아보자!
Git을 조금 더 알아보자!Git을 조금 더 알아보자!
Git을 조금 더 알아보자!Young Kim
 
PHP AST 徹底解説
PHP AST 徹底解説PHP AST 徹底解説
PHP AST 徹底解説do_aki
 
NDC12_Lockless게임서버설계와구현
NDC12_Lockless게임서버설계와구현NDC12_Lockless게임서버설계와구현
NDC12_Lockless게임서버설계와구현noerror
 
아꿈사 DDD(Domain-Driven Design) 5장 소프트웨어에서 표현되는 모델
아꿈사 DDD(Domain-Driven Design) 5장 소프트웨어에서 표현되는 모델아꿈사 DDD(Domain-Driven Design) 5장 소프트웨어에서 표현되는 모델
아꿈사 DDD(Domain-Driven Design) 5장 소프트웨어에서 표현되는 모델명환 안
 
Extending Java EE with CDI and JBoss Forge
Extending Java EE with CDI and JBoss ForgeExtending Java EE with CDI and JBoss Forge
Extending Java EE with CDI and JBoss ForgeAntoine Sabot-Durand
 
[JWAP-2] DI & Spring
[JWAP-2] DI & Spring[JWAP-2] DI & Spring
[JWAP-2] DI & SpringYoung-Ho Cho
 
C++20 Coroutine
C++20 CoroutineC++20 Coroutine
C++20 Coroutine진화 손
 
JavaScript Fetch API
JavaScript Fetch APIJavaScript Fetch API
JavaScript Fetch APIXcat Liu
 

Was ist angesagt? (20)

C++ 프로젝트에 단위 테스트 도입하기
C++ 프로젝트에 단위 테스트 도입하기C++ 프로젝트에 단위 테스트 도입하기
C++ 프로젝트에 단위 테스트 도입하기
 
C++20 the small things - Timur Doumler
C++20 the small things - Timur DoumlerC++20 the small things - Timur Doumler
C++20 the small things - Timur Doumler
 
인프콘 2022 - Rust 크로스 플랫폼 프로그래밍
인프콘 2022 - Rust 크로스 플랫폼 프로그래밍인프콘 2022 - Rust 크로스 플랫폼 프로그래밍
인프콘 2022 - Rust 크로스 플랫폼 프로그래밍
 
[수정본] 우아한 객체지향
[수정본] 우아한 객체지향[수정본] 우아한 객체지향
[수정본] 우아한 객체지향
 
Ksug2015 - JPA2, JPA 기초와매핑
Ksug2015 - JPA2, JPA 기초와매핑Ksug2015 - JPA2, JPA 기초와매핑
Ksug2015 - JPA2, JPA 기초와매핑
 
DDD 구현기초 (거의 Final 버전)
DDD 구현기초 (거의 Final 버전)DDD 구현기초 (거의 Final 버전)
DDD 구현기초 (거의 Final 버전)
 
PHPでマルチスレッド
PHPでマルチスレッドPHPでマルチスレッド
PHPでマルチスレッド
 
Writing php extensions in golang
Writing php extensions in golangWriting php extensions in golang
Writing php extensions in golang
 
Google Mobile Vision과 OpenCV로 card.io를 확장한 범용 카드번호인식 개발
Google Mobile Vision과 OpenCV로 card.io를 확장한 범용 카드번호인식 개발Google Mobile Vision과 OpenCV로 card.io를 확장한 범용 카드번호인식 개발
Google Mobile Vision과 OpenCV로 card.io를 확장한 범용 카드번호인식 개발
 
OAuth 2.0 Web Messaging Response Mode - OpenID Summit Tokyo 2015
OAuth 2.0 Web Messaging Response Mode - OpenID Summit Tokyo 2015OAuth 2.0 Web Messaging Response Mode - OpenID Summit Tokyo 2015
OAuth 2.0 Web Messaging Response Mode - OpenID Summit Tokyo 2015
 
multi-thread 어플리케이션에 대해 모든 개발자가 알아 두지 않으면 안 되는 것
multi-thread 어플리케이션에 대해 모든 개발자가 알아 두지 않으면 안 되는 것multi-thread 어플리케이션에 대해 모든 개발자가 알아 두지 않으면 안 되는 것
multi-thread 어플리케이션에 대해 모든 개발자가 알아 두지 않으면 안 되는 것
 
Git을 조금 더 알아보자!
Git을 조금 더 알아보자!Git을 조금 더 알아보자!
Git을 조금 더 알아보자!
 
PHP AST 徹底解説
PHP AST 徹底解説PHP AST 徹底解説
PHP AST 徹底解説
 
NDC12_Lockless게임서버설계와구현
NDC12_Lockless게임서버설계와구현NDC12_Lockless게임서버설계와구현
NDC12_Lockless게임서버설계와구현
 
아꿈사 DDD(Domain-Driven Design) 5장 소프트웨어에서 표현되는 모델
아꿈사 DDD(Domain-Driven Design) 5장 소프트웨어에서 표현되는 모델아꿈사 DDD(Domain-Driven Design) 5장 소프트웨어에서 표현되는 모델
아꿈사 DDD(Domain-Driven Design) 5장 소프트웨어에서 표현되는 모델
 
Extending Java EE with CDI and JBoss Forge
Extending Java EE with CDI and JBoss ForgeExtending Java EE with CDI and JBoss Forge
Extending Java EE with CDI and JBoss Forge
 
[JWAP-2] DI & Spring
[JWAP-2] DI & Spring[JWAP-2] DI & Spring
[JWAP-2] DI & Spring
 
C++20 Coroutine
C++20 CoroutineC++20 Coroutine
C++20 Coroutine
 
JavaScript Fetch API
JavaScript Fetch APIJavaScript Fetch API
JavaScript Fetch API
 
200531 jandi
200531 jandi200531 jandi
200531 jandi
 

Andere mochten auch

Boost 라이브리와 C++11
Boost 라이브리와 C++11Boost 라이브리와 C++11
Boost 라이브리와 C++11OnGameServer
 
MinWin에 대해서
MinWin에 대해서MinWin에 대해서
MinWin에 대해서OnGameServer
 
Windows os 상에서 효율적인 덤프
Windows os 상에서 효율적인 덤프Windows os 상에서 효율적인 덤프
Windows os 상에서 효율적인 덤프OnGameServer
 
게임 개발에 도움을 주는 CruiseControl.NET과 Windows Terminal
게임 개발에 도움을 주는 CruiseControl.NET과 Windows Terminal게임 개발에 도움을 주는 CruiseControl.NET과 Windows Terminal
게임 개발에 도움을 주는 CruiseControl.NET과 Windows TerminalOnGameServer
 
안준석님 - 안드로이드 프로세스들의 통신 메커니즘 : 바인더 이야기
안준석님 - 안드로이드 프로세스들의 통신 메커니즘 : 바인더 이야기안준석님 - 안드로이드 프로세스들의 통신 메커니즘 : 바인더 이야기
안준석님 - 안드로이드 프로세스들의 통신 메커니즘 : 바인더 이야기OnGameServer
 
Microsoft SharePoint를 활용한 개발환경 구축
Microsoft SharePoint를 활용한 개발환경 구축Microsoft SharePoint를 활용한 개발환경 구축
Microsoft SharePoint를 활용한 개발환경 구축OnGameServer
 
해외 취업 이야기
해외 취업 이야기해외 취업 이야기
해외 취업 이야기OnGameServer
 
Multi thread game server
Multi thread game serverMulti thread game server
Multi thread game serverOnGameServer
 
SDC 3rd 안중원님 - InGame CashShop 개발 하기
SDC 3rd 안중원님 - InGame CashShop 개발 하기SDC 3rd 안중원님 - InGame CashShop 개발 하기
SDC 3rd 안중원님 - InGame CashShop 개발 하기OnGameServer
 
IPv6 이론과 소켓 프로그래밍
IPv6 이론과 소켓 프로그래밍IPv6 이론과 소켓 프로그래밍
IPv6 이론과 소켓 프로그래밍OnGameServer
 
이욱진님 - 메모리 관리자로부터 배우기
이욱진님 - 메모리 관리자로부터 배우기이욱진님 - 메모리 관리자로부터 배우기
이욱진님 - 메모리 관리자로부터 배우기OnGameServer
 
Mongo db 시작하기
Mongo db 시작하기Mongo db 시작하기
Mongo db 시작하기OnGameServer
 
임영기님 - 코드 리뷰 시스템 도입하기
임영기님 - 코드 리뷰 시스템 도입하기임영기님 - 코드 리뷰 시스템 도입하기
임영기님 - 코드 리뷰 시스템 도입하기OnGameServer
 
一起分享吧
一起分享吧一起分享吧
一起分享吧Emma Chang
 
Femei pe matasari - pentru participare
Femei pe matasari - pentru participareFemei pe matasari - pentru participare
Femei pe matasari - pentru participareAriel Constantinof
 
Form and purpose of the business
Form and purpose of the businessForm and purpose of the business
Form and purpose of the businessUdayan Kachchhy
 

Andere mochten auch (20)

Boost 라이브리와 C++11
Boost 라이브리와 C++11Boost 라이브리와 C++11
Boost 라이브리와 C++11
 
MinWin에 대해서
MinWin에 대해서MinWin에 대해서
MinWin에 대해서
 
Windows os 상에서 효율적인 덤프
Windows os 상에서 효율적인 덤프Windows os 상에서 효율적인 덤프
Windows os 상에서 효율적인 덤프
 
게임 개발에 도움을 주는 CruiseControl.NET과 Windows Terminal
게임 개발에 도움을 주는 CruiseControl.NET과 Windows Terminal게임 개발에 도움을 주는 CruiseControl.NET과 Windows Terminal
게임 개발에 도움을 주는 CruiseControl.NET과 Windows Terminal
 
안준석님 - 안드로이드 프로세스들의 통신 메커니즘 : 바인더 이야기
안준석님 - 안드로이드 프로세스들의 통신 메커니즘 : 바인더 이야기안준석님 - 안드로이드 프로세스들의 통신 메커니즘 : 바인더 이야기
안준석님 - 안드로이드 프로세스들의 통신 메커니즘 : 바인더 이야기
 
Microsoft SharePoint를 활용한 개발환경 구축
Microsoft SharePoint를 활용한 개발환경 구축Microsoft SharePoint를 활용한 개발환경 구축
Microsoft SharePoint를 활용한 개발환경 구축
 
해외 취업 이야기
해외 취업 이야기해외 취업 이야기
해외 취업 이야기
 
Multi thread game server
Multi thread game serverMulti thread game server
Multi thread game server
 
SDC 3rd 안중원님 - InGame CashShop 개발 하기
SDC 3rd 안중원님 - InGame CashShop 개발 하기SDC 3rd 안중원님 - InGame CashShop 개발 하기
SDC 3rd 안중원님 - InGame CashShop 개발 하기
 
IPv6 이론과 소켓 프로그래밍
IPv6 이론과 소켓 프로그래밍IPv6 이론과 소켓 프로그래밍
IPv6 이론과 소켓 프로그래밍
 
이욱진님 - 메모리 관리자로부터 배우기
이욱진님 - 메모리 관리자로부터 배우기이욱진님 - 메모리 관리자로부터 배우기
이욱진님 - 메모리 관리자로부터 배우기
 
Mongo db 시작하기
Mongo db 시작하기Mongo db 시작하기
Mongo db 시작하기
 
임영기님 - 코드 리뷰 시스템 도입하기
임영기님 - 코드 리뷰 시스템 도입하기임영기님 - 코드 리뷰 시스템 도입하기
임영기님 - 코드 리뷰 시스템 도입하기
 
Dream
DreamDream
Dream
 
3亭賢結婚
3亭賢結婚3亭賢結婚
3亭賢結婚
 
一起分享吧
一起分享吧一起分享吧
一起分享吧
 
Saruulbuyn
SaruulbuynSaruulbuyn
Saruulbuyn
 
Trimax | reclamefotografen food fotografie
Trimax | reclamefotografen food fotografieTrimax | reclamefotografen food fotografie
Trimax | reclamefotografen food fotografie
 
Femei pe matasari - pentru participare
Femei pe matasari - pentru participareFemei pe matasari - pentru participare
Femei pe matasari - pentru participare
 
Form and purpose of the business
Form and purpose of the businessForm and purpose of the business
Form and purpose of the business
 

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 중 한쪽만 추가를 하던가, 또는 한쪽만 삭제를 한다면
  • 6.
  • 8.
  • 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
  • 20.