[Sdc 3rd] Boost multi_index
-
Upload
- -
Category
Self Improvement
-
view
1.595 -
download
1
Transcript of [Sdc 3rd] Boost multi_index
multi_index
index : 색인multi : 다양한
class Character{ INT32 m_nCharID; wstring m_strName; INT16 nLevel; INT32 nMoney; .....};
KeyKey
std::map<INT32, Character> m_CharSetByCharIDstd::map<wstring, Character> m_CharSetByName
m_CharSetByCharID.insertm_CharSetByName.insert
m_CharSetByName.erasem_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.insertm_CharSetByName.insert
m_CharSetByName.erasem_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
orderedordered_unique
ordered_non_unique
hashed hashed_unique
hashed_non_unique
non key-basedsequenced
random_access
인덱스의 종류
삽입 삭제 기능
ordered_uniqueordered_non_unique
O(log N) O(1) set, multiset, map, multimap
hashed_uniquehashed_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;
identitymemberconst_mem_funmem_funglobal_funcomposite_key
Key 종류
Demo
Tutorial 1 std::list && std::multiset
Tutorial 2std::vector && std::multiset
Tutorial 3가독성 UP!
Tutorial 4 유저 정의형 타입 사용
Tutorial 5유저 정의형 타입 && 멤버 함수 키 && 합성 키 && bound
Tutorial 6유저 정의형 타입 && std::multiset && std::map
Tutorial 7 replace
Tutorial 8modify
Tutorial 9member_offset
공식 문서http://www.boost.org/doc/libs/1_47_0/libs/multi_index/doc/
핵심 정리( 일어 )http://www24.atwiki.jp/reisiki/pages/59.html