CMap Class
자료구조용으로 많이 사용하는데 CList, CArray 등이있다.
3가지의 장단점을 비교한 내용이다.

classOrderd?Indexed? Insert an elementSearch for specified elementDuplicate elements?
Listyesnofastslowyes
Arrsyyesby intslowslowyes
Mapnoby keyfastfastno(keys), yes(values)


표에서 나와있듯이 속도면에서는 CMap 클래스가 좋은것 같다.

원형은
template< class KEY, class ARG_KEY, class VALUE, class ARG_VALUE >class CMap : public CObject
KEY : Map에 키로 사용될 오브젝트클래스
ARG_KEY : KEY참조값으로 사용된다
VALUE : 저장할 값을나타낸다.
ARG_VALUE : VALUE 참조값으로 사용된다.

사용예 :
// CMap 클래스 헤더 포함
#include "afxtempl.h"

// CMap 유형 정의
typedef CMap <CString, LPCSTR, StrType, StrType&> CMapTest;
// CMap 전역변수 선언
CMapTest m_Map;


// 해쉬 테이블 초기화 및 크기(권장 : 소수값) 설정
m_Map.InitHashTable(17);

// 키와 키값 해쉬 테이블에 저장
m_Map.SetAt(str1, mStr1);
m_Map.SetAt(str2, mStr2);
m_Map.SetAt(str3, mStr3);

// 각각의 저장된 값을 해쉬 테이블에서 읽음
StrType strVal;

strVal.hWnd = NULL;
m_Map.Lookup(str1, strVal);

strVal.hWnd = NULL;
m_Map.Lookup(str2, strVal);

strVal.hWnd = NULL;
m_Map.Lookup(str3, strVal);

// 모든 데이타 삭제
m_Map.RemoveAll();

+ Recent posts