hash_map (STL/CLR)

템플릿 클래스는 양방향 액세스 권한이 있는 요소의 다양한 길이 시퀀스를 제어하는 개체를 설명합니다. 컨테이너 hash_map 를 사용하여 요소 시퀀스를 해시 테이블로 관리하고, 각 테이블 항목은 노드의 양방향 연결된 목록을 저장하고, 각 노드는 하나의 요소를 저장합니다. 요소는 시퀀스 순서를 지정하기 위한 키와 라이드를 위해 따라가는 매핑된 값으로 구성됩니다.

아래 GValue 설명에서는 다음과 같습니다.

Microsoft::VisualC::StlClr::GenericPair<GKey, GMapped>

여기서

GKey 는 후자가 ref 형식이 아니면 동일합니다 Key . 이 경우 Key^

GMapped 는 후자가 ref 형식이 아니면 동일합니다 Mapped . 이 경우 Mapped^

구문

template<typename Key,
    typename Mapped>
    ref class hash_map
        :   public
        System::ICloneable,
        System::Collections::IEnumerable,
        System::Collections::ICollection,
        System::Collections::Generic::IEnumerable<GValue>,
        System::Collections::Generic::ICollection<GValue>,
        System::Collections::Generic::IList<GValue>,
        System::Collections::Generic::IDictionary<Gkey, GMapped>,
        Microsoft::VisualC::StlClr::IHash<Gkey, GValue>
    { ..... };

매개 변수

Key
제어되는 시퀀스에 있는 요소의 키 구성 요소 형식입니다.

Mapped
제어되는 시퀀스에 있는 요소의 다른 구성 요소 형식입니다.

요구 사항

헤더:<cliext/hash_map>

네임스페이스:cliext

선언

형식 정의 설명
hash_map::const_iterator 제어되는 시퀀스에 대한 상수 반복기의 형식입니다.
hash_map::const_reference 요소에 대한 상수 참조의 형식입니다.
hash_map::const_reverse_iterator 제어되는 시퀀스에 대한 상수 역방향 반복기의 형식입니다.
hash_map::difference_type 두 요소 사이의 (부호 있는) 거리의 형식입니다.
hash_map::generic_container 컨테이너에 대한 제네릭 인터페이스의 형식입니다.
hash_map::generic_iterator 컨테이너의 제네릭 인터페이스에 대한 반복기의 형식입니다.
hash_map::generic_reverse_iterator 컨테이너의 제네릭 인터페이스에 대한 역방향 반복기의 형식입니다.
hash_map::generic_value 컨테이너의 제네릭 인터페이스에 대한 요소의 형식입니다.
hash_map::hasher 키에 대한 해시 대리자입니다.
hash_map::iterator 제어되는 시퀀스에 대한 반복기의 형식입니다.
hash_map::key_compare 두 키에 대한 순서 지정 대리자입니다.
hash_map::key_type 정렬 키의 형식입니다.
hash_map::mapped_type 각 키와 연결된 매핑된 값의 형식입니다.
hash_map::reference 요소에 대한 참조의 형식입니다.
hash_map::reverse_iterator 제어되는 시퀀스에 대한 반대 반복기의 형식입니다.
hash_map::size_type 두 요소 사이의 (음수가 아닌) 거리의 형식입니다.
hash_map::value_compare 두 요소 값에 대한 순서 지정 대리자입니다.
hash_map::value_type 요소의 형식입니다.
멤버 함수 설명
hash_map::begin 제어되는 시퀀스의 시작을 지정합니다.
hash_map::bucket_count 버킷 수를 계산합니다.
hash_map::clear 모든 요소를 제거합니다.
hash_map::count 지정된 키와 일치하는 요소를 계산합니다.
hash_map::empty 요소가 있는지 여부를 테스트합니다.
hash_map::end 제어되는 시퀀스의 끝을 지정합니다.
hash_map::equal_range 지정된 키와 일치하는 범위를 찾습니다.
hash_map::erase 지정된 위치에 있는 요소를 제거합니다.
hash_map::find 지정된 키와 일치하는 요소를 찾습니다.
hash_map::hash_delegate 키에 대한 해시 대리자를 복사합니다.
hash_map::hash_map 컨테이너 개체를 만듭니다.
hash_map::insert 요소를 추가합니다.
hash_map::key_comp 두 키에 대한 순서 지정 대리자를 복사합니다.
hash_map::load_factor 버킷당 평균 요소 수를 계산합니다.
hash_map::lower_bound 지정된 키와 일치하는 범위의 시작을 찾습니다.
hash_map::make_value 값 개체를 생성합니다.
hash_map::max_load_factor 버킷당 최대 요소 수를 가져오거나 설정합니다.
hash_map::rbegin 제어되는 역방향 시퀀스의 시작을 지정합니다.
hash_map::rehash 해시 테이블을 다시 빌드합니다.
hash_map::rend 제어되는 역방향 시퀀스의 끝을 지정합니다.
hash_map::size 요소 수를 계산합니다.
hash_map::swap 두 컨테이너의 내용을 바꿉니다.
hash_map::to_array 제어된 시퀀스를 새 배열에 복사합니다.
hash_map::upper_bound 지정된 키와 일치하는 범위의 끝을 찾습니다.
hash_map::value_comp 두 요소 값에 대한 순서 지정 대리자를 복사합니다.
연산자 설명
hash_map::operator= 제어되는 시퀀스를 바꿉니다.
hash_map::operator[] 연결된 매핑된 값에 키를 지도.

인터페이스

인터페이스 설명
ICloneable 개체를 복제합니다.
IEnumerable 요소를 시퀀스합니다.
ICollection 요소 그룹을 유지 관리합니다.
IEnumerable<T> 형식화된 요소를 통한 시퀀스입니다.
ICollection<T> 형식화된 요소 그룹을 유지 관리합니다.
IDictionary<TKey,TValue> {key, value} 쌍의 그룹을 유지 관리합니다.
IHash<Key, Value> 일반 컨테이너를 유지 관리합니다.

설명

개체는 양방향 연결된 목록에서 개별 노드로 제어하는 시퀀스에 대한 스토리지를 할당하고 해제합니다. 액세스 속도를 높이기 위해 개체는 목록(해시 테이블)에 다양한 길이의 포인터 배열을 기본 전체 목록을 하위 목록 또는 버킷의 시퀀스로 효과적으로 관리합니다. 한 노드의 내용을 다른 노드에 복사하지 않고 노드 간 링크를 변경하여 순서가 유지되는 버킷에 요소를 삽입합니다. 즉, 요소를 다시 기본 방해하지 않고 요소를 자유롭게 삽입하고 제거할 수 있습니다.

개체는 형식 hash_set::key_compare의 저장된 대리자 개체를 호출하여 제어하는 각 버킷을 정렬합니다. hash_set 만들 때 저장된 대리자 개체를 지정할 수 있습니다. 대리자 개체를 지정하지 않으면 기본값은 비교 operator<=(key_type, key_type)입니다.

멤버 함수 hash_set::key_comp()를 호출하여 저장된 대리자 개체에 액세스합니다. 이러한 대리자 개체는 형식 hash_set::key_type의 키 간에 동일한 순서를 정의해야 합니다. 즉, 두 키 X 에 대해 다음을 Y수행합니다.

key_comp()(X, Y) 는 모든 호출에서 동일한 부울 결과를 반환합니다.

true XY 이면 key_comp()(X, Y) && key_comp()(Y, X) 동일한 순서를 가지고 있다고 합니다.

동일한 순서 지정처럼 operator<=(key_type, key_type)operator>=(key_type, key_type) 동작하거나 operator==(key_type, key_type) 동일한 순서를 정의하는 모든 순서 지정 규칙입니다.

컨테이너는 키가 동일한 순서(및 동일한 정수 값에 대한 해시)를 가진 요소만 버킷 내에 인접하도록 합니다. 템플릿 클래스 hash_multimap와 달리 템플릿 클래스 hash_map 의 개체는 모든 요소의 키가 고유하도록 합니다. (두 키에는 동일한 순서가 없습니다.)

개체는 형식 hash_set::hasher의 저장된 대리자 개체를 호출하여 지정된 순서 지정 키를 포함해야 하는 버킷을 결정합니다. 키 값에 따라 정수 값을 얻기 위해 멤버 함수 hash_set::hash_delegate 를 호출하여 이 저장된 개체에 액세스합니다. hash_set 만들 때 저장된 대리자 개체를 지정할 수 있습니다. 대리자 개체를 지정하지 않으면 기본값은 함수 System::Object::hash_value(key_type)입니다. 즉, 모든 키 X 에 대해 다음을 Y수행합니다.

hash_delegate()(X) 는 모든 호출에서 동일한 정수 결과를 반환합니다.

Y 동일한 순서가 hash_delegate()(X) 있는 경우 X 동일한 정수 결과를 hash_delegate()(Y)반환해야 합니다.

각 요소에는 별도의 키와 매핑된 값이 포함됩니다. 시퀀스는 상수 시간에 임의의 요소의 조회, 삽입 및 제거를 허용하는 방식으로 표시됩니다. 즉, 작업 수는 적어도 최상의 경우 시퀀스의 요소 수와 독립적입니다. 또한 요소를 삽입하면 반복기가 무효화되지 않고 요소를 제거하면 제거된 요소를 가리키는 반복기만 무효화됩니다.

그러나 해시된 값이 균일하게 분산되지 않으면 해시 테이블이 퇴화될 수 있습니다. 극단(항상 동일한 값을 반환하는 해시 함수의 경우) 조회, 삽입 및 제거는 시퀀스의 요소 수(선형 시간)에 비례합니다. 컨테이너는 적절한 해시 함수, 평균 버킷 크기 및 해시 테이블 크기(총 버킷 수)를 선택하기 위해 노력하지만 이러한 선택 항목 중 전부 또는 전부를 재정의할 수 있습니다. 예를 들어 함수 및 hash_set::rehash.를 참조하세요hash_set::max_load_factor.

A는 hash_map 양방향 반복기를 지원합니다. 즉, 제어되는 시퀀스에서 요소를 지정하는 반복기가 지정된 경우 인접한 요소로 단계별로 실행할 수 있습니다. 특수 헤드 노드는 .에서 반환 end()한 반복기에 해당합니다. 제어된 시퀀스의 마지막 요소(있는 경우)에 도달하도록 이 반복기를 감소할 수 있습니다. 반복기를 증 hash_map 분하여 헤드 노드에 도달할 수 있으며, 그러면 같음과 end()비교됩니다. 그러나 반환 end()된 반복기를 역참조할 수는 없습니다.

숫자 위치를 지정하면 요소를 직접 참조할 hash_map 수 없으며 임의 액세스 반복기가 필요합니다.

hash_map 반복기는 연결된 hash_map 노드에 핸들을 저장합니다. 이 노드는 연결된 컨테이너에 대한 핸들을 저장합니다. 연결된 컨테이너 개체에서만 반복기를 사용할 수 있습니다. hash_map 반복기는 연결된 hash_map 노드가 일부 hash_map노드와 연결되어 있는 한 유효합니다기본. 또한 유효한 반복기는 역참조할 수 있습니다. 이 값을 사용하여 지정 end()한 요소 값에 액세스하거나 변경할 수 있습니다.

요소를 지우거나 제거하면 저장된 값에 대한 소멸자가 호출됩니다. 컨테이너를 삭제하면 모든 요소가 지워집니다. 따라서 요소 형식이 ref 클래스인 컨테이너는 컨테이너보다 더 오래 살 요소가 없도록 합니다. 그러나 핸들 컨테이너는 해당 요소를 삭제하지 않습니다.

멤버

hash_map::begin

제어되는 시퀀스의 시작을 지정합니다.

구문

iterator begin();

설명

멤버 함수는 제어되는 시퀀스의 첫 번째 요소를 지정하거나 빈 시퀀스의 끝 바로 너머를 지정하는 양방향 반복기를 반환합니다. 이를 사용하여 제어되는 시퀀스의 시작을 지정 current 하는 반복기를 가져오지만 제어되는 시퀀스의 길이가 변경되면 해당 상태 변경될 수 있습니다.

예시

// cliext_hash_map_begin.cpp
// compile with: /clr
#include <cliext/hash_map>

typedef cliext::hash_map<wchar_t, int> Myhash_map;
int main()
    {
    Myhash_map c1;
    c1.insert(Myhash_map::make_value(L'a', 1));
    c1.insert(Myhash_map::make_value(L'b', 2));
    c1.insert(Myhash_map::make_value(L'c', 3));

    // display contents " [a 1] [b 2] [c 3]"
    for each (Myhash_map::value_type elem in c1)
        System::Console::Write("[{0} {1}] ", elem->first, elem->second);
    System::Console::WriteLine();

    // inspect first two items
    Myhash_map::iterator it = c1.begin();
    System::Console::WriteLine("*begin() = [{0} {1}]",
        it->first, it->second);
    ++it;
    System::Console::WriteLine("*++begin() = [{0} {1}]",
        it->first, it->second);
    return (0);
    }
[a 1] [b 2] [c 3]
*begin() = [a 1]
*++begin() = [b 2]

hash_map::bucket_count

버킷 수를 계산합니다.

구문

int bucket_count();

설명

멤버 함수는 현재 버킷 수를 반환합니다. 이를 사용하여 해시 테이블의 크기를 확인합니다.

예시

// cliext_hash_map_bucket_count.cpp
// compile with: /clr
#include <cliext/hash_map>

typedef cliext::hash_map<wchar_t, int> Myhash_map;
int main()
    {
    Myhash_map c1 = gcnew Myhash_map;
    c1.insert(Myhash_map::make_value(L'a', 1));
    c1.insert(Myhash_map::make_value(L'b', 2));
    c1.insert(Myhash_map::make_value(L'c', 3));

    // display contents " [a 1] [b 2] [c 3]"
    for each (Myhash_map::value_type elem in c1)
        System::Console::Write("[{0} {1}] ", elem->first, elem->second);
    System::Console::WriteLine();

    // inspect current parameters
    System::Console::WriteLine("bucket_count() = {0}", c1.bucket_count());
    System::Console::WriteLine("load_factor() = {0}", c1.load_factor());
    System::Console::WriteLine("max_load_factor() = {0}",
        c1.max_load_factor());
    System::Console::WriteLine();

    // change max_load_factor and redisplay
    c1.max_load_factor(0.25f);
    System::Console::WriteLine("bucket_count() = {0}", c1.bucket_count());
    System::Console::WriteLine("load_factor() = {0}", c1.load_factor());
    System::Console::WriteLine("max_load_factor() = {0}",
        c1.max_load_factor());
    System::Console::WriteLine();

    // rehash and redisplay
    c1.rehash(100);
    System::Console::WriteLine("bucket_count() = {0}", c1.bucket_count());
    System::Console::WriteLine("load_factor() = {0}", c1.load_factor());
    System::Console::WriteLine("max_load_factor() = {0}",
        c1.max_load_factor());
    return (0);
    }
[a 1] [b 2] [c 3]
bucket_count() = 16
load_factor() = 0.1875
max_load_factor() = 4

bucket_count() = 16
load_factor() = 0.1875
max_load_factor() = 0.25

bucket_count() = 128
load_factor() = 0.0234375
max_load_factor() = 0.25

hash_map::clear

모든 요소를 제거합니다.

구문

void clear();

설명

멤버 함수는 효과적으로 호출 erase(begin(), end())합니다. 제어된 시퀀스가 비어 있는지 확인하는 데 사용합니다.

예시

// cliext_hash_map_clear.cpp
// compile with: /clr
#include <cliext/hash_map>

typedef cliext::hash_map<wchar_t, int> Myhash_map;
int main()
    {
    Myhash_map c1;
    c1.insert(Myhash_map::make_value(L'a', 1));
    c1.insert(Myhash_map::make_value(L'b', 2));
    c1.insert(Myhash_map::make_value(L'c', 3));

    // display contents " [a 1] [b 2] [c 3]"
    for each (Myhash_map::value_type elem in c1)
        System::Console::Write("[{0} {1}] ", elem->first, elem->second);
    System::Console::WriteLine();

    // clear the container and reinspect
    c1.clear();
    System::Console::WriteLine("size() = {0}", c1.size());

    c1.insert(Myhash_map::make_value(L'a', 1));
    c1.insert(Myhash_map::make_value(L'b', 2));

    // display contents " [a 1] [b 2]"
    for each (Myhash_map::value_type elem in c1)
        System::Console::Write("[{0} {1}] ", elem->first, elem->second);
    System::Console::WriteLine();
    c1.clear();
    System::Console::WriteLine("size() = {0}", c1.size());
    return (0);
    }
[a 1] [b 2] [c 3]
size() = 0
[a 1] [b 2]
size() = 0

hash_map::const_iterator

제어되는 시퀀스에 대한 상수 반복기의 형식입니다.

구문

typedef T2 const_iterator;

설명

이 형식은 제어되는 시퀀스에 대한 상수 양방향 반복기 역할을 할 수 있는 지정되지 않은 형식 T2 의 개체를 설명합니다.

예시

// cliext_hash_map_const_iterator.cpp
// compile with: /clr
#include <cliext/hash_map>

typedef cliext::hash_map<wchar_t, int> Myhash_map;
int main()
    {
    Myhash_map c1;
    c1.insert(Myhash_map::make_value(L'a', 1));
    c1.insert(Myhash_map::make_value(L'b', 2));
    c1.insert(Myhash_map::make_value(L'c', 3));

    // display contents " [a 1] [b 2] [c 3]"
    Myhash_map::const_iterator cit = c1.begin();
    for (; cit != c1.end(); ++cit)
        System::Console::Write("[{0} {1}] ", cit->first, cit->second);
    System::Console::WriteLine();
    return (0);
    }
[a 1] [b 2] [c 3]

hash_map::const_reference

요소에 대한 상수 참조의 형식입니다.

구문

typedef value_type% const_reference;

설명

이 형식은 요소에 대한 상수 참조를 설명합니다.

예시

// cliext_hash_map_const_reference.cpp
// compile with: /clr
#include <cliext/hash_map>

typedef cliext::hash_map<wchar_t, int> Myhash_map;
int main()
    {
    Myhash_map c1;
    c1.insert(Myhash_map::make_value(L'a', 1));
    c1.insert(Myhash_map::make_value(L'b', 2));
    c1.insert(Myhash_map::make_value(L'c', 3));

    // display contents " [a 1] [b 2] [c 3]"
    Myhash_map::const_iterator cit = c1.begin();
    for (; cit != c1.end(); ++cit)
        {   // get a const reference to an element
        Myhash_map::const_reference cref = *cit;
        System::Console::Write("[{0} {1}] ", cref->first, cref->second);
        }
    System::Console::WriteLine();
    return (0);
    }
[a 1] [b 2] [c 3]

hash_map::const_reverse_iterator

제어되는 시퀀스에 대한 상수 역방향 반복기의 형식입니다.

구문

typedef T4 const_reverse_iterator;

설명

이 형식은 제어되는 시퀀스에 대한 상수 역방향 반복기 역할을 할 수 있는 지정되지 않은 형식 T4 의 개체를 설명합니다.

예시

// cliext_hash_map_const_reverse_iterator.cpp
// compile with: /clr
#include <cliext/hash_map>

typedef cliext::hash_map<wchar_t, int> Myhash_map;
int main()
    {
    Myhash_map c1;
    c1.insert(Myhash_map::make_value(L'a', 1));
    c1.insert(Myhash_map::make_value(L'b', 2));
    c1.insert(Myhash_map::make_value(L'c', 3));

    // display contents " [a 1] [b 2] [c 3]" reversed
    Myhash_map::const_reverse_iterator crit = c1.rbegin();
    for (; crit != c1.rend(); ++crit)
        System::Console::Write("[{0} {1}] ", crit->first, crit->second);
    System::Console::WriteLine();
    return (0);
    }
[c 3] [b 2] [a 1]

hash_map::count

지정한 키와 일치하는 요소의 수를 찾습니다.

구문

size_type count(key_type key);

매개 변수

key
검색할 키 값입니다.

설명

멤버 함수는 동일한 순서를 가진 제어되는 시퀀스의 요소 수를 반환합니다 key. 이를 사용하여 지정된 키와 일치하는 제어된 시퀀스에 있는 요소의 수를 확인합니다.

예시

// cliext_hash_map_count.cpp
// compile with: /clr
#include <cliext/hash_map>

typedef cliext::hash_map<wchar_t, int> Myhash_map;
int main()
    {
    Myhash_map c1;
    c1.insert(Myhash_map::make_value(L'a', 1));
    c1.insert(Myhash_map::make_value(L'b', 2));
    c1.insert(Myhash_map::make_value(L'c', 3));

    // display contents " [a 1] [b 2] [c 3]"
    for each (Myhash_map::value_type elem in c1)
        System::Console::Write("[{0} {1}] ", elem->first, elem->second);
    System::Console::WriteLine();

    System::Console::WriteLine("count(L'A') = {0}", c1.count(L'A'));
    System::Console::WriteLine("count(L'b') = {0}", c1.count(L'b'));
    System::Console::WriteLine("count(L'C') = {0}", c1.count(L'C'));
    return (0);
    }
[a 1] [b 2] [c 3]
count(L'A') = 0
count(L'b') = 1
count(L'C') = 0

hash_map::difference_type

두 요소 사이의 부가된 거리 형식입니다.

구문

typedef int difference_type;

설명

이 형식은 음수 요소 수를 설명합니다.

예시

// cliext_hash_map_difference_type.cpp
// compile with: /clr
#include <cliext/hash_map>

typedef cliext::hash_map<wchar_t, int> Myhash_map;
int main()
    {
    Myhash_map c1;
    c1.insert(Myhash_map::make_value(L'a', 1));
    c1.insert(Myhash_map::make_value(L'b', 2));
    c1.insert(Myhash_map::make_value(L'c', 3));

    // display contents " [a 1] [b 2] [c 3]"
    for each (Myhash_map::value_type elem in c1)
        System::Console::Write("[{0} {1}] ", elem->first, elem->second);
    System::Console::WriteLine();

    // compute positive difference
    Myhash_map::difference_type diff = 0;
    for (Myhash_map::iterator it = c1.begin(); it != c1.end(); ++it)
        ++diff;
    System::Console::WriteLine("end()-begin() = {0}", diff);

    // compute negative difference
    diff = 0;
    for (Myhash_map::iterator it = c1.end(); it != c1.begin(); --it)
        --diff;
    System::Console::WriteLine("begin()-end() = {0}", diff);
    return (0);
    }
[a 1] [b 2] [c 3]
end()-begin() = 3
begin()-end() = -3

hash_map::empty

요소가 있는지 여부를 테스트합니다.

구문

bool empty();

설명

멤버 함수는 제어되는 빈 시퀀스에 대해 반환 true 합니다. 이 값은 .에 해당합니다 size() == 0. 이 값을 사용하여 비어 있는지 여부를 테스트합니다 hash_map .

예시

// cliext_hash_map_empty.cpp
// compile with: /clr
#include <cliext/hash_map>

typedef cliext::hash_map<wchar_t, int> Myhash_map;
int main()
    {
    Myhash_map c1;
    c1.insert(Myhash_map::make_value(L'a', 1));
    c1.insert(Myhash_map::make_value(L'b', 2));
    c1.insert(Myhash_map::make_value(L'c', 3));

    // display contents " [a 1] [b 2] [c 3]"
    for each (Myhash_map::value_type elem in c1)
        System::Console::Write("[{0} {1}] ", elem->first, elem->second);
    System::Console::WriteLine();
    System::Console::WriteLine("size() = {0}", c1.size());
    System::Console::WriteLine("empty() = {0}", c1.empty());

    // clear the container and reinspect
    c1.clear();
    System::Console::WriteLine("size() = {0}", c1.size());
    System::Console::WriteLine("empty() = {0}", c1.empty());
    return (0);
    }
[a 1] [b 2] [c 3]
size() = 3
empty() = False
size() = 0
empty() = True

hash_map::end

제어되는 시퀀스의 끝을 지정합니다.

구문

iterator end();

설명

멤버 함수는 제어되는 시퀀스의 끝 바로 다음을 가리키는 양방향 반복기를 반환합니다. 제어되는 시퀀스의 끝을 지정하는 반복기를 가져오는 데 사용합니다. 제어되는 시퀀스의 길이가 변경되면 해당 상태 변경되지 않습니다.

예시

// cliext_hash_map_end.cpp
// compile with: /clr
#include <cliext/hash_map>

typedef cliext::hash_map<wchar_t, int> Myhash_map;
int main()
    {
    Myhash_map c1;
    c1.insert(Myhash_map::make_value(L'a', 1));
    c1.insert(Myhash_map::make_value(L'b', 2));
    c1.insert(Myhash_map::make_value(L'c', 3));

    // display contents " [a 1] [b 2] [c 3]"
    for each (Myhash_map::value_type elem in c1)
        System::Console::Write("[{0} {1}] ", elem->first, elem->second);
    System::Console::WriteLine();

    // inspect last two items
    Myhash_map::iterator it = c1.end();
    --it;
    --it;
    System::Console::WriteLine("*-- --end() = [{0} {1}]",
        it->first, it->second);
    ++it;
    System::Console::WriteLine("*--end() = [{0} {1}]",
        it->first, it->second);
    return (0);
    }
[a 1] [b 2] [c 3]
*-- --end() = [b 2]
*--end() = [c 3]

hash_map::equal_range

지정된 키와 일치하는 범위를 찾습니다.

구문

cliext::pair<iterator, iterator> equal_range(key_type key);

매개 변수

key
검색할 키 값입니다.

설명

멤버 함수는 반복기 쌍을 반환합니다 cliext::pair<iterator, iterator>(lower_bound(key), upper_bound(key)). 이를 사용하여 지정된 키와 일치하는 제어된 시퀀스에 있는 요소의 범위를 확인합니다.

예시

// cliext_hash_map_equal_range.cpp
// compile with: /clr
#include <cliext/hash_map>

typedef cliext::hash_map<wchar_t, int> Myhash_map;
typedef Myhash_map::pair_iter_iter Pairii;
int main()
    {
    Myhash_map c1;
    c1.insert(Myhash_map::make_value(L'a', 1));
    c1.insert(Myhash_map::make_value(L'b', 2));
    c1.insert(Myhash_map::make_value(L'c', 3));

    // display contents " [a 1] [b 2] [c 3]"
    for each (Myhash_map::value_type elem in c1)
        System::Console::Write("[{0} {1}] ", elem->first, elem->second);
    System::Console::WriteLine();

    // display results of failed search
    Pairii pair1 = c1.equal_range(L'x');
    System::Console::WriteLine("equal_range(L'x') empty = {0}",
        pair1.first == pair1.second);

    // display results of successful search
    pair1 = c1.equal_range(L'b');
    for (; pair1.first != pair1.second; ++pair1.first)
        System::Console::Write("[{0} {1}] ",
            pair1.first->first, pair1.first->second);
    System::Console::WriteLine();
    return (0);
    }
[a 1] [b 2] [c 3]
equal_range(L'x') empty = True
[b 2]

hash_map::erase

지정된 위치에 있는 요소를 제거합니다.

구문

iterator erase(iterator where);
iterator erase(iterator first, iterator last);
bool erase(key_type key)

매개 변수

first
지울 범위의 시작입니다.

key
지울 키 값입니다.

last
지울 범위의 끝입니다.

where
지울 요소입니다.

설명

첫 번째 멤버 함수는 제어되는 시퀀스의 where요소를 제거하고 제거된 요소를 벗어나거나 end() 해당 요소가 없는 경우 기본 첫 번째 요소를 다시 지정하는 반복기를 반환합니다. 단일 요소를 제거하는 데 사용합니다.

두 번째 멤버 함수는 [first,last) 범위에서 제어되는 시퀀스의 요소를 제거하고 제거된 요소를 벗어나거나 end() 해당 요소가 없는 경우 첫 번째 요소를 다시 지정하는 반복기를 반환합니다기본. 0개 이상의 연속 요소를 제거하는 데 사용합니다.

세 번째 멤버 함수는 키가 동일한 순서 key를 갖는 제어되는 시퀀스의 요소를 제거하고 제거된 요소의 개수를 반환합니다. 지정된 키와 일치하는 모든 요소를 제거하고 계산하는 데 사용합니다.

각 요소 삭제는 제어되는 시퀀스의 요소 수 로그에 비례하여 시간이 걸립니다.

예시

// cliext_hash_map_erase.cpp
// compile with: /clr
#include <cliext/hash_map>

typedef cliext::hash_map<wchar_t, int> Myhash_map;
int main()
    {
    cliext::hash_map<wchar_t, int> c1;
    c1.insert(cliext::hash_map<wchar_t, int>::make_value(L'a', 1));
    c1.insert(cliext::hash_map<wchar_t, int>::make_value(L'b', 2));
    c1.insert(cliext::hash_map<wchar_t, int>::make_value(L'c', 3));

    // display contents " [a 1] [b 2] [c 3]"
    for each (cliext::hash_map<wchar_t, int>::value_type elem in c1)
        System::Console::Write("[{0} {1}] ", elem->first, elem->second);
    System::Console::WriteLine();

    // erase an element and reinspect
    cliext::hash_map<wchar_t, int>::iterator it =
        c1.erase(c1.begin());
    System::Console::WriteLine("erase(begin()) = [{0} {1}]",
        it->first, it->second);

    // add elements and display " b c d e"
    c1.insert(cliext::hash_map<wchar_t, int>::make_value(L'd', 4));
    c1.insert(cliext::hash_map<wchar_t, int>::make_value(L'e', 5));
    for each (cliext::hash_map<wchar_t, int>::value_type elem in c1)
        System::Console::Write("[{0} {1}] ", elem->first, elem->second);
    System::Console::WriteLine();

    // erase all but end
    it = c1.end();
    it = c1.erase(c1.begin(), --it);
    System::Console::WriteLine("erase(begin(), end()-1) = [{0} {1}]",
        it->first, it->second);
    System::Console::WriteLine("size() = {0}", c1.size());

    // erase end
    System::Console::WriteLine("erase(L'x') = {0}", c1.erase(L'x'));
    System::Console::WriteLine("erase(L'e') = {0}", c1.erase(L'e'));
    return (0);
    }
[a 1] [b 2] [c 3]
erase(begin()) = [b 2]
[b 2] [c 3] [d 4] [e 5]
erase(begin(), end()-1) = [e 5]
size() = 1
erase(L'x') = 0
erase(L'e') = 1

hash_map::find

지정된 키와 일치하는 요소를 찾습니다.

구문

iterator find(key_type key);

매개 변수

key
검색할 키 값입니다.

설명

제어되는 시퀀스의 하나 이상의 요소에 동일한 순서가 key있는 경우 멤버 함수는 해당 요소 중 하나를 지정하는 반복기를 반환하고, 그렇지 않으면 반환됩니다 end(). 이를 사용하여 지정된 키와 일치하는 제어된 시퀀스에서 현재 요소를 찾습니다.

예시

// cliext_hash_map_find.cpp
// compile with: /clr
#include <cliext/hash_map>

typedef cliext::hash_map<wchar_t, int> Myhash_map;
int main()
    {
    Myhash_map c1;
    c1.insert(Myhash_map::make_value(L'a', 1));
    c1.insert(Myhash_map::make_value(L'b', 2));
    c1.insert(Myhash_map::make_value(L'c', 3));

    // display contents " [a 1] [b 2] [c 3]"
    for each (Myhash_map::value_type elem in c1)
        System::Console::Write("[{0} {1}] ", elem->first, elem->second);
    System::Console::WriteLine();

    System::Console::WriteLine("find {0} = {1}",
        L'A', c1.find(L'A') != c1.end());

    Myhash_map::iterator it = c1.find(L'b');
    System::Console::WriteLine("find {0} = [{1} {2}]",
        L'b', it->first, it->second);

    System::Console::WriteLine("find {0} = {1}",
        L'C', c1.find(L'C') != c1.end());
    return (0);
    }
[a 1] [b 2] [c 3]
find A = False
find b = [b 2]
find C = False

hash_map::generic_container

컨테이너에 대한 제네릭 인터페이스의 형식입니다.

구문

typedef Microsoft::VisualC::StlClr::
    IHash<GKey, GValue>
    generic_container;

설명

이 형식은 이 템플릿 컨테이너 클래스에 대한 제네릭 인터페이스를 설명합니다.

예시

// cliext_hash_map_generic_container.cpp
// compile with: /clr
#include <cliext/hash_map>

typedef cliext::hash_map<wchar_t, int> Myhash_map;
int main()
    {
    Myhash_map c1;
    c1.insert(Myhash_map::make_value(L'a', 1));
    c1.insert(Myhash_map::make_value(L'b', 2));
    c1.insert(Myhash_map::make_value(L'c', 3));

    // display contents " [a 1] [b 2] [c 3]"
    for each (Myhash_map::value_type elem in c1)
        System::Console::Write("[{0} {1}] ", elem->first, elem->second);
    System::Console::WriteLine();

    // construct a generic container
    Myhash_map::generic_container^ gc1 = %c1;
    for each (Myhash_map::value_type elem in gc1)
        System::Console::Write("[{0} {1}] ", elem->first, elem->second);
    System::Console::WriteLine();

    // modify generic and display original
    gc1->insert(Myhash_map::make_value(L'd', 4));
    for each (Myhash_map::value_type elem in c1)
        System::Console::Write("[{0} {1}] ", elem->first, elem->second);
    System::Console::WriteLine();

    // modify original and display generic
    c1.insert(Myhash_map::make_value(L'e', 5));
    for each (Myhash_map::value_type elem in gc1)
        System::Console::Write("[{0} {1}] ", elem->first, elem->second);
    System::Console::WriteLine();
    return (0);
    }
[a 1] [b 2] [c 3]
[a 1] [b 2] [c 3]
[a 1] [b 2] [c 3] [d 4]
[a 1] [b 2] [c 3] [d 4] [e 5]

hash_map::generic_iterator

컨테이너에 대한 제네릭 인터페이스와 함께 사용할 반복기의 형식입니다.

구문

typedef Microsoft::VisualC::StlClr::Generic::
    ContainerBidirectionalIterator<generic_value>
    generic_iterator;

설명

이 형식은 이 템플릿 컨테이너 클래스에 대한 제네릭 인터페이스와 함께 사용할 수 있는 제네릭 반복기를 설명합니다.

예시

// cliext_hash_map_generic_iterator.cpp
// compile with: /clr
#include <cliext/hash_map>

typedef cliext::hash_map<wchar_t, int> Myhash_map;
int main()
    {
    Myhash_map c1;
    c1.insert(Myhash_map::make_value(L'a', 1));
    c1.insert(Myhash_map::make_value(L'b', 2));
    c1.insert(Myhash_map::make_value(L'c', 3));

    // display contents " [a 1] [b 2] [c 3]"
    for each (Myhash_map::value_type elem in c1)
        System::Console::Write("[{0} {1}] ", elem->first, elem->second);
    System::Console::WriteLine();

    // construct a generic container
    Myhash_map::generic_container^ gc1 = %c1;
    for each (Myhash_map::value_type elem in gc1)
        System::Console::Write("[{0} {1}] ", elem->first, elem->second);
    System::Console::WriteLine();

    // get an element and display it
    Myhash_map::generic_iterator gcit = gc1->begin();
    Myhash_map::generic_value gcval = *gcit;
    System::Console::Write("[{0} {1}] ", gcval->first, gcval->second);
    System::Console::WriteLine();
    return (0);
    }
[a 1] [b 2] [c 3]
[a 1] [b 2] [c 3]
[a 1]

hash_map::generic_reverse_iterator

컨테이너의 제네릭 인터페이스와 함께 사용할 역방향 반복기의 형식입니다.

구문

typedef Microsoft::VisualC::StlClr::Generic::
    ReverseRandomAccessIterator<generic_value>
    generic_reverse_iterator;

설명

이 형식은 이 템플릿 컨테이너 클래스에 대한 제네릭 인터페이스와 함께 사용할 수 있는 제네릭 역방향 반복기를 설명합니다.

예시

// cliext_hash_map_generic_reverse_iterator.cpp
// compile with: /clr
#include <cliext/hash_map>

typedef cliext::hash_map<wchar_t, int> Myhash_map;
int main()
    {
    Myhash_map c1;
    c1.insert(Myhash_map::make_value(L'a', 1));
    c1.insert(Myhash_map::make_value(L'b', 2));
    c1.insert(Myhash_map::make_value(L'c', 3));

    // display contents " [a 1] [b 2] [c 3]"
    for each (Myhash_map::value_type elem in c1)
        System::Console::Write("[{0} {1}] ", elem->first, elem->second);
    System::Console::WriteLine();

    // construct a generic container
    Myhash_map::generic_container^ gc1 = %c1;
    for each (Myhash_map::value_type elem in gc1)
        System::Console::Write("[{0} {1}] ", elem->first, elem->second);
    System::Console::WriteLine();

    // get an element and display it
    Myhash_map::generic_reverse_iterator gcit = gc1->rbegin();
    Myhash_map::generic_value gcval = *gcit;
    System::Console::WriteLine("[{0} {1}] ", gcval->first, gcval->second);
    return (0);
    }
[a 1] [b 2] [c 3]
[a 1] [b 2] [c 3]
[c 3]

hash_map::generic_value

컨테이너에 대한 제네릭 인터페이스와 함께 사용할 요소의 형식입니다.

구문

typedef GValue generic_value;

설명

이 형식은 이 템플릿 컨테이너 클래스의 제네릭 인터페이스와 함께 사용할 저장된 요소 값을 설명하는 형식 GValue 의 개체를 설명합니다.

예시

// cliext_hash_map_generic_value.cpp
// compile with: /clr
#include <cliext/hash_map>

typedef cliext::hash_map<wchar_t, int> Myhash_map;
int main()
    {
    Myhash_map c1;
    c1.insert(Myhash_map::make_value(L'a', 1));
    c1.insert(Myhash_map::make_value(L'b', 2));
    c1.insert(Myhash_map::make_value(L'c', 3));

    // display contents " [a 1] [b 2] [c 3]"
    for each (Myhash_map::value_type elem in c1)
        System::Console::Write("[{0} {1}] ", elem->first, elem->second);
    System::Console::WriteLine();

    // construct a generic container
    Myhash_map::generic_container^ gc1 = %c1;
    for each (Myhash_map::value_type elem in gc1)
        System::Console::Write("[{0} {1}] ", elem->first, elem->second);
    System::Console::WriteLine();

    // get an element and display it
    Myhash_map::generic_iterator gcit = gc1->begin();
    Myhash_map::generic_value gcval = *gcit;
    System::Console::WriteLine("[{0} {1}] ", gcval->first, gcval->second);
    return (0);
    }
[a 1] [b 2] [c 3]
[a 1] [b 2] [c 3]
[a 1]

hash_map::hash_delegate

지정된 키와 일치하는 요소를 찾습니다.

구문

hasher^ hash_delegate();

설명

멤버 함수는 키 값을 정수로 변환하는 데 사용되는 대리자를 반환합니다. 키를 해시하는 데 사용합니다.

예시

// cliext_hash_map_hash_delegate.cpp
// compile with: /clr
#include <cliext/hash_map>

typedef cliext::hash_map<wchar_t, int> Myhash_map;
int main()
    {
    Myhash_map c1;
    Myhash_map::hasher^ myhash = c1.hash_delegate();

    System::Console::WriteLine("hash(L'a') = {0}", myhash(L'a'));
    System::Console::WriteLine("hash(L'b') = {0}", myhash(L'b'));
    return (0);
    }
hash(L'a') = 1616896120
hash(L'b') = 570892832

hash_map::hash_map

컨테이너 개체를 만듭니다.

구문

hash_map();
explicit hash_map(key_compare^ pred);
hash_map(key_compare^ pred, hasher^ hashfn);
hash_map(hash_map<Key, Mapped>% right);
hash_map(hash_map<Key, Mapped>^ right);
template<typename InIter>
    hash_maphash_map(InIter first, InIter last);
template<typename InIter>
    hash_map(InIter first, InIter last,
        key_compare^ pred);
template<typename InIter>
    hash_map(InIter first, InIter last,
        key_compare^ pred, hasher^ hashfn);
hash_map(System::Collections::Generic::IEnumerable<GValue>^ right);
hash_map(System::Collections::Generic::IEnumerable<GValue>^ right,
    key_compare^ pred);
hash_map(System::Collections::Generic::IEnumerable<GValue>^ right,
    key_compare^ pred, hasher^ hashfn);

매개 변수

first
삽입할 범위의 시작 부분입니다.

hashfn
버킷에 키를 매핑하는 해시 함수입니다.

last
삽입할 범위의 끝입니다.

pred
제어되는 시퀀스에 대한 조건자 순서 지정

right
삽입할 개체 또는 범위입니다.

설명

생성자:

hash_map();

는 기본 순서 조건 key_compare()자 및 기본 해시 함수를 사용하여 요소 없이 제어되는 시퀀스를 초기화합니다. 기본 순서 조건자 및 해시 함수를 사용하여 빈 초기 제어 시퀀스를 지정하는 데 사용합니다.

생성자:

explicit hash_map(key_compare^ pred);

는 요소 없이 순서 지정 조건 pred자 및 기본 해시 함수를 사용하여 제어되는 시퀀스를 초기화합니다. 지정된 순서 조건자와 기본 해시 함수를 사용하여 빈 초기 제어 시퀀스를 지정하는 데 사용합니다.

생성자:

hash_map(key_compare^ pred, hasher^ hashfn);

순서 조건자와 해시 함수hashfn를 사용하여 요소 pred없이 제어되는 시퀀스를 초기화합니다. 지정된 순서 조건자 및 해시 함수를 사용하여 빈 초기 제어 시퀀스를 지정하는 데 사용합니다.

생성자:

hash_map(hash_map<Key, Mapped>% right);

시퀀스 [right.begin(), right.end()), 기본 순서 조건자 및 기본 해시 함수를 사용하여 제어되는 시퀀스를 초기화합니다. 기본 순서 조건자 및 해시 함수를 사용하여 개체right에 의해 hash_map 제어되는 시퀀스의 복사본인 초기 제어 시퀀스를 지정하는 데 사용합니다.

생성자:

hash_map(hash_map<Key, Mapped>^ right);

시퀀스 [right->begin(), right->end()), 기본 순서 조건자 및 기본 해시 함수를 사용하여 제어되는 시퀀스를 초기화합니다. 기본 순서 조건자 및 해시 함수를 사용하여 개체right에 의해 hash_map 제어되는 시퀀스의 복사본인 초기 제어 시퀀스를 지정하는 데 사용합니다.

생성자:

template<typename InIter> hash_map(InIter first, InIter last);

시퀀스 [first, last), 기본 순서 조건자 및 기본 해시 함수를 사용하여 제어되는 시퀀스를 초기화합니다. 제어된 시퀀스를 기본 순서 조건자 및 해시 함수와 함께 다른 시퀀스의 복사본으로 만드는 데 사용합니다.

생성자:

template<typename InIter> hash_map(InIter first, InIter last, key_compare^ pred);

순서 조건자와 기본 해시 함수를 사용하여 시퀀스 [first, last), pred제어되는 시퀀스를 초기화합니다. 지정된 순서 조건자와 기본 해시 함수를 사용하여 제어되는 시퀀스를 다른 시퀀스의 복사본으로 만드는 데 사용합니다.

생성자:

template<typename InIter> hash_map(InIter first, InIter last, key_compare^ pred, hasher^ hashfn);

순서 조건자와 해시 함수hashfn를 사용하여 [first, last) pred시퀀스를 사용하여 제어되는 시퀀스를 초기화합니다. 지정된 순서 조건자 및 해시 함수를 사용하여 제어되는 시퀀스를 다른 시퀀스의 복사본으로 만드는 데 사용합니다.

생성자:

hash_map(System::Collections::Generic::IEnumerable<Key>^ right);

는 기본 순서 조건자와 기본 해시 함수를 사용하여 열거자가 right지정한 시퀀스를 사용하여 제어되는 시퀀스를 초기화합니다. 제어된 시퀀스를 기본 순서 조건자 및 해시 함수와 함께 열거자가 설명하는 다른 시퀀스의 복사본으로 만드는 데 사용합니다.

생성자:

hash_map(System::Collections::Generic::IEnumerable<Key>^ right, key_compare^ pred);

는 순서 조건자와 기본 해시 함수를 사용하여 열거자가 right지정한 pred시퀀스를 사용하여 제어되는 시퀀스를 초기화합니다. 제어된 시퀀스를 지정된 순서 조건자 및 기본 해시 함수를 사용하여 열거자가 설명하는 다른 시퀀스의 복사본으로 만드는 데 사용합니다.

생성자:

hash_map(System::Collections::Generic::IEnumerable<Key>^ right, key_compare^ pred, hasher^ hashfn);

순서 조건자와 해시 함수hashfn를 사용하여 열거자가 rightpred지정한 시퀀스를 사용하여 제어되는 시퀀스를 초기화합니다. 제어된 시퀀스를 지정된 순서 조건자 및 해시 함수를 사용하여 열거자가 설명하는 다른 시퀀스의 복사본으로 만드는 데 사용합니다.

예시

// cliext_hash_map_construct.cpp
// compile with: /clr
#include <cliext/hash_map>

int myfun(wchar_t key)
    { // hash a key
    return (key ^ 0xdeadbeef);
    }

typedef cliext::hash_map<wchar_t, int> Myhash_map;
int main()
    {
// construct an empty container
    Myhash_map c1;
    System::Console::WriteLine("size() = {0}", c1.size());

    c1.insert(Myhash_map::make_value(L'a', 1));
    c1.insert(Myhash_map::make_value(L'b', 2));
    c1.insert(Myhash_map::make_value(L'c', 3));
    for each (Myhash_map::value_type elem in c1)
        System::Console::Write("[{0} {1}] ", elem->first, elem->second);
    System::Console::WriteLine();

    // construct with an ordering rule
    Myhash_map c2 = cliext::greater_equal<wchar_t>();
    System::Console::WriteLine("size() = {0}", c2.size());

    c2.insert(c1.begin(), c1.end());
    for each (Myhash_map::value_type elem in c2)
        System::Console::Write("[{0} {1}] ", elem->first, elem->second);
    System::Console::WriteLine();

    // construct with an ordering rule and hash function
    Myhash_map c2h(cliext::greater_equal<wchar_t>(),
        gcnew Myhash_map::hasher(&myfun));
    System::Console::WriteLine("size() = {0}", c2h.size());

    c2h.insert(c1.begin(), c1.end());
    for each (Myhash_map::value_type elem in c2h)
        System::Console::Write("[{0} {1}] ", elem->first, elem->second);
    System::Console::WriteLine();
    System::Console::WriteLine();

    // construct with an iterator range
    Myhash_map c3(c1.begin(), c1.end());
    for each (Myhash_map::value_type elem in c3)
        System::Console::Write("[{0} {1}] ", elem->first, elem->second);
    System::Console::WriteLine();

    // construct with an iterator range and an ordering rule
    Myhash_map c4(c1.begin(), c1.end(),
        cliext::greater_equal<wchar_t>());
    for each (Myhash_map::value_type elem in c4)
        System::Console::Write("[{0} {1}] ", elem->first, elem->second);
    System::Console::WriteLine();

    // construct with an iterator range and an ordering rule and hash function
    Myhash_map c4h(c1.begin(), c1.end(),
        cliext::greater_equal<wchar_t>(),
        gcnew Myhash_map::hasher(&myfun));
    for each (Myhash_map::value_type elem in c4h)
        System::Console::Write("[{0} {1}] ", elem->first, elem->second);
    System::Console::WriteLine();
    System::Console::WriteLine();

    // construct with an enumeration
    Myhash_map c5(   // NOTE: cast is not needed
        (System::Collections::Generic::IEnumerable<
            Myhash_map::value_type>^)%c3);
    for each (Myhash_map::value_type elem in c5)
        System::Console::Write("[{0} {1}] ", elem->first, elem->second);
    System::Console::WriteLine();

    // construct with an enumeration and an ordering rule
    Myhash_map c6(   // NOTE: cast is not needed
        (System::Collections::Generic::IEnumerable<
            Myhash_map::value_type>^)%c3,
                cliext::greater_equal<wchar_t>());
    for each (Myhash_map::value_type elem in c6)
        System::Console::Write("[{0} {1}] ", elem->first, elem->second);
    System::Console::WriteLine();

    // construct with an enumeration and an ordering rule and hash function
    Myhash_map c6h(   // NOTE: cast is not needed
        (System::Collections::Generic::IEnumerable<
            Myhash_map::value_type>^)%c3,
                cliext::greater_equal<wchar_t>(),
                gcnew Myhash_map::hasher(&myfun));
    for each (Myhash_map::value_type elem in c6h)
        System::Console::Write("[{0} {1}] ", elem->first, elem->second);
    System::Console::WriteLine();
    System::Console::WriteLine();

    // construct by copying another container
    Myhash_map c7(c4);
    for each (Myhash_map::value_type elem in c7)
        System::Console::Write("[{0} {1}] ", elem->first, elem->second);
    System::Console::WriteLine();

    // construct by copying a container handle
    Myhash_map c8(%c3);
    for each (Myhash_map::value_type elem in c8)
        System::Console::Write("[{0} {1}] ", elem->first, elem->second);
    System::Console::WriteLine();
    return (0);
    }
size() = 0
[a 1] [b 2] [c 3]
size() = 0
[a 1] [b 2] [c 3]
size() = 0
[c 3] [b 2] [a 1]

[a 1] [b 2] [c 3]
[a 1] [b 2] [c 3]
[c 3] [b 2] [a 1]

[a 1] [b 2] [c 3]
[a 1] [b 2] [c 3]
[c 3] [b 2] [a 1]

[a 1] [b 2] [c 3]
[a 1] [b 2] [c 3]

hash_map::hasher

키에 대한 해시 대리자입니다.

구문

Microsoft::VisualC::StlClr::UnaryDelegate<GKey, int>
    hasher;

설명

이 형식은 키 값을 정수로 변환하는 대리자를 설명합니다.

예시

// cliext_hash_map_hasher.cpp
// compile with: /clr
#include <cliext/hash_map>

typedef cliext::hash_map<wchar_t, int> Myhash_map;
int main()
    {
    Myhash_map c1;
    Myhash_map::hasher^ myhash = c1.hash_delegate();

    System::Console::WriteLine("hash(L'a') = {0}", myhash(L'a'));
    System::Console::WriteLine("hash(L'b') = {0}", myhash(L'b'));
    return (0);
    }
hash(L'a') = 1616896120
hash(L'b') = 570892832

hash_map::insert

요소를 추가합니다.

구문

cliext::pair<iterator, bool> insert(value_type val);
iterator insert(iterator where, value_type val);
template<typename InIter>
    void insert(InIter first, InIter last);
void insert(System::Collections::Generic::IEnumerable<value_type>^ right);

매개 변수

first
삽입할 범위의 시작 부분입니다.

last
삽입할 범위의 끝입니다.

right
삽입할 열거형입니다.

val
삽입할 키 값입니다.

where
삽입할 컨테이너의 위치(힌트만 해당).

설명

각 멤버 함수는 다시 기본 피연산자에서 지정한 시퀀스를 삽입합니다.

첫 번째 멤버 함수는 값 val이 있는 요소를 삽입하기 위해 노력하고 값 쌍을 반환합니다 X. true이면 X.second 새로 삽입된 요소를 지정하고, X.first 그렇지 않으면 X.first 이미 존재하고 새 요소가 삽입되지 않은 동일한 순서로 요소를 지정합니다. 단일 요소를 삽입하는 데 사용합니다.

두 번째 멤버 함수는 힌트로 사용하여 whereval이 있는 요소를 삽입하고 새로 삽입된 요소를 지정하는 반복기를 반환합니다. 이를 사용하여 알고 있는 요소 옆에 있을 수 있는 단일 요소를 삽입합니다.

세 번째 멤버 함수는 시퀀스 [, last)를first 삽입합니다. 다른 시퀀스에서 복사한 요소를 0개 이상 삽입하는 데 사용합니다.

네 번째 멤버 함수는 .에 의해 right지정된 시퀀스를 삽입합니다. 열거자가 설명하는 시퀀스를 삽입하는 데 사용합니다.

각 요소 삽입은 제어되는 시퀀스의 요소 수 로그에 비례하여 시간이 걸립니다. 그러나 삽입 지점 옆의 요소를 지정하는 힌트가 있으면 분할 상환 상수 시간에 삽입이 발생할 수 있습니다.

예시

// cliext_hash_map_insert.cpp
// compile with: /clr
#include <cliext/hash_map>

typedef cliext::hash_map<wchar_t, int> Myhash_map;
typedef Myhash_map::pair_iter_bool Pairib;
int main()
    {
    Myhash_map c1;
    c1.insert(Myhash_map::make_value(L'a', 1));
    c1.insert(Myhash_map::make_value(L'b', 2));
    c1.insert(Myhash_map::make_value(L'c', 3));

    // display contents " [a 1] [b 2] [c 3]"
    for each (Myhash_map::value_type elem in c1)
        System::Console::Write("[{0} {1}] ", elem->first, elem->second);
    System::Console::WriteLine();

    // insert a single value, unique and duplicate
    Pairib pair1 =
        c1.insert(Myhash_map::make_value(L'x', 24));
    System::Console::WriteLine("insert([L'x' 24]) = [{0} {1}] {2}",
        pair1.first->first, pair1.first->second, pair1.second);

    pair1 = c1.insert(Myhash_map::make_value(L'b', 2));
    System::Console::WriteLine("insert([L'b' 2]) = [{0} {1}] {2}",
        pair1.first->first, pair1.first->second, pair1.second);

    for each (Myhash_map::value_type elem in c1)
        System::Console::Write("[{0} {1}] ", elem->first, elem->second);
    System::Console::WriteLine();

    // insert a single value with hint
    Myhash_map::iterator it =
        c1.insert(c1.begin(), Myhash_map::make_value(L'y', 25));
    System::Console::WriteLine("insert(begin(), [L'y' 25]) = [{0} {1}]",
        it->first, it->second);
    for each (Myhash_map::value_type elem in c1)
        System::Console::Write("[{0} {1}] ", elem->first, elem->second);
    System::Console::WriteLine();

    // insert an iterator range
    Myhash_map c2;
    it = c1.end();
    c2.insert(c1.begin(), --it);
    for each (Myhash_map::value_type elem in c2)
        System::Console::Write("[{0} {1}] ", elem->first, elem->second);
    System::Console::WriteLine();

    // insert an enumeration
    Myhash_map c3;
    c3.insert(   // NOTE: cast is not needed
        (System::Collections::Generic::
            IEnumerable<Myhash_map::value_type>^)%c1);
    for each (Myhash_map::value_type elem in c3)
        System::Console::Write("[{0} {1}] ", elem->first, elem->second);
    System::Console::WriteLine();
    return (0);
    }
[a 1] [b 2] [c 3]
insert([L'x' 24]) = [x 24] True
insert([L'b' 2]) = [b 2] False
[a 1] [b 2] [c 3] [x 24]
insert(begin(), [L'y' 25]) = [y 25]
[a 1] [b 2] [c 3] [x 24] [y 25]
[a 1] [b 2] [c 3] [x 24]
[a 1] [b 2] [c 3] [x 24] [y 25]

hash_map::iterator

제어되는 시퀀스에 대한 반복기의 형식입니다.

구문

typedef T1 iterator;

설명

형식은 제어되는 시퀀스에 대한 양방향 반복기 역할을 할 수 있는 지정되지 않은 형식 T1 의 개체를 설명합니다.

예시

// cliext_hash_map_iterator.cpp
// compile with: /clr
#include <cliext/hash_map>

typedef cliext::hash_map<wchar_t, int> Myhash_map;
int main()
    {
    Myhash_map c1;
    c1.insert(Myhash_map::make_value(L'a', 1));
    c1.insert(Myhash_map::make_value(L'b', 2));
    c1.insert(Myhash_map::make_value(L'c', 3));

    // display contents " [a 1] [b 2] [c 3]"
    Myhash_map::iterator it = c1.begin();
    for (; it != c1.end(); ++it)
        System::Console::Write("[{0} {1}] ", it->first, it->second);
    System::Console::WriteLine();
    return (0);
    }
[a 1] [b 2] [c 3]

hash_map::key_comp

두 키에 대한 순서 지정 대리자를 복사합니다.

구문

key_compare^key_comp();

설명

멤버 함수는 제어되는 시퀀스를 정렬하는 데 사용되는 순서 지정 대리자를 반환합니다. 두 키를 비교하는 데 사용합니다.

예시

// cliext_hash_map_key_comp.cpp
// compile with: /clr
#include <cliext/hash_map>

typedef cliext::hash_map<wchar_t, int> Myhash_map;
int main()
    {
    Myhash_map c1;
    Myhash_map::key_compare^ kcomp = c1.key_comp();

    System::Console::WriteLine("compare(L'a', L'a') = {0}",
        kcomp(L'a', L'a'));
    System::Console::WriteLine("compare(L'a', L'b') = {0}",
        kcomp(L'a', L'b'));
    System::Console::WriteLine("compare(L'b', L'a') = {0}",
        kcomp(L'b', L'a'));
    System::Console::WriteLine();

    // test a different ordering rule
    Myhash_map c2 = cliext::greater<wchar_t>();
    kcomp = c2.key_comp();

    System::Console::WriteLine("compare(L'a', L'a') = {0}",
        kcomp(L'a', L'a'));
    System::Console::WriteLine("compare(L'a', L'b') = {0}",
        kcomp(L'a', L'b'));
    System::Console::WriteLine("compare(L'b', L'a') = {0}",
        kcomp(L'b', L'a'));
    return (0);
    }
compare(L'a', L'a') = True
compare(L'a', L'b') = True
compare(L'b', L'a') = False

compare(L'a', L'a') = False
compare(L'a', L'b') = False
compare(L'b', L'a') = True

hash_map::key_compare

두 키에 대한 순서 지정 대리자입니다.

구문

Microsoft::VisualC::StlClr::BinaryDelegate<GKey, GKey, bool>
    key_compare;

설명

형식은 해당 키 인수의 순서를 결정하는 대리자의 동의어입니다.

예시

// cliext_hash_map_key_compare.cpp
// compile with: /clr
#include <cliext/hash_map>

typedef cliext::hash_map<wchar_t, int> Myhash_map;
int main()
    {
    Myhash_map c1;
    Myhash_map::key_compare^ kcomp = c1.key_comp();

    System::Console::WriteLine("compare(L'a', L'a') = {0}",
        kcomp(L'a', L'a'));
    System::Console::WriteLine("compare(L'a', L'b') = {0}",
        kcomp(L'a', L'b'));
    System::Console::WriteLine("compare(L'b', L'a') = {0}",
        kcomp(L'b', L'a'));
    System::Console::WriteLine();

    // test a different ordering rule
    Myhash_map c2 = cliext::greater<wchar_t>();
    kcomp = c2.key_comp();

    System::Console::WriteLine("compare(L'a', L'a') = {0}",
        kcomp(L'a', L'a'));
    System::Console::WriteLine("compare(L'a', L'b') = {0}",
        kcomp(L'a', L'b'));
    System::Console::WriteLine("compare(L'b', L'a') = {0}",
        kcomp(L'b', L'a'));
    return (0);
    }
compare(L'a', L'a') = True
compare(L'a', L'b') = True
compare(L'b', L'a') = False

compare(L'a', L'a') = False
compare(L'a', L'b') = False
compare(L'b', L'a') = True

hash_map::key_type

정렬 키의 형식입니다.

구문

typedef Key key_type;

설명

이 형식은 템플릿 매개 변수 Key의 동의어입니다.

예시

// cliext_hash_map_key_type.cpp
// compile with: /clr
#include <cliext/hash_map>

typedef cliext::hash_map<wchar_t, int> Myhash_map;
int main()
    {
    Myhash_map c1;
    c1.insert(Myhash_map::make_value(L'a', 1));
    c1.insert(Myhash_map::make_value(L'b', 2));
    c1.insert(Myhash_map::make_value(L'c', 3));

    // display contents " [a 1] [b 2] [c 3]" using key_type
    for (Myhash_map::iterator it = c1.begin(); it != c1.end(); ++it)
        {   // store element in key_type object
        Myhash_map::key_type val = it->first;

        System::Console::Write("{0} ", val);
        }
    System::Console::WriteLine();
    return (0);
    }
a b c

hash_map::load_factor

버킷당 평균 요소 수를 계산합니다.

구문

float load_factor();

설명

멤버 함수는 (float)size() / bucket_count()를 반환합니다. 이를 사용하여 평균 버킷 크기를 결정합니다.

예시

// cliext_hash_map_load_factor.cpp
// compile with: /clr
#include <cliext/hash_map>

typedef cliext::hash_map<wchar_t, int> Myhash_map;
int main()
    {
    Myhash_map c1 = gcnew Myhash_map;
    c1.insert(Myhash_map::make_value(L'a', 1));
    c1.insert(Myhash_map::make_value(L'b', 2));
    c1.insert(Myhash_map::make_value(L'c', 3));

    // display contents " [a 1] [b 2] [c 3]"
    for each (Myhash_map::value_type elem in c1)
        System::Console::Write("[{0} {1}] ", elem->first, elem->second);
    System::Console::WriteLine();

    // inspect current parameters
    System::Console::WriteLine("bucket_count() = {0}", c1.bucket_count());
    System::Console::WriteLine("load_factor() = {0}", c1.load_factor());
    System::Console::WriteLine("max_load_factor() = {0}",
        c1.max_load_factor());
    System::Console::WriteLine();

    // change max_load_factor and redisplay
    c1.max_load_factor(0.25f);
    System::Console::WriteLine("bucket_count() = {0}", c1.bucket_count());
    System::Console::WriteLine("load_factor() = {0}", c1.load_factor());
    System::Console::WriteLine("max_load_factor() = {0}",
        c1.max_load_factor());
    System::Console::WriteLine();

    // rehash and redisplay
    c1.rehash(100);
    System::Console::WriteLine("bucket_count() = {0}", c1.bucket_count());
    System::Console::WriteLine("load_factor() = {0}", c1.load_factor());
    System::Console::WriteLine("max_load_factor() = {0}",
        c1.max_load_factor());
    return (0);
    }
[a 1] [b 2] [c 3]
bucket_count() = 16
load_factor() = 0.1875
max_load_factor() = 4

bucket_count() = 16
load_factor() = 0.1875
max_load_factor() = 0.25

bucket_count() = 128
load_factor() = 0.0234375
max_load_factor() = 0.25

hash_map::lower_bound

지정된 키와 일치하는 범위의 시작을 찾습니다.

구문

iterator lower_bound(key_type key);

매개 변수

key
검색할 키 값입니다.

설명

멤버 함수는 제어되는 시퀀스에서 동일한 버킷 key 으로 해시하고 동일한 순서를 사용하는 첫 번째 요소를 X 결정합니다key. 이러한 요소가 없으면 반환 end()됩니다. 그렇지 않으면 지정하는 반복기를 반환합니다 X. 이를 사용하여 지정된 키와 일치하는 제어된 시퀀스에서 현재 요소 시퀀스의 시작을 찾습니다.

예시

// cliext_hash_map_lower_bound.cpp
// compile with: /clr
#include <cliext/hash_map>

typedef cliext::hash_map<wchar_t, int> Myhash_map;
int main()
    {
    Myhash_map c1;
    c1.insert(Myhash_map::make_value(L'a', 1));
    c1.insert(Myhash_map::make_value(L'b', 2));
    c1.insert(Myhash_map::make_value(L'c', 3));

    // display contents " [a 1] [b 2] [c 3]"
    for each (Myhash_map::value_type elem in c1)
        System::Console::Write("[{0} {1}] ", elem->first, elem->second);
    System::Console::WriteLine();

    System::Console::WriteLine("lower_bound(L'x')==end() = {0}",
        c1.lower_bound(L'x') == c1.end());

    Myhash_map::iterator it = c1.lower_bound(L'a');
    System::Console::WriteLine("*lower_bound(L'a') = [{0} {1}]",
        it->first, it->second);
    it = c1.lower_bound(L'b');
    System::Console::WriteLine("*lower_bound(L'b') = [{0} {1}]",
        it->first, it->second);
    return (0);
    }
[a 1] [b 2] [c 3]
lower_bound(L'x')==end() = True
*lower_bound(L'a') = [a 1]
*lower_bound(L'b') = [b 2]

hash_map::make_value

값 개체를 생성합니다.

구문

static value_type make_value(key_type key, mapped_type mapped);

매개 변수

key
사용할 키 값입니다.

mapped
검색할 매핑된 값입니다.

설명

멤버 함수는 키가 있고 매핑된 값이 key 있는 개체를 반환 value_type 합니다mapped. 이 함수를 사용하여 다른 여러 멤버 함수와 함께 사용하기에 적합한 개체를 작성합니다.

예시

// cliext_hash_map_make_value.cpp
// compile with: /clr
#include <cliext/hash_map>

typedef cliext::hash_map<wchar_t, int> Myhash_map;
int main()
    {
    Myhash_map c1;
    c1.insert(Myhash_map::make_value(L'a', 1));
    c1.insert(Myhash_map::make_value(L'b', 2));
    c1.insert(Myhash_map::make_value(L'c', 3));

    // display contents " [a 1] [b 2] [c 3]"
    for each (Myhash_map::value_type elem in c1)
        System::Console::Write("[{0} {1}] ", elem->first, elem->second);
    System::Console::WriteLine();
    return (0);
    }
[a 1] [b 2] [c 3]

hash_map::mapped_type

각 키와 연결된 매핑된 값의 형식입니다.

구문

typedef Mapped mapped_type;

설명

이 형식은 템플릿 매개 변수 Mapped의 동의어입니다.

예시

// cliext_hash_map_mapped_type.cpp
// compile with: /clr
#include <cliext/hash_map>

typedef cliext::hash_map<wchar_t, int> Myhash_map;
int main()
    {
    Myhash_map c1;
    c1.insert(Myhash_map::make_value(L'a', 1));
    c1.insert(Myhash_map::make_value(L'b', 2));
    c1.insert(Myhash_map::make_value(L'c', 3));

    // display contents " [a 1] [b 2] [c 3]" using mapped_type
    for (Myhash_map::iterator it = c1.begin(); it != c1.end(); ++it)
        {   // store element in mapped_type object
        Myhash_map::mapped_type val = it->second;

        System::Console::Write("{0} ", val);
        }
    System::Console::WriteLine();
    return (0);
    }
1 2 3

hash_map::max_load_factor

버킷당 최대 요소 수를 가져오거나 설정합니다.

구문

float max_load_factor();
void max_load_factor(float new_factor);

매개 변수

new_factor
저장할 새 최대 로드 요소입니다.

설명

첫 번째 멤버 함수는 현재 저장된 최대 로드 팩터를 반환합니다. 이를 사용하여 최대 평균 버킷 크기를 결정합니다.

두 번째 멤버 함수는 저장소 최대 로드 팩터를 .로 바 new_factor꿉니다. 후속 삽입까지 자동 다시 해시가 발생하지 않습니다.

예시

// cliext_hash_map_max_load_factor.cpp
// compile with: /clr
#include <cliext/hash_map>

typedef cliext::hash_map<wchar_t, int> Myhash_map;
int main()
    {
    Myhash_map c1 = gcnew Myhash_map;
    c1.insert(Myhash_map::make_value(L'a', 1));
    c1.insert(Myhash_map::make_value(L'b', 2));
    c1.insert(Myhash_map::make_value(L'c', 3));

    // display contents " [a 1] [b 2] [c 3]"
    for each (Myhash_map::value_type elem in c1)
        System::Console::Write("[{0} {1}] ", elem->first, elem->second);
    System::Console::WriteLine();

    // inspect current parameters
    System::Console::WriteLine("bucket_count() = {0}", c1.bucket_count());
    System::Console::WriteLine("load_factor() = {0}", c1.load_factor());
    System::Console::WriteLine("max_load_factor() = {0}",
        c1.max_load_factor());
    System::Console::WriteLine();

    // change max_load_factor and redisplay
    c1.max_load_factor(0.25f);
    System::Console::WriteLine("bucket_count() = {0}", c1.bucket_count());
    System::Console::WriteLine("load_factor() = {0}", c1.load_factor());
    System::Console::WriteLine("max_load_factor() = {0}",
        c1.max_load_factor());
    System::Console::WriteLine();

    // rehash and redisplay
    c1.rehash(100);
    System::Console::WriteLine("bucket_count() = {0}", c1.bucket_count());
    System::Console::WriteLine("load_factor() = {0}", c1.load_factor());
    System::Console::WriteLine("max_load_factor() = {0}",
        c1.max_load_factor());
    return (0);
    }
[a 1] [b 2] [c 3]
bucket_count() = 16
load_factor() = 0.1875
max_load_factor() = 4

bucket_count() = 16
load_factor() = 0.1875
max_load_factor() = 0.25

bucket_count() = 128
load_factor() = 0.0234375
max_load_factor() = 0.25

hash_map::operator=

제어되는 시퀀스를 바꿉니다.

구문

hash_map<Key, Mapped>% operator=(hash_map<Key, Mapped>% right);

매개 변수

right
복사할 컨테이너입니다.

설명

멤버 연산자는 개체에 복사한 다음 반환합니다 right*this. 이를 사용하여 제어되는 시퀀스를 right의 제어되는 시퀀스 복사본으로 대체합니다.

예시

// cliext_hash_map_operator_as.cpp
// compile with: /clr
#include <cliext/hash_map>

typedef cliext::hash_map<wchar_t, int> Myhash_map;
int main()
    {
    Myhash_map c1;
    c1.insert(Myhash_map::make_value(L'a', 1));
    c1.insert(Myhash_map::make_value(L'b', 2));
    c1.insert(Myhash_map::make_value(L'c', 3));

    // display contents " [a 1] [b 2] [c 3]"
    for each (Myhash_map::value_type elem in c1)
        System::Console::Write("[{0} {1}] ", elem->first, elem->second);
    System::Console::WriteLine();

    // assign to a new container
    Myhash_map c2;
    c2 = c1;
// display contents " [a 1] [b 2] [c 3]"
    for each (Myhash_map::value_type elem in c2)
        System::Console::Write("[{0} {1}] ", elem->first, elem->second);
    System::Console::WriteLine();
    return (0);
    }
[a 1] [b 2] [c 3]
[a 1] [b 2] [c 3]

hash_map::operator[]

연결된 매핑된 값에 키를 지도.

구문

mapped_type operator[](key_type key);

매개 변수

key
검색할 키 값입니다.

설명

멤버 함수는 동일한 순서로 요소를 찾기 위해 노력합니다 key. 이 값을 찾으면 연결된 매핑된 값이 반환됩니다. 그렇지 않으면 연결된(기본값) 매핑된 값을 삽입 value_type(key, mapped_type()) 하고 반환합니다. 연결된 키가 지정된 경우 매핑된 값을 조회하거나 키가 없는 경우 키에 대한 항목이 있는지 확인하는 데 사용합니다.

예시

// cliext_hash_map_operator_sub.cpp
// compile with: /clr
#include <cliext/hash_map>

typedef cliext::hash_map<wchar_t, int> Myhash_map;
int main()
    {
    Myhash_map c1;
    c1.insert(Myhash_map::make_value(L'a', 1));
    c1.insert(Myhash_map::make_value(L'b', 2));
    c1.insert(Myhash_map::make_value(L'c', 3));

    // display contents " [a 1] [b 2] [c 3]"
    for each (Myhash_map::value_type elem in c1)
        System::Console::Write("[{0} {1}] ", elem->first, elem->second);
    System::Console::WriteLine();

    System::Console::WriteLine("c1[{0}] = {1}",
        L'A', c1[L'A']);
    System::Console::WriteLine("c1[{0}] = {1}",
        L'b', c1[L'b']);

    // redisplay altered contents
    for each (Myhash_map::value_type elem in c1)
        System::Console::Write("[{0} {1}] ", elem->first, elem->second);
    System::Console::WriteLine();

    // alter mapped values and redisplay
    c1[L'A'] = 10;
    c1[L'c'] = 13;
    for each (Myhash_map::value_type elem in c1)
        System::Console::Write("[{0} {1}] ", elem->first, elem->second);
    System::Console::WriteLine();
    return (0);
    }
[a 1] [b 2] [c 3]
c1[A] = 0
c1[b] = 2
[a 1] [A 0] [b 2] [c 3]
[a 1] [A 10] [b 2] [c 13]

hash_map::rbegin

제어되는 역방향 시퀀스의 시작을 지정합니다.

구문

reverse_iterator rbegin();

설명

멤버 함수는 제어되는 시퀀스의 마지막 요소를 지정하거나 빈 시퀀스의 시작 부분 바로 너머를 지정하는 역방향 반복기를 반환합니다. 따라서 역방향 시퀀스를 지정합니다 beginning . 이를 사용하여 역순으로 표시되는 제어되는 시퀀스의 시작을 지정 current 하는 반복기를 가져오지만 제어되는 시퀀스의 길이가 변경되면 해당 상태 변경될 수 있습니다.

예시

// cliext_hash_map_rbegin.cpp
// compile with: /clr
#include <cliext/hash_map>

typedef cliext::hash_map<wchar_t, int> Myhash_map;
int main()
    {
    Myhash_map c1;
    c1.insert(Myhash_map::make_value(L'a', 1));
    c1.insert(Myhash_map::make_value(L'b', 2));
    c1.insert(Myhash_map::make_value(L'c', 3));

    // display contents " [a 1] [b 2] [c 3]"
    for each (Myhash_map::value_type elem in c1)
        System::Console::Write("[{0} {1}] ", elem->first, elem->second);
    System::Console::WriteLine();

    // inspect first two items in reversed sequence
    Myhash_map::reverse_iterator rit = c1.rbegin();
    System::Console::WriteLine("*rbegin() = [{0} {1}]",
        rit->first, rit->second);
    ++rit;
    System::Console::WriteLine("*++rbegin() = [{0} {1}]",
        rit->first, rit->second);
    return (0);
    }
[a 1] [b 2] [c 3]
*rbegin() = [c 3]
*++rbegin() = [b 2]

hash_map::reference

요소에 대한 참조의 형식입니다.

구문

typedef value_type% reference;

설명

이 형식은 요소에 대한 참조를 설명합니다.

예시

// cliext_hash_map_reference.cpp
// compile with: /clr
#include <cliext/hash_map>

typedef cliext::hash_map<wchar_t, int> Myhash_map;
int main()
    {
    Myhash_map c1;
    c1.insert(Myhash_map::make_value(L'a', 1));
    c1.insert(Myhash_map::make_value(L'b', 2));
    c1.insert(Myhash_map::make_value(L'c', 3));

    // display contents " [a 1] [b 2] [c 3]"
    Myhash_map::iterator it = c1.begin();
    for (; it != c1.end(); ++it)
        {   // get a reference to an element
        Myhash_map::reference ref = *it;
        System::Console::Write("[{0} {1}] ", ref->first, ref->second);
        }
    System::Console::WriteLine();
    return (0);
    }
[a 1] [b 2] [c 3]

hash_map::rehash

해시 테이블을 다시 빌드합니다.

구문

void rehash();

설명

멤버 함수는 해시 테이블을 다시 빌드하여 확인 load_factor() <= max_load_factor()합니다. 그렇지 않으면 해시 테이블의 크기는 삽입 후에 필요에 따라 증가합니다. (크기는 자동으로 감소하지 않습니다.) 해시 테이블의 크기를 조정하는 데 사용합니다.

예시

// cliext_hash_map_rehash.cpp
// compile with: /clr
#include <cliext/hash_map>

typedef cliext::hash_map<wchar_t, int> Myhash_map;
int main()
    {
    Myhash_map c1 = gcnew Myhash_map;
    c1.insert(Myhash_map::make_value(L'a', 1));
    c1.insert(Myhash_map::make_value(L'b', 2));
    c1.insert(Myhash_map::make_value(L'c', 3));

    // display contents " [a 1] [b 2] [c 3]"
    for each (Myhash_map::value_type elem in c1)
        System::Console::Write("[{0} {1}] ", elem->first, elem->second);
    System::Console::WriteLine();

    // inspect current parameters
    System::Console::WriteLine("bucket_count() = {0}", c1.bucket_count());
    System::Console::WriteLine("load_factor() = {0}", c1.load_factor());
    System::Console::WriteLine("max_load_factor() = {0}",
        c1.max_load_factor());
    System::Console::WriteLine();

    // change max_load_factor and redisplay
    c1.max_load_factor(0.25f);
    System::Console::WriteLine("bucket_count() = {0}", c1.bucket_count());
    System::Console::WriteLine("load_factor() = {0}", c1.load_factor());
    System::Console::WriteLine("max_load_factor() = {0}",
        c1.max_load_factor());
    System::Console::WriteLine();

    // rehash and redisplay
    c1.rehash(100);
    System::Console::WriteLine("bucket_count() = {0}", c1.bucket_count());
    System::Console::WriteLine("load_factor() = {0}", c1.load_factor());
    System::Console::WriteLine("max_load_factor() = {0}",
        c1.max_load_factor());
    return (0);
    }
[a 1] [b 2] [c 3]
bucket_count() = 16
load_factor() = 0.1875
max_load_factor() = 4

bucket_count() = 16
load_factor() = 0.1875
max_load_factor() = 0.25

bucket_count() = 128
load_factor() = 0.0234375
max_load_factor() = 0.25

hash_map::rend

제어되는 역방향 시퀀스의 끝을 지정합니다.

구문

reverse_iterator rend();

설명

멤버 함수는 제어되는 시퀀스의 시작 부분 바로 앞을 가리키는 역방향 반복기를 반환합니다. 따라서 역방향 시퀀스를 지정합니다 end . 이를 사용하여 제어되는 시퀀스의 끝을 역순으로 표시하는 current 반복기를 가져오지만 제어되는 시퀀스의 길이가 변경되면 해당 상태 변경될 수 있습니다.

예시

// cliext_hash_map_rend.cpp
// compile with: /clr
#include <cliext/hash_map>

typedef cliext::hash_map<wchar_t, int> Myhash_map;
int main()
    {
    Myhash_map c1;
    c1.insert(Myhash_map::make_value(L'a', 1));
    c1.insert(Myhash_map::make_value(L'b', 2));
    c1.insert(Myhash_map::make_value(L'c', 3));

    // display contents " [a 1] [b 2] [c 3]"
    for each (Myhash_map::value_type elem in c1)
        System::Console::Write("[{0} {1}] ", elem->first, elem->second);
    System::Console::WriteLine();

    // inspect first two items in reversed sequence
    Myhash_map::reverse_iterator rit = c1.rend();
    --rit;
    --rit;
    System::Console::WriteLine("*-- --rend() = [{0} {1}]",
        rit->first, rit->second);
    ++rit;
    System::Console::WriteLine("*--rend() = [{0} {1}]",
        rit->first, rit->second);
    return (0);
    }
[a 1] [b 2] [c 3]
*-- --rend() = [b 2]
*--rend() = [a 1]

hash_map::reverse_iterator

제어되는 시퀀스에 대한 반대 반복기의 형식입니다.

구문

typedef T3 reverse_iterator;

설명

이 형식은 제어된 시퀀스에 대해 반대 반복기로 사용될 수 있는 지정되지 않은 T3 형식의 개체를 설명합니다.

예시

// cliext_hash_map_reverse_iterator.cpp
// compile with: /clr
#include <cliext/hash_map>

typedef cliext::hash_map<wchar_t, int> Myhash_map;
int main()
    {
    Myhash_map c1;
    c1.insert(Myhash_map::make_value(L'a', 1));
    c1.insert(Myhash_map::make_value(L'b', 2));
    c1.insert(Myhash_map::make_value(L'c', 3));

    // display contents " [a 1] [b 2] [c 3]" reversed
    Myhash_map::reverse_iterator rit = c1.rbegin();
    for (; rit != c1.rend(); ++rit)
        System::Console::Write("[{0} {1}] ", rit->first, rit->second);
    System::Console::WriteLine();
    return (0);
    }
[c 3] [b 2] [a 1]

hash_map::size

요소 수를 계산합니다.

구문

size_type size();

설명

멤버 함수는 제어되는 시퀀스의 길이를 반환합니다. 이를 사용하여 현재 제어되는 시퀀스에 있는 요소 수를 확인합니다. 시퀀스의 크기가 0이 아닌지 여부만 있으면 다음을 참조하세요 hash_map::empty.

예시

// cliext_hash_map_size.cpp
// compile with: /clr
#include <cliext/hash_map>

typedef cliext::hash_map<wchar_t, int> Myhash_map;
int main()
    {
    Myhash_map c1;
    c1.insert(Myhash_map::make_value(L'a', 1));
    c1.insert(Myhash_map::make_value(L'b', 2));
    c1.insert(Myhash_map::make_value(L'c', 3));

    // display contents " [a 1] [b 2] [c 3]"
    for each (Myhash_map::value_type elem in c1)
        System::Console::Write("[{0} {1}] ", elem->first, elem->second);
    System::Console::WriteLine();

    // clear the container and reinspect
    c1.clear();
    System::Console::WriteLine("size() = {0} after clearing", c1.size());

    // add elements and clear again
    c1.insert(Myhash_map::make_value(L'd', 4));
    c1.insert(Myhash_map::make_value(L'e', 5));
    System::Console::WriteLine("size() = {0} after adding 2", c1.size());
    return (0);
    }
[a 1] [b 2] [c 3]
size() = 0 after clearing
size() = 2 after adding 2

hash_map::size_type

두 요소 사이의 부호가 있는 거리의 형식입니다.

구문

typedef int size_type;

설명

이 형식은 음수가 아닌 요소 수를 설명합니다.

예시

// cliext_hash_map_size_type.cpp
// compile with: /clr
#include <cliext/hash_map>

typedef cliext::hash_map<wchar_t, int> Myhash_map;
int main()
    {
    Myhash_map c1;
    c1.insert(Myhash_map::make_value(L'a', 1));
    c1.insert(Myhash_map::make_value(L'b', 2));
    c1.insert(Myhash_map::make_value(L'c', 3));

    // display contents " [a 1] [b 2] [c 3]"
    for each (Myhash_map::value_type elem in c1)
        System::Console::Write("[{0} {1}] ", elem->first, elem->second);
    System::Console::WriteLine();

    // compute positive difference
    Myhash_map::size_type diff = 0;
    for (Myhash_map::iterator it = c1.begin(); it != c1.end(); ++it)
        ++diff;
    System::Console::WriteLine("end()-begin() = {0}", diff);
    return (0);
    }
[a 1] [b 2] [c 3]
end()-begin() = 3

hash_map::swap

두 컨테이너의 내용을 바꿉니다.

구문

void swap(hash_map<Key, Mapped>% right);

매개 변수

right
콘텐츠와 바꿀 컨테이너입니다.

설명

멤버 함수는 thisright 간에 제어된 시퀀스를 교환합니다. 그것은 일정한 시간에 그렇게하고 예외를 throw하지 않습니다. 두 컨테이너의 콘텐츠를 빠르게 교환하는 방법으로 사용합니다.

예시

// cliext_hash_map_swap.cpp
// compile with: /clr
#include <cliext/hash_map>

typedef cliext::hash_map<wchar_t, int> Myhash_map;
int main()
    {
    Myhash_map c1;
    c1.insert(Myhash_map::make_value(L'a', 1));
    c1.insert(Myhash_map::make_value(L'b', 2));
    c1.insert(Myhash_map::make_value(L'c', 3));

    // display contents " [a 1] [b 2] [c 3]"
    for each (Myhash_map::value_type elem in c1)
        System::Console::Write("[{0} {1}] ", elem->first, elem->second);
    System::Console::WriteLine();

    // construct another container with repetition of values
    Myhash_map c2;
    c2.insert(Myhash_map::make_value(L'd', 4));
    c2.insert(Myhash_map::make_value(L'e', 5));
    c2.insert(Myhash_map::make_value(L'f', 6));
    for each (Myhash_map::value_type elem in c2)
        System::Console::Write("[{0} {1}] ", elem->first, elem->second);
    System::Console::WriteLine();

    // swap and redisplay
    c1.swap(c2);
    for each (Myhash_map::value_type elem in c1)
        System::Console::Write("[{0} {1}] ", elem->first, elem->second);
    System::Console::WriteLine();

    for each (Myhash_map::value_type elem in c2)
        System::Console::Write("[{0} {1}] ", elem->first, elem->second);
    System::Console::WriteLine();
    return (0);
    }
[a 1] [b 2] [c 3]
[d 4] [e 5] [f 6]
[d 4] [e 5] [f 6]
[a 1] [b 2] [c 3]

hash_map::to_array

제어된 시퀀스를 새 배열에 복사합니다.

구문

cli::array<value_type>^ to_array();

설명

멤버 함수는 제어되는 시퀀스를 포함하는 배열을 반환합니다. 이를 사용하여 배열 형식으로 제어된 시퀀스의 복사본을 가져옵니다.

예시

// cliext_hash_map_to_array.cpp
// compile with: /clr
#include <cliext/hash_map>

typedef cliext::hash_map<wchar_t, int> Myhash_map;
int main()
    {
    Myhash_map c1;
    c1.insert(Myhash_map::make_value(L'a', 1));
    c1.insert(Myhash_map::make_value(L'b', 2));
    c1.insert(Myhash_map::make_value(L'c', 3));

    // copy the container and modify it
    cli::array<Myhash_map::value_type>^ a1 = c1.to_array();

    c1.insert(Myhash_map::make_value(L'd', 4));
    for each (Myhash_map::value_type elem in c1)
        System::Console::Write("[{0} {1}] ", elem->first, elem->second);
    System::Console::WriteLine();

    // display the earlier array copy
    for each (Myhash_map::value_type elem in a1)
        System::Console::Write("[{0} {1}] ", elem->first, elem->second);
    System::Console::WriteLine();
    return (0);
    }
[a 1] [b 2] [c 3] [d 4]
[a 1] [b 2] [c 3]

hash_map::upper_bound

지정된 키와 일치하는 범위의 끝을 찾습니다.

구문

iterator upper_bound(key_type key);

매개 변수

key
검색할 키 값입니다.

설명

멤버 함수는 제어되는 시퀀스에서 동일한 버킷 key 으로 해시하고 동일한 순서를 사용하는 마지막 요소를 X 결정합니다key. 이러한 요소가 없거나 제어되는 시퀀스의 마지막 요소인 경우 X 반환 end()됩니다. 그렇지 않으면 첫 번째 요소를 넘어 X지정하는 반복기를 반환합니다. 이를 사용하여 지정된 키와 일치하는 제어된 시퀀스에서 현재 요소 시퀀스의 끝을 찾습니다.

예시

// cliext_hash_map_upper_bound.cpp
// compile with: /clr
#include <cliext/hash_map>

typedef cliext::hash_map<wchar_t, int> Myhash_map;
int main()
    {
    Myhash_map c1;
    c1.insert(Myhash_map::make_value(L'a', 1));
    c1.insert(Myhash_map::make_value(L'b', 2));
    c1.insert(Myhash_map::make_value(L'c', 3));

    // display contents " [a 1] [b 2] [c 3]"
    for each (Myhash_map::value_type elem in c1)
        System::Console::Write("[{0} {1}] ", elem->first, elem->second);
    System::Console::WriteLine();

    System::Console::WriteLine("upper_bound(L'x')==end() = {0}",
        c1.upper_bound(L'x') == c1.end());

    Myhash_map::iterator it = c1.upper_bound(L'a');
    System::Console::WriteLine("*upper_bound(L'a') = [{0} {1}]",
        it->first, it->second);
    it = c1.upper_bound(L'b');
    System::Console::WriteLine("*upper_bound(L'b') = [{0} {1}]",
        it->first, it->second);
    return (0);
    }
[a 1] [b 2] [c 3]
upper_bound(L'x')==end() = True
*upper_bound(L'a') = [b 2]
*upper_bound(L'b') = [c 3]

hash_map::value_comp

두 요소 값에 대한 순서 지정 대리자를 복사합니다.

구문

value_compare^ value_comp();

설명

멤버 함수는 제어되는 시퀀스를 정렬하는 데 사용되는 순서 지정 대리자를 반환합니다. 두 요소 값을 비교하는 데 사용합니다.

예시

// cliext_hash_map_value_comp.cpp
// compile with: /clr
#include <cliext/hash_map>

typedef cliext::hash_map<wchar_t, int> Myhash_map;
int main()
    {
    Myhash_map c1;
    Myhash_map::value_compare^ kcomp = c1.value_comp();

    System::Console::WriteLine("compare([L'a', 1], [L'a', 1]) = {0}",
        kcomp(Myhash_map::make_value(L'a', 1),
            Myhash_map::make_value(L'a', 1)));
    System::Console::WriteLine("compare([L'a', 1], [L'b', 2]) = {0}",
        kcomp(Myhash_map::make_value(L'a', 1),
            Myhash_map::make_value(L'b', 2)));
    System::Console::WriteLine("compare([L'b', 2], [L'a', 1]) = {0}",
        kcomp(Myhash_map::make_value(L'b', 2),
            Myhash_map::make_value(L'a', 1)));
    System::Console::WriteLine();
    return (0);
    }
compare([L'a', 1], [L'a', 1]) = True
compare([L'a', 1], [L'b', 2]) = True
compare([L'b', 2], [L'a', 1]) = False

hash_map::value_compare

두 요소 값에 대한 순서 지정 대리자입니다.

구문

Microsoft::VisualC::StlClr::BinaryDelegate<generic_value, generic_value, bool>
    value_compare;

설명

형식은 해당 값 인수의 순서를 결정하는 대리자의 동의어입니다.

예시

// cliext_hash_map_value_compare.cpp
// compile with: /clr
#include <cliext/hash_map>

typedef cliext::hash_map<wchar_t, int> Myhash_map;
int main()
    {
    Myhash_map c1;
    Myhash_map::value_compare^ kcomp = c1.value_comp();

    System::Console::WriteLine("compare([L'a', 1], [L'a', 1]) = {0}",
        kcomp(Myhash_map::make_value(L'a', 1),
            Myhash_map::make_value(L'a', 1)));
    System::Console::WriteLine("compare([L'a', 1], [L'b', 2]) = {0}",
        kcomp(Myhash_map::make_value(L'a', 1),
            Myhash_map::make_value(L'b', 2)));
    System::Console::WriteLine("compare([L'b', 2], [L'a', 1]) = {0}",
        kcomp(Myhash_map::make_value(L'b', 2),
            Myhash_map::make_value(L'a', 1)));
    System::Console::WriteLine();
    return (0);
    }
compare([L'a', 1], [L'a', 1]) = True
compare([L'a', 1], [L'b', 2]) = True
compare([L'b', 2], [L'a', 1]) = False

hash_map::value_type

요소의 형식입니다.

구문

typedef generic_value value_type;

설명

이 형식은 generic_value의 동의어입니다.

예제

// cliext_hash_map_value_type.cpp
// compile with: /clr
#include <cliext/hash_map>

typedef cliext::hash_map<wchar_t, int> Myhash_map;
int main()
    {
    Myhash_map c1;
    c1.insert(Myhash_map::make_value(L'a', 1));
    c1.insert(Myhash_map::make_value(L'b', 2));
    c1.insert(Myhash_map::make_value(L'c', 3));

    // display contents " [a 1] [b 2] [c 3]" using value_type
    for (Myhash_map::iterator it = c1.begin(); it != c1.end(); ++it)
        {   // store element in value_type object
        Myhash_map::value_type val = *it;
        System::Console::Write("[{0} {1}] ", val->first, val->second);
        }
    System::Console::WriteLine();
    return (0);
    }
[a 1] [b 2] [c 3]