sdc 3rd 최흥배님 - boost.multi_index 사용하기
TRANSCRIPT
multi_index
index : 색인
multi : 다양한
class Character { INT32 m_nCharID; wstring m_strName; INT16 nLevel; INT32 nMoney; ..... };
Key
Key
std::map<INT32, Character> m_CharSetByCharID std::map<wstring, Character> m_CharSetByName m_CharSetByCharID.insert m_CharSetByName.insert m_CharSetByName.erase m_CharSetByCharID.erase
Key는 2개이지만 둘 다 하나의 객체를 가리킨다 실수로 m_CharSetByCharID 나 m_CharSetByName 중 한쪽만 추가를 하던가, 또는 한쪽만 삭제를 한다면
struct Character { INT32 nCharID; wstring 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
multi_index
Boost.multi_index
// 컨테이너의 키를 선언 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;
저장할 객체 캐릭터 ID로 검색
캐릭터 이름으로 검색
type specifier
key-based
ordered ordered_unique
ordered_non_unique
hashed hashed_unique
hashed_non_unique
non key-based sequenced
random_access
인덱스의 종류
삽입 삭제 기능
ordered_unique ordered_non_unique
O(log N) O(1) set, multiset, map, multimap
hashed_unique hashed_non_unique
O(1) O(1) unordered_set, unordered_map
sequenced O(1) O(1) list
random_access O(1) O(뒤에 있는 요소 수) vector
인덱스 성능
컨테이너
<boost/multi_index_container.hpp> multi_index_container를 사용한다
인덱스
<boost/multi_index/ordered_index.hpp> set이나 map과 같이 정렬되는 인덱스를 사용한다 ordered_unique, ordered_non_unique
<boost/multi_index/hashed_index.hpp> 해쉬 키를 가진 인덱스를 사용한다 hashed_unique, hashed_non_unique
<boost/multi_index/sequenced_index.hpp> list와 같은 순번 대로 접근하는 인덱스를 사용한다 sequenced
<boost/multi_index/random_access_index.hpp> vector와 같이 임의 접근이 가능한 인덱스를 사용한다 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;
identity member const_mem_fun mem_fun global_fun composite_key
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