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> 복수의 조건으로 비교하는 경우 필요