hash_multiset (STL/CLR)

このテンプレート クラスは、双方向にアクセスできる可変長の要素シーケンスを制御するオブジェクトを表します。 hash_multiset コンテナーを使って、要素のシーケンスをハッシュ テーブルとして管理します。各テーブル エントリにはノードの双方向リンク リストが格納され、各ノードには 1 つの要素が格納されます。 各要素の値は、シーケンスの順序付けのためのキーとして使われます。

以下の説明では、と同じですが、GValue後者が ref 型でない限り同じですKey。その場合は Key^.GKey

構文

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

パラメーター

Key
制御シーケンス内の要素のキー コンポーネントの型。

必要条件

ヘッダー:<cliext/hash_set>

名前空間cliext:

宣言

型定義 説明
hash_multiset::const_iterator 被制御シーケンスの定数反復子の型です。
hash_multiset::const_reference 要素への定数参照の型です。
hash_multiset::const_reverse_iterator 被制御シーケンスの定数反転反復子の型です。
hash_multiset::difference_type 2 つの要素間の距離を表す (場合によっては符号付きの) 型です。
hash_multiset::generic_container コンテナーのジェネリック インターフェイスの型です。
hash_multiset::generic_iterator コンテナーのジェネリック インターフェイスの反復子の型です。
hash_multiset::generic_reverse_iterator コンテナーのジェネリック インターフェイスの反転反復子の型です。
hash_multiset::generic_value コンテナーのジェネリック インターフェイスの要素の型です。
hash_multiset::hasher キーのハッシュ デリゲートです。
hash_multiset::iterator 被制御シーケンスの反復子の型です。
hash_multiset::key_compare 2 つのキーの順序付けデリゲートです。
hash_multiset::key_type 順序付けキーの型です。
hash_multiset::reference 要素への参照の型です。
hash_multiset::reverse_iterator 被制御シーケンスの反転反復子の型です。
hash_multiset::size_type 2 つの要素間の距離を表す (負でない) 型です。
hash_multiset::value_compare 2 つの要素値の順序付けデリゲートです。
hash_multiset::value_type 要素の型。
メンバー関数 説明
hash_multiset::begin 被制御シーケンスの先頭を指定します。
hash_multiset::bucket_count バケット数をカウントします。
hash_multiset::clear すべての要素を削除します。
hash_multiset::count 指定したキーに一致する要素をカウントします。
hash_multiset::empty 要素が存在しないかどうかをテストします。
hash_multiset::end 被制御シーケンスの末尾を指定します。
hash_multiset::equal_range 指定したキーに一致する範囲を検索します。
hash_multiset::erase 指定した位置にある要素を削除します。
hash_multiset::find 指定したキーに一致する要素を検索します。
hash_multiset::hash_delegate キーのハッシュ デリゲートをコピーします。
hash_multiset::hash_multiset コンテナー オブジェクトを構築します。
hash_multiset::insert 要素を追加します。
hash_multiset::key_comp 2 つのキーの順序付けデリゲートをコピーします。
hash_multiset::load_factor バケットごとの平均要素数をカウントします。
hash_multiset::lower_bound 指定したキーに一致する範囲の先頭を検索します。
hash_multiset::make_value 値オブジェクトを構築します。
hash_multiset::max_load_factor バケットあたりの最大要素数を取得または設定します。
hash_multiset::rbegin 反転被制御シーケンスの先頭を指定します。
hash_multiset::rehash ハッシュ テーブルをリビルドします。
hash_multiset::rend 反転被制御シーケンスの末尾を指定します。
hash_multiset::size 要素の数をカウントします。
hash_multiset::swap 2 つのコンテナーのコンテンツを交換します。
hash_multiset::to_array 被制御シーケンスを新しい配列にコピーします。
hash_multiset::upper_bound 指定したキーに一致する範囲の末尾を検索します。
hash_multiset::value_comp 2 つの要素値の順序付けデリゲートをコピーします。
Operator 説明
hash_multiset::operator= 被制御シーケンスを置き換えます。

インターフェイス

インターフェイス 説明
ICloneable オブジェクトを複製します。
IEnumerable 要素をシーケンス処理します。
ICollection 要素のグループを維持します。
IEnumerable<T> 型指定された要素をシーケンス処理します。
ICollection<T> 型指定された要素のグループを維持します。
IHash<Key, Value> ジェネリック コンテナーを維持します。

解説

このオブジェクトでは、双方向リンク リスト内の個々のノードとしての被制御シーケンスに対してストレージの割り当てと解放を行います。 アクセスを高速化するために、このオブジェクトは可変長のポインターの配列をリスト (ハッシュ テーブル) にも保持し、リスト全体をサブリスト (バケット) のシーケンスとして効果的に管理します。 コンテンツをノード間でコピーするのではなく、ノード間のリンクを変更することにより、順序付けを維持した状態でバケットに要素を挿入します。 つまり、残りの要素に影響を与えずに、要素を自由に挿入および削除できます。

オブジェクトは、型の格納されたデリゲート オブジェクトを呼び出すことによって、制御する各バケットを並べ替えます hash_set::key_compare。 hash_set の構築時に、格納されているデリゲート オブジェクトを指定できます。デリゲート オブジェクトを指定しない場合、既定値は比較 operator<=(key_type, key_type) です。

格納されているデリゲート オブジェクトにアクセスするには、メンバー関数 hash_set::key_compを呼び出します。 このようなデリゲート オブジェクトでは、型 hash_set::key_typeのキー間で同等の順序を定義する必要があります。 つまり、任意の 2 つのキー XY については、次のようになります。

key_comp()(X, Y) は、すべての呼び出しで同じブール値の結果を返します。

key_comp()(X, Y) && key_comp()(Y, X) が true の場合、XY の順序付けが等しくなります。

同じようにoperator<=(key_type, key_type)operator>=(key_type, key_type)動作する、またはoperator==(key_type, key_type)同等の順序を定義する順序付けルール。

コンテナーは、キーの順序が同等の要素 (および同じ整数値に対するハッシュ) がバケット内で隣接していることを確認します。 テンプレート クラス hash_set (STL/CLR) とは異なり、テンプレート クラス hash_multiset のオブジェクトでは、すべての要素のキーが一意である必要はありません。 (2 つ以上のキーの順序付けを等しくすることができます)。

オブジェクトは、格納 hash_set::hasherされている型のデリゲート オブジェクトを呼び出すことによって、特定の順序付けキーを含めるバケットを決定します。 この格納されたオブジェクトにアクセスするには、メンバー関数 hash_set::hash_delegate を呼び出して、キー値に依存する整数値を取得します。 hash_set の構築時に、格納されているデリゲート オブジェクトを指定できます。デリゲート オブジェクトを指定しない場合、既定値は関数 System::Object::hash_value(key_type) です。 つまり、任意のキー XY については、次のようになります。

hash_delegate()(X) は、すべての呼び出しで同じ整数の結果を返します。

XY の順序付けが等しい場合、hash_delegate()(X)hash_delegate()(Y) と同じ整数の結果を返す必要があります。

各要素には、キーと値、両方の役割があります。 シーケンスは、一定の時間で任意の要素の検索、挿入、および削除を許可する方法で表されます。 つまり、操作の数は、少なくとも最良のケースでは、シーケンス内の要素の数に依存しません。 さらに、要素を挿入すると反復子が無効になり、要素を削除すると、削除された要素を指す反復子のみが無効になります。

ただし、ハッシュ値が均一に分散されていない場合は、ハッシュ テーブルが縮退する可能性があります。 極端な場合 (常に同じ値を返すハッシュ関数の場合)、検索、挿入、および削除は、シーケンス内の要素の数 (線形時間) に比例します。 コンテナーでは、適切なハッシュ関数、平均バケット サイズ、ハッシュ テーブル サイズ (バケットの総数) を選択しようとしますが、これらの選択肢のいずれかまたはすべてをオーバーライドできます。 例えば、関数 hash_set::max_load_factorhash_set::rehash.

A は hash_multiset 双方向反復子をサポートしています。つまり、被制御シーケンス内の要素を指定する反復子を指定すると、隣接する要素にステップ インできます。 特殊なヘッド ノードは、によって hash_multiset::end返される反復子に対応します。 この反復子をデクリメントすると、被制御シーケンス内の最後の要素 (存在する場合) に到達できます。 反復子を hash_multiset インクリメントしてヘッド ノードに到達すると、等しい end()値と比較されます。 ただし、返される end()反復子を逆参照することはできません。

数値の位置を指定して要素を hash_multiset 直接参照することはできません。 これにはランダム アクセス反復子が必要です。

反復子は hash_multiset 、関連付けられた hash_multiset ノードへのハンドルを格納し、関連付けられたコンテナーへのハンドルを格納します。 反復子は、関連付けられているコンテナー オブジェクトでのみ使用できます。 hash_multiset反復子メイン関連付けられたhash_multisetノードが一部hash_multisetに関連付けられている限り有効です。 さらに、有効な反復子は逆参照可能です。 指定した要素値にアクセスしたり変更したりするために使用できます(等しくない end()限り)。

要素を消去または削除すると、格納されている値のデストラクターが呼び出されます。 コンテナーを破棄すると、すべての要素が消去されます。 したがって、要素型が ref クラスのコンテナーでは、コンテナーよりも有効期間が長い要素はありません。 ただし、ハンドルのコンテナーでは、その要素は破棄されません。

メンバー

hash_multiset::begin

被制御シーケンスの先頭を指定します。

構文

iterator begin();

解説

このメンバー関数は、被制御シーケンスの最初の要素 (または空のシーケンスの末尾の次の位置) を指定する双方向反復子を返します。 これを使用して被制御シーケンスの先頭を指定する反復子を current 取得しますが、被制御シーケンスの長さが変わると状態が変わる可能性があります。

// cliext_hash_multiset_begin.cpp
// compile with: /clr
#include <cliext/hash_set>

typedef cliext::hash_multiset<wchar_t> Myhash_multiset;
int main()
    {
    Myhash_multiset c1;
    c1.insert(L'a');
    c1.insert(L'b');
    c1.insert(L'c');

    // display initial contents " a b c"
    for each (wchar_t elem in c1)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();

    // inspect first two items
    Myhash_multiset::iterator it = c1.begin();
    System::Console::WriteLine("*begin() = {0}", *it);
    System::Console::WriteLine("*++begin() = {0}", *++it);
    return (0);
    }
a b c
*begin() = a
*++begin() = b

hash_multiset::bucket_count

バケット数をカウントします。

構文

int bucket_count();

解説

このメンバー関数は、現在のバケット数を返します。 ハッシュ テーブルのサイズを確認する場合に、これを使用します。

// cliext_hash_multiset_bucket_count.cpp
// compile with: /clr
#include <cliext/hash_set>

typedef cliext::hash_multiset<wchar_t> Myhash_multiset;
int main()
    {
    Myhash_multiset c1;
    c1.insert(L'a');
    c1.insert(L'b');
    c1.insert(L'c');

    // display initial contents " a b c"
    for each (wchar_t elem in c1)
        System::Console::Write("{0} ", elem);
    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 b c
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_multiset::clear

すべての要素を削除します。

構文

void clear();

解説

メンバー関数は、erase(begin(), end()) を効果的に呼び出します。 被制御シーケンスが空であることを確実にするために使います。

// cliext_hash_multiset_clear.cpp
// compile with: /clr
#include <cliext/hash_set>

typedef cliext::hash_multiset<wchar_t> Myhash_multiset;
int main()
    {
    Myhash_multiset c1;
    c1.insert(L'a');
    c1.insert(L'b');
    c1.insert(L'c');

    // display initial contents " a b c"
    for each (wchar_t elem in c1)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();

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

    // add elements and clear again
    c1.insert(L'a');
    c1.insert(L'b');

    for each (wchar_t elem in c1)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();
    c1.clear();
    System::Console::WriteLine("size() = {0}", c1.size());
    return (0);
    }
a b c
size() = 0
a b
size() = 0

hash_multiset::const_iterator

被制御シーケンスの定数反復子の型です。

構文

typedef T2 const_iterator;

解説

この型は、被制御シーケンスの定数双方向反復子として使用できる未指定の T2 型のオブジェクトを表します。

// cliext_hash_multiset_const_iterator.cpp
// compile with: /clr
#include <cliext/hash_set>

typedef cliext::hash_multiset<wchar_t> Myhash_multiset;
int main()
    {
    Myhash_multiset c1;
    c1.insert(L'a');
    c1.insert(L'b');
    c1.insert(L'c');

    // display contents " a b c"
    Myhash_multiset::const_iterator cit = c1.begin();
    for (; cit != c1.end(); ++cit)
        System::Console::Write("{0} ", *cit);
    System::Console::WriteLine();
    return (0);
    }
a b c

hash_multiset::const_reference

要素への定数参照の型です。

構文

typedef value_type% const_reference;

解説

この型は、要素への定数参照を表します。

// cliext_hash_multiset_const_reference.cpp
// compile with: /clr
#include <cliext/hash_set>

typedef cliext::hash_multiset<wchar_t> Myhash_multiset;
int main()
    {
    Myhash_multiset c1;
    c1.insert(L'a');
    c1.insert(L'b');
    c1.insert(L'c');

    // display initial contents " a b c"
    Myhash_multiset::const_iterator cit = c1.begin();
    for (; cit != c1.end(); ++cit)
        {   // get a const reference to an element
        Myhash_multiset::const_reference cref = *cit;
        System::Console::Write("{0} ", cref);
        }
    System::Console::WriteLine();
    return (0);
    }
a b c

hash_multiset::const_reverse_iterator

被制御シーケンスの定数反転反復子の型です。

構文

typedef T4 const_reverse_iterator;

解説

この型は、被制御シーケンスの定数反転反復子として使用できる未指定の T4 型のオブジェクトを表します。

// cliext_hash_multiset_const_reverse_iterator.cpp
// compile with: /clr
#include <cliext/hash_set>

typedef cliext::hash_multiset<wchar_t> Myhash_multiset;
int main()
    {
    Myhash_multiset c1;
    c1.insert(L'a');
    c1.insert(L'b');
    c1.insert(L'c');

    // display contents " a b c" reversed
    Myhash_multiset::const_reverse_iterator crit = c1.rbegin();
    for (; crit != c1.rend(); ++crit)
        System::Console::Write("{0} ", *crit);
    System::Console::WriteLine();
    return (0);
    }
c b a

hash_multiset::count

指定したキーに一致する要素の数を検索します。

構文

size_type count(key_type key);

パラメーター

key
検索対象のキー値。

解説

このメンバー関数は、次の値と同等の順序を持つ、制御シーケンス内の要素の数を key返します。 これを使用して、指定したキーと一致する、現在、制御シーケンス内の要素の数を決定します。

// cliext_hash_multiset_count.cpp
// compile with: /clr
#include <cliext/hash_set>

typedef cliext::hash_multiset<wchar_t> Myhash_multiset;
int main()
    {
    Myhash_multiset c1;
    c1.insert(L'a');
    c1.insert(L'b');
    c1.insert(L'c');

    // display initial contents " a b c"
    for each (wchar_t elem in c1)
        System::Console::Write("{0} ", elem);
    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 b c
count(L'A') = 0
count(L'b') = 1
count(L'C') = 0

hash_multiset::difference_type

2 つの要素間の符号付きの距離を表す型です。

構文

typedef int difference_type;

解説

この型は、場合によっては負の要素数を表します。

// cliext_hash_multiset_difference_type.cpp
// compile with: /clr
#include <cliext/hash_set>

typedef cliext::hash_multiset<wchar_t> Myhash_multiset;
int main()
    {
    Myhash_multiset c1;
    c1.insert(L'a');
    c1.insert(L'b');
    c1.insert(L'c');

    // display initial contents " a b c"
    for each (wchar_t elem in c1)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();

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

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

hash_multiset::empty

要素が存在しないかどうかをテストします。

構文

bool empty();

解説

このメンバー関数は、被制御シーケンスが空の場合に true を返します。 これは size() == 0 と同じです。 これを使用して、空かどうかを hash_multiset テストします。

// cliext_hash_multiset_empty.cpp
// compile with: /clr
#include <cliext/hash_set>

typedef cliext::hash_multiset<wchar_t> Myhash_multiset;
int main()
    {
    Myhash_multiset c1;
    c1.insert(L'a');
    c1.insert(L'b');
    c1.insert(L'c');

    // display initial contents " a b c"
    for each (wchar_t elem in c1)
        System::Console::Write("{0} ", elem);
    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 b c
size() = 3
empty() = False
size() = 0
empty() = True

hash_multiset::end

被制御シーケンスの末尾を指定します。

構文

iterator end();

解説

このメンバー関数は、被制御シーケンスの末尾を越えたところを示す双方向反復子を返します。 これを使用して、被制御シーケンスの末尾を指定する反復子を取得します。その状態は、制御シーケンスの長さが変更されても変わりません。

// cliext_hash_multiset_end.cpp
// compile with: /clr
#include <cliext/hash_set>

typedef cliext::hash_multiset<wchar_t> Myhash_multiset;
int main()
    {
    Myhash_multiset c1;
    c1.insert(L'a');
    c1.insert(L'b');
    c1.insert(L'c');

    // display initial contents " a b c"
    for each (wchar_t elem in c1)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();

    // inspect last two items
    Myhash_multiset::iterator it = c1.end();
    --it;
    System::Console::WriteLine("*-- --end() = {0}", *--it);
    System::Console::WriteLine("*--end() = {0}", *++it);
    return (0);
    }
a b c
*-- --end() = b
*--end() = c

hash_multiset::equal_range

指定したキーに一致する範囲を検索します。

構文

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

パラメーター

key
検索対象のキー値。

解説

このメンバー関数は、反復子 cliext::pair<iterator, iterator>(lower_bound(key), upper_bound(key)) のペアを返します。 指定したキーに一致する、被制御シーケンス内の現在の要素の範囲を特定するために使います。

// cliext_hash_multiset_equal_range.cpp
// compile with: /clr
#include <cliext/hash_set>

typedef cliext::hash_multiset<wchar_t> Myhash_multiset;
typedef Myhash_multiset::pair_iter_iter Pairii;
int main()
    {
    Myhash_multiset c1;
    c1.insert(L'a');
    c1.insert(L'b');
    c1.insert(L'c');

    // display initial contents " a b c"
    for each (wchar_t elem in c1)
        System::Console::Write("{0} ", elem);
    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} ", *pair1.first);
    System::Console::WriteLine();
    return (0);
    }
a b c
equal_range(L'x') empty = True
b

hash_multiset::erase

指定した位置にある要素を削除します。

構文

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

パラメーター

first
消去する範囲の先頭。

key
消去するキー値。

last
消去する範囲の末尾。

where
消去する要素。

解説

最初のメンバー関数は、指定された被制御シーケンスの要素を削除し、削除されたwhere要素を超えて、またはend()そのような要素が存在しない場合にメイン最初の要素を指定する反復子を返します。 1 つの要素を削除する場合に使います。

2 番目のメンバー関数は、範囲 [first, ), 内の被制御シーケンスの要素を削除し、last削除された要素を超えてメイン最初の要素を指定する反復子を返します。またはend()、そのような要素が存在しない場合。 0 個以上の連続する要素を削除する場合に、これを使用します。

3 番目のメンバー関数は、キーの順序 keyが同等の制御シーケンスの要素を削除し、削除された要素の数を返します。 指定したキーに一致するすべての要素を削除してカウントする場合に、これを使用します。

各要素の消去には、被制御シーケンス内の要素数の対数に比例した時間が必要です。

// cliext_hash_multiset_erase.cpp
// compile with: /clr
#include <cliext/hash_set>

typedef cliext::hash_multiset<wchar_t> Myhash_multiset;
int main()
    {
    Myhash_multiset c1;
    c1.insert(L'a');
    c1.insert(L'b');
    c1.insert(L'c');

    // display initial contents " a b c"
    for each (wchar_t elem in c1)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();

    // erase an element and reinspect
    System::Console::WriteLine("erase(begin()) = {0}",
        *c1.erase(c1.begin()));

    // add elements and display " b c d e"
    c1.insert(L'd');
    c1.insert(L'e');
    for each (wchar_t elem in c1)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();

    // erase all but end
    Myhash_multiset::iterator it = c1.end();
    System::Console::WriteLine("erase(begin(), end()-1) = {0}",
        *c1.erase(c1.begin(), --it));
    System::Console::WriteLine("size() = {0}", c1.size());
    return (0);
    }
a b c
erase(begin()) = b
b c d e
erase(begin(), end()-1) = e
size() = 1

hash_multiset::find

指定したキーに一致する要素を検索します。

構文

iterator find(key_type key);

パラメーター

key
検索対象のキー値。

解説

被制御シーケンス内の少なくとも 1 つの要素の順序 keyが等しい場合、メンバー関数は、これらの要素のいずれかを指定する反復子を返します。それ以外の場合は返します end()。 被制御シーケンス内の指定したキーに一致する現在の要素を検索する場合に使います。

// cliext_hash_multiset_find.cpp
// compile with: /clr
#include <cliext/hash_set>

typedef cliext::hash_multiset<wchar_t> Myhash_multiset;
int main()
    {
    Myhash_multiset c1;
    c1.insert(L'a');
    c1.insert(L'b');
    c1.insert(L'c');

    // display initial contents " a b c"
    for each (wchar_t elem in c1)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();

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

hash_multiset::generic_container

コンテナーのジェネリック インターフェイスの型です。

構文

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

解説

この型は、このテンプレート コンテナー クラスのジェネリック インターフェイスを表します。

// cliext_hash_multiset_generic_container.cpp
// compile with: /clr
#include <cliext/hash_set>

typedef cliext::hash_multiset<wchar_t> Myhash_multiset;
int main()
    {
    Myhash_multiset c1;
    c1.insert(L'a');
    c1.insert(L'b');
    c1.insert(L'c');

    // display contents " a b c"
    for each (wchar_t elem in c1)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();

    // construct a generic container
    Myhash_multiset::generic_container^ gc1 = %c1;
    for each (wchar_t elem in gc1)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();

    // modify generic and display original
    gc1->insert(L'd');
    for each (wchar_t elem in c1)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();

    // modify original and display generic
    c1.insert(L'e');
    for each (wchar_t elem in gc1)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();
    return (0);
    }
a b c
a b c
a b c d
a b c d e

hash_multiset::generic_iterator

コンテナーのジェネリック インターフェイスで使用する反復子の型です。

構文

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

解説

この型は、このテンプレート コンテナー クラスのジェネリック インターフェイスで使用できるジェネリック反復子を表します。

// cliext_hash_multiset_generic_iterator.cpp
// compile with: /clr
#include <cliext/hash_set>

typedef cliext::hash_multiset<wchar_t> Myhash_multiset;
int main()
    {
    Myhash_multiset c1;
    c1.insert(L'a');
    c1.insert(L'b');
    c1.insert(L'c');

    // display contents " a b c"
    for each (wchar_t elem in c1)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();

    // construct a generic container
    Myhash_multiset::generic_container^ gc1 = %c1;
    for each (wchar_t elem in gc1)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();

    // get an element and display it
    Myhash_multiset::generic_iterator gcit = gc1->begin();
    Myhash_multiset::generic_value gcval = *gcit;
    System::Console::WriteLine("{0} ", gcval);
    return (0);
    }
a b c
a b c
a

hash_multiset::generic_reverse_iterator

コンテナーのジェネリック インターフェイスで使用する反転反復子の型です。

構文

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

解説

この型は、このテンプレート コンテナー クラスのジェネリック インターフェイスで使用できるジェネリック反転反復子を表します。

// cliext_hash_multiset_generic_reverse_iterator.cpp
// compile with: /clr
#include <cliext/hash_set>

typedef cliext::hash_multiset<wchar_t> Myhash_multiset;
int main()
    {
    Myhash_multiset c1;
    c1.insert(L'a');
    c1.insert(L'b');
    c1.insert(L'c');

    // display contents " a b c"
    for each (wchar_t elem in c1)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();

    // construct a generic container
    Myhash_multiset::generic_container^ gc1 = %c1;
    for each (wchar_t elem in gc1)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();

    // get an element and display it
    Myhash_multiset::generic_reverse_iterator gcit = gc1->rbegin();
    Myhash_multiset::generic_value gcval = *gcit;
    System::Console::WriteLine("{0} ", gcval);
    return (0);
    }
a b c
a b c
c

hash_multiset::generic_value

コンテナーのジェネリック インターフェイスで使用する要素の型です。

構文

typedef GValue generic_value;

解説

この型は、このテンプレート コンテナー クラスのジェネリック インターフェイスで使用する、格納されている要素の値を記述する GValue 型のオブジェクトを表します。

// cliext_hash_multiset_generic_value.cpp
// compile with: /clr
#include <cliext/hash_set>

typedef cliext::hash_multiset<wchar_t> Myhash_multiset;
int main()
    {
    Myhash_multiset c1;
    c1.insert(L'a');
    c1.insert(L'b');
    c1.insert(L'c');

    // display contents " a b c"
    for each (wchar_t elem in c1)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();

    // construct a generic container
    Myhash_multiset::generic_container^ gc1 = %c1;
    for each (wchar_t elem in gc1)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();

    // get an element and display it
    Myhash_multiset::generic_iterator gcit = gc1->begin();
    Myhash_multiset::generic_value gcval = *gcit;
    System::Console::WriteLine("{0} ", gcval);
    return (0);
    }
a b c
a b c
a

hash_multiset::hash_delegate

指定したキーに一致する要素を検索します。

構文

hasher^ hash_delegate();

解説

このメンバー関数は、キー値を整数に変換するために使用されるデリゲートを返します。 キーをハッシュする場合に、これを使用します。

// cliext_hash_multiset_hash_delegate.cpp
// compile with: /clr
#include <cliext/hash_set>

typedef cliext::hash_multiset<wchar_t> Myhash_multiset;
int main()
    {
    Myhash_multiset c1;
    Myhash_multiset::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_multiset::hash_multiset

コンテナー オブジェクトを構築します。

構文

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

パラメーター

first
挿入する範囲の先頭。

hashfn
キーをバケットにマップするハッシュ関数。

last
挿入する範囲の末尾。

pred
被制御シーケンスの順序付けの述語。

right
挿入するオブジェクトまたは範囲。

解説

コンストラクター:

hash_multiset();

既定の順序付けの述語 key_compare() および既定のハッシュ関数を使用して、要素のない被制御シーケンスを初期化します。 既定の順序付けの述語とハッシュ関数を使用して、空である最初の被制御シーケンスを指定する場合に、これを使用します。

コンストラクター:

explicit hash_multiset(key_compare^ pred);

は、要素なしで、順序付け述語 predを使用して、および既定のハッシュ関数を使用して、制御シーケンスを初期化します。 指定した順序付けの述語と既定のハッシュ関数を使用して、空である最初の被制御シーケンスを指定する場合に、これを使用します。

コンストラクター:

hash_multiset(key_compare^ pred, hasher^ hashfn);

は、要素なしで、順序述語 predを使用して、およびハッシュ関数 hashfnを使用して、制御シーケンスを初期化します。 指定した順序付けの述語とハッシュ関数を使用して、空である最初の被制御シーケンスを指定する場合に、これを使用します。

コンストラクター:

hash_multiset(hash_multiset<Key>% right);

既定の順序付けの述語と既定のハッシュ関数を使用して、シーケンス [right.begin(), right.end()) で被制御シーケンスを初期化します。 これを使用して、既定の順序付け述語とハッシュ関数を使用して、オブジェクトrightによってhash_multiset制御されるシーケンスのコピーである初期被制御シーケンスを指定します。

コンストラクター:

hash_multiset(hash_multiset<Key>^ right);

既定の順序付けの述語と既定のハッシュ関数を使用して、シーケンス [right->begin(), right->end()) で被制御シーケンスを初期化します。 これを使用して、既定の順序付け述語とハッシュ関数を使用して、オブジェクトrightによってhash_multiset制御されるシーケンスのコピーである初期被制御シーケンスを指定します。

コンストラクター:

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

既定の順序付けの述語と既定のハッシュ関数を使用して、シーケンス [first, last) で被制御シーケンスを初期化します。 既定の順序付けの述語とハッシュ関数を使用して、被制御シーケンスを別のシーケンスのコピーにする場合に、これを使用します。

コンストラクター:

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

は、順序付け述語predを使用し、既定のハッシュ関数を使用して、シーケンス [first, last) を使用して、制御シーケンスを初期化します。 指定した順序付けの述語と既定のハッシュ関数を使用して、被制御シーケンスを別のシーケンスのコピーにする場合に、これを使用します。

コンストラクター:

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

は、順序付け述語predを使用して、およびハッシュ関数hashfnを使用して、シーケンス [first, last) を使用して、制御シーケンスを初期化します。 指定した順序付けの述語とハッシュ関数を使用して、被制御シーケンスを別のシーケンスのコピーにする場合に、これを使用します。

コンストラクター:

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

は、列挙子 rightによって指定されたシーケンス、既定の順序付け述語、および既定のハッシュ関数を使用して、制御シーケンスを初期化します。 既定の順序付けの述語とハッシュ関数を使用して、被制御シーケンスを列挙子によって記述された別のシーケンスのコピーにする場合に、これを使用します。

コンストラクター:

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

は、列挙子 rightによって指定されたシーケンス、順序付け述語 pred、および既定のハッシュ関数を使用して、制御シーケンスを初期化します。 指定した順序付けの述語と既定のハッシュ関数を使用して、被制御シーケンスを列挙子によって記述された別のシーケンスのコピーにする場合に、これを使用します。

コンストラクター:

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

は、列挙子 rightによって指定されたシーケンス、順序付け述語 pred、およびハッシュ関数 hashfnを使用して、制御シーケンスを初期化します。 指定した順序付けの述語とハッシュ関数を使用して、被制御シーケンスを列挙子によって記述された別のシーケンスのコピーにする場合に、これを使用します。

// cliext_hash_multiset_construct.cpp
// compile with: /clr
#include <cliext/hash_set>

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

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

    c1.insert(L'a');
    c1.insert(L'b');
    c1.insert(L'c');
    for each (wchar_t elem in c1)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();

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

    c2.insert(c1.begin(), c1.end());
    for each (wchar_t elem in c2)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();

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

    c2h.insert(c1.begin(), c1.end());
    for each (wchar_t elem in c2h)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();
    System::Console::WriteLine();

    // construct with an iterator range
    Myhash_multiset c3(c1.begin(), c1.end());
    for each (wchar_t elem in c3)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();

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

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

    // construct with an enumeration
    Myhash_multiset c5(   // NOTE: cast is not needed
        (System::Collections::Generic::IEnumerable<wchar_t>^)%c3);
    for each (wchar_t elem in c5)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();

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

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

    // construct from a generic container
    Myhash_multiset c7(c4);
    for each (wchar_t elem in c7)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();

    // construct by copying another container
    Myhash_multiset c8(%c3);
    for each (wchar_t elem in c8)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();
    return (0);
    }
size() = 0
a b c
size() = 0
a b c
size() = 0
c b a

a b c
a b c
c b a

a b c
a b c
c b a

a b c
a b c

hash_multiset::hasher

キーのハッシュ デリゲートです。

構文

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

解説

この型は、キー値を整数に変換するデリゲートを表します。

// cliext_hash_multiset_hasher.cpp
// compile with: /clr
#include <cliext/hash_set>

typedef cliext::hash_multiset<wchar_t> Myhash_multiset;
int main()
    {
    Myhash_multiset c1;
    Myhash_multiset::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_multiset::insert

要素を追加します。

構文

iterator 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を持つ要素を挿入し、新しく挿入された要素を指定する反復子を返します。 1 つの要素を挿入する場合に、これを使用します。

2 番目のメンバー関数は、(パフォーマンスを向上させるために) ヒントとして使用して、値 valを持 where つ要素を挿入し、新しく挿入された要素を指定する反復子を返します。 これを使用して、知っている要素の横にある可能性のある 1 つの要素を挿入します。

3 つ目のメンバー関数は、シーケンス [first, last) を挿入します。 別のシーケンスからコピーした 0 個以上の要素を挿入する場合に、これを使用します。

4 番目のメンバー関数は、によって指定されたシーケンスを挿入します。right 列挙子によって記述されたシーケンスを挿入する場合に、これを使用します。

各要素の挿入には、被制御シーケンス内の要素数の対数に比例した時間が必要です。 ただし、挿入ポイントの横にある要素を指定するヒントを指定すると、挿入は償却定数時間で発生する可能性があります。

// cliext_hash_multiset_insert.cpp
// compile with: /clr
#include <cliext/hash_set>

typedef cliext::hash_multiset<wchar_t> Myhash_multiset;
int main()
    {
    Myhash_multiset c1;
    c1.insert(L'a');
    c1.insert(L'b');
    c1.insert(L'c');

    // display initial contents " a b c"
    for each (wchar_t elem in c1)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();

    // insert a single value, unique and duplicate
    System::Console::WriteLine("insert(L'x') = {0}",
        *c1.insert(L'x'));

    System::Console::WriteLine("insert(L'b') = {0}",
        *c1.insert(L'b'));

    for each (wchar_t elem in c1)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();

    // insert a single value with hint
    System::Console::WriteLine("insert(begin(), L'y') = {0}",
        *c1.insert(c1.begin(), L'y'));
    for each (wchar_t elem in c1)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();

    // insert an iterator range
    Myhash_multiset c2;
    Myhash_multiset::iterator it = c1.end();
    c2.insert(c1.begin(), --it);
    for each (wchar_t elem in c2)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();

    // insert an enumeration
    Myhash_multiset c3;
    c3.insert(   // NOTE: cast is not needed
        (System::Collections::Generic::IEnumerable<wchar_t>^)%c1);
    for each (wchar_t elem in c3)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();
    return (0);
    }
a b c
insert(L'x') = x
insert(L'b') = b
a b b c x
insert(begin(), L'y') = y
a b b c x y
a b b c x
a b b c x y

hash_multiset::iterator

被制御シーケンスの反復子の型です。

構文

typedef T1 iterator;

解説

この型は、被制御シーケンスの双方向反復子として使用できる未指定の T1 型のオブジェクトを表します。

// cliext_hash_multiset_iterator.cpp
// compile with: /clr
#include <cliext/hash_set>

typedef cliext::hash_multiset<wchar_t> Myhash_multiset;
int main()
    {
    Myhash_multiset c1;
    c1.insert(L'a');
    c1.insert(L'b');
    c1.insert(L'c');

    // display contents " a b c"
    Myhash_multiset::iterator it = c1.begin();
    for (; it != c1.end(); ++it)
        System::Console::Write("{0} ", *it);
    System::Console::WriteLine();
    return (0);
    }
a b c

hash_multiset::key_comp

2 つのキーの順序付けデリゲートをコピーします。

構文

key_compare^key_comp();

解説

このメンバー関数は、被制御シーケンスの順序付けに使用される順序付けデリゲートを返します。 これを使用して、2 つのキーを比較します。

// cliext_hash_multiset_key_comp.cpp
// compile with: /clr
#include <cliext/hash_set>

typedef cliext::hash_multiset<wchar_t> Myhash_multiset;
int main()
    {
    Myhash_multiset c1;
    Myhash_multiset::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_multiset 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_multiset::key_compare

2 つのキーの順序付けデリゲートです。

構文

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

解説

この型は、キー引数の順序付けを決定するデリゲートのシノニムです。

// cliext_hash_multiset_key_compare.cpp
// compile with: /clr
#include <cliext/hash_set>

typedef cliext::hash_multiset<wchar_t> Myhash_multiset;
int main()
    {
    Myhash_multiset c1;
    Myhash_multiset::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_multiset 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_multiset::key_type

順序付けキーの型です。

構文

typedef Key key_type;

解説

この型は、テンプレート パラメーター Keyのシノニムです。

// cliext_hash_multiset_key_type.cpp
// compile with: /clr
#include <cliext/hash_set>

typedef cliext::hash_multiset<wchar_t> Myhash_multiset;
int main()
    {
    Myhash_multiset c1;
    c1.insert(L'a');
    c1.insert(L'b');
    c1.insert(L'c');

    // display contents " a b c" using key_type
    for (Myhash_multiset::iterator it = c1.begin(); it != c1.end(); ++it)
        {   // store element in key_type object
        Myhash_multiset::key_type val = *it;

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

hash_multiset::load_factor

バケットごとの平均要素数をカウントします。

構文

float load_factor();

解説

このメンバー関数は、(float)size() / count() を返します。 バケットの平均サイズを決定するために使います。

// cliext_hash_multiset_load_factor.cpp
// compile with: /clr
#include <cliext/hash_set>

typedef cliext::hash_multiset<wchar_t> Myhash_multiset;
int main()
    {
    Myhash_multiset c1;
    c1.insert(L'a');
    c1.insert(L'b');
    c1.insert(L'c');

    // display initial contents " a b c"
    for each (wchar_t elem in c1)
        System::Console::Write("{0} ", elem);
    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 b c
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_multiset::lower_bound

指定したキーに一致する範囲の先頭を検索します。

構文

iterator lower_bound(key_type key);

パラメーター

key
検索対象のキー値。

解説

メンバー関数は、同じバケットkeyにハッシュし、同等の順序を持つ、制御シーケンス内の最初の要素Xkey決定します。 そのような要素が存在しない場合は返 end()されます。それ以外の場合は、指定する反復子を返します X。 指定したキーに一致する、被制御シーケンス内の現在の要素のシーケンスの先頭を検索する場合に使います。

// cliext_hash_multiset_lower_bound.cpp
// compile with: /clr
#include <cliext/hash_set>

typedef cliext::hash_multiset<wchar_t> Myhash_multiset;
int main()
    {
    Myhash_multiset c1;
    c1.insert(L'a');
    c1.insert(L'b');
    c1.insert(L'c');

    // display initial contents " a b c"
    for each (wchar_t elem in c1)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();

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

    System::Console::WriteLine("*lower_bound(L'a') = {0}",
        *c1.lower_bound(L'a'));
    System::Console::WriteLine("*lower_bound(L'b') = {0}",
        *c1.lower_bound(L'b'));
    return (0);
    }
a b c
lower_bound(L'x')==end() = True
*lower_bound(L'a') = a
*lower_bound(L'b') = b

hash_multiset::make_value

値オブジェクトを構築します。

構文

static value_type make_value(key_type key);

パラメーター

key
使用するキー値。

解説

メンバー関数は、キーkeyvalue_type . 他のいくつかのメンバー関数での使用に適したオブジェクトを作成する場合に使います。

// cliext_hash_multiset_make_value.cpp
// compile with: /clr
#include <cliext/hash_set>

typedef cliext::hash_multiset<wchar_t> Myhash_multiset;
int main()
    {
    Myhash_multiset c1;
    c1.insert(Myhash_multiset::make_value(L'a'));
    c1.insert(Myhash_multiset::make_value(L'b'));
    c1.insert(Myhash_multiset::make_value(L'c'));

    // display contents " a b c"
    for each (Myhash_multiset::value_type elem in c1)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();
    return (0);
    }
a b c

hash_multiset::max_load_factor

バケットあたりの最大要素数を取得または設定します。

構文

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

パラメーター

new_factor
格納する新しい最大テーブル占有率。

解説

最初のメンバー関数は、現在格納されている最大テーブル占有率を返します。 最大バケット サイズを確認する場合に、これを使用します。

2 番目のメンバー関数は、ストアの最大読み込み係数 new_factorを . 後続の挿入まで、自動再ハッシュは行われません。

// cliext_hash_multiset_max_load_factor.cpp
// compile with: /clr
#include <cliext/hash_set>

typedef cliext::hash_multiset<wchar_t> Myhash_multiset;
int main()
    {
    Myhash_multiset c1;
    c1.insert(L'a');
    c1.insert(L'b');
    c1.insert(L'c');

    // display initial contents " a b c"
    for each (wchar_t elem in c1)
        System::Console::Write("{0} ", elem);
    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 b c
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_multiset::operator=

被制御シーケンスを置き換えます。

構文

hash_multiset<Key>% operator=(hash_multiset<Key>% right);

パラメーター

right
コピーするコンテナー。

解説

メンバー演算子は、オブジェクトにコピー right し、次に返します *this。 これを使用して、被制御シーケンスを right の被制御シーケンスのコピーと置き換えます。

// cliext_hash_multiset_operator_as.cpp
// compile with: /clr
#include <cliext/hash_set>

typedef cliext::hash_multiset<wchar_t> Myhash_multiset;
int main()
    {
    Myhash_multiset c1;
    c1.insert(L'a');
    c1.insert(L'b');
    c1.insert(L'c');

    // display contents " a b c"
    for each (Myhash_multiset::value_type elem in c1)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();

    // assign to a new container
    Myhash_multiset c2;
    c2 = c1;
// display contents " a b c"
    for each (Myhash_multiset::value_type elem in c2)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();
    return (0);
    }
a b c
a b c

hash_multiset::rbegin

反転被制御シーケンスの先頭を指定します。

構文

reverse_iterator rbegin();

解説

このメンバー関数は、被制御シーケンスの最後の要素 (または空のシーケンスの先頭の次の位置) を指定する反転反復子を返します。 したがって、逆シーケンスを beginning 指定します。 これを使用して、被制御シーケンスの先頭を current 逆の順序で指定する反復子を取得しますが、被制御シーケンスの長さが変わると状態が変わる可能性があります。

// cliext_hash_multiset_rbegin.cpp
// compile with: /clr
#include <cliext/hash_set>

typedef cliext::hash_multiset<wchar_t> Myhash_multiset;
int main()
    {
    Myhash_multiset c1;
    c1.insert(L'a');
    c1.insert(L'b');
    c1.insert(L'c');

    // display initial contents " a b c"
    for each (wchar_t elem in c1)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();

    // inspect first two items in reversed sequence
    Myhash_multiset::reverse_iterator rit = c1.rbegin();
    System::Console::WriteLine("*rbegin() = {0}", *rit);
    System::Console::WriteLine("*++rbegin() = {0}", *++rit);
    return (0);
    }
a b c
*rbegin() = c
*++rbegin() = b

hash_multiset::reference

要素への参照の型です。

構文

typedef value_type% reference;

解説

この型は、要素への参照を表します。

// cliext_hash_multiset_reference.cpp
// compile with: /clr
#include <cliext/hash_set>

typedef cliext::hash_multiset<wchar_t> Myhash_multiset;
int main()
    {
    Myhash_multiset c1;
    c1.insert(L'a');
    c1.insert(L'b');
    c1.insert(L'c');

    // display initial contents " a b c"
    Myhash_multiset::iterator it = c1.begin();
    for (; it != c1.end(); ++it)
        {   // get a reference to an element
        Myhash_multiset::reference ref = *it;
        System::Console::Write("{0} ", ref);
        }
    System::Console::WriteLine();
    return (0);
    }
a b c

hash_multiset::rehash

ハッシュ テーブルをリビルドします。

構文

void rehash();

解説

メンバー関数はハッシュ テーブルを再構築し、次の点 load_factor() <= max_load_factor()を確認します。 それ以外の場合、ハッシュ テーブルのサイズは、挿入後に必要な場合にのみ増加します (サイズが自動的に減少することはありません。これを使用して、ハッシュ テーブルのサイズを調整します。

// cliext_hash_multiset_rehash.cpp
// compile with: /clr
#include <cliext/hash_set>

typedef cliext::hash_multiset<wchar_t> Myhash_multiset;
int main()
    {
    Myhash_multiset c1;
    c1.insert(L'a');
    c1.insert(L'b');
    c1.insert(L'c');

    // display initial contents " a b c"
    for each (wchar_t elem in c1)
        System::Console::Write("{0} ", elem);
    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 b c
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_multiset::rend

反転被制御シーケンスの末尾を指定します。

構文

reverse_iterator rend();

解説

このメンバー関数は、被制御シーケンスの先頭を超えた位置を示す反転反復子を返します。 したがって、逆シーケンスを end 指定します。 これを使用して、被制御シーケンスの末尾を逆の順序で指定 current する反復子を取得しますが、被制御シーケンスの長さが変わると状態が変わる可能性があります。

// cliext_hash_multiset_rend.cpp
// compile with: /clr
#include <cliext/hash_set>

typedef cliext::hash_multiset<wchar_t> Myhash_multiset;
int main()
    {
    Myhash_multiset c1;
    c1.insert(L'a');
    c1.insert(L'b');
    c1.insert(L'c');

    // display initial contents " a b c"
    for each (wchar_t elem in c1)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();

    // inspect first two items
    Myhash_multiset::reverse_iterator rit = c1.rend();
    --rit;
    System::Console::WriteLine("*-- --rend() = {0}", *--rit);
    System::Console::WriteLine("*--rend() = {0}", *++rit);
    return (0);
    }
a b c
*-- --rend() = b
*--rend() = a

hash_multiset::reverse_iterator

被制御シーケンスの反転反復子の型です。

構文

typedef T3 reverse_iterator;

解説

この型は、被制御シーケンスの反転反復子として使用できる未指定の T3 型のオブジェクトを表します。

// cliext_hash_multiset_reverse_iterator.cpp
// compile with: /clr
#include <cliext/hash_set>

typedef cliext::hash_multiset<wchar_t> Myhash_multiset;
int main()
    {
    Myhash_multiset c1;
    c1.insert(L'a');
    c1.insert(L'b');
    c1.insert(L'c');

    // display contents " a b c" reversed
    Myhash_multiset::reverse_iterator rit = c1.rbegin();
    for (; rit != c1.rend(); ++rit)
        System::Console::Write("{0} ", *rit);
    System::Console::WriteLine();
    return (0);
    }
c b a

hash_multiset::size

要素の数をカウントします。

構文

size_type size();

解説

このメンバー関数は、被制御シーケンスの長さを返します。 被制御シーケンス内の現在の要素の数を特定する場合に使います。 シーケンスに 0 以外のサイズがあるかどうかを考慮する必要がある場合は、次を参照してください hash_multiset::empty

// cliext_hash_multiset_size.cpp
// compile with: /clr
#include <cliext/hash_set>

typedef cliext::hash_multiset<wchar_t> Myhash_multiset;
int main()
    {
    Myhash_multiset c1;
    c1.insert(L'a');
    c1.insert(L'b');
    c1.insert(L'c');

    // display initial contents " a b c"
    for each (wchar_t elem in c1)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();
    System::Console::WriteLine("size() = {0} starting with 3", c1.size());

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

    // add elements and clear again
    c1.insert(L'a');
    c1.insert(L'b');
    System::Console::WriteLine("size() = {0} after adding 2", c1.size());
    return (0);
    }
a b c
size() = 3 starting with 3
size() = 0 after clearing
size() = 2 after adding 2

hash_multiset::size_type

2 つの要素間の距離を表す、符号付きの型です。

構文

typedef int size_type;

解説

この型は、負でない要素数を表します。

// cliext_hash_multiset_size_type.cpp
// compile with: /clr
#include <cliext/hash_set>

typedef cliext::hash_multiset<wchar_t> Myhash_multiset;
int main()
    {
    Myhash_multiset c1;
    c1.insert(L'a');
    c1.insert(L'b');
    c1.insert(L'c');

    // display initial contents " a b c"
    for each (wchar_t elem in c1)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();

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

hash_multiset::swap

2 つのコンテナーのコンテンツを交換します。

構文

void swap(hash_multiset<Key>% right);

パラメーター

right
コンテンツを交換するコンテナー。

解説

このメンバー関数は、thisright の間で被制御シーケンスを交換します。 一定時間に実行し、例外をスローしません。 2 つのコンテナーのコンテンツを簡単に交換する方法として、これを使用します。

// cliext_hash_multiset_swap.cpp
// compile with: /clr
#include <cliext/hash_set>

typedef cliext::hash_multiset<wchar_t> Myhash_multiset;
int main()
    {
    Myhash_multiset c1;
    c1.insert(L'a');
    c1.insert(L'b');
    c1.insert(L'c');

    // display initial contents " a b c"
    for each (wchar_t elem in c1)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();

    // construct another container with repetition of values
    Myhash_multiset c2;
    c2.insert(L'd');
    c2.insert(L'e');
    c2.insert(L'f');
    for each (wchar_t elem in c2)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();

    // swap and redisplay
    c1.swap(c2);
    for each (wchar_t elem in c1)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();

    for each (wchar_t elem in c2)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();
    return (0);
    }
a b c
d e f
d e f
a b c

hash_multiset::to_array

被制御シーケンスを新しい配列にコピーします。

構文

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

解説

このメンバー関数は、被制御シーケンスを含む配列を返します。 配列形式の被制御シーケンスのコピーを取得する場合に、これを使用します。

// cliext_hash_multiset_to_array.cpp
// compile with: /clr
#include <cliext/hash_set>

typedef cliext::hash_multiset<wchar_t> Myhash_multiset;
int main()
    {
    Myhash_multiset c1;
    c1.insert(L'a');
    c1.insert(L'b');
    c1.insert(L'c');

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

    c1.insert(L'd');
    for each (wchar_t elem in c1)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();

    // display the earlier array copy
    for each (wchar_t elem in a1)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();
    return (0);
    }
a b c d
a b c

hash_multiset::upper_bound

指定したキーに一致する範囲の末尾を検索します。

構文

iterator upper_bound(key_type key);

パラメーター

key
検索対象のキー値。

解説

メンバー関数は、同じバケットkeyにハッシュし、同等の順序を持つ、制御シーケンス内の最後の要素Xkey決定します。 このような要素が存在しない場合、または被制御シーケンスの最後の要素である場合 X は返されます。それ以外の場合は、 end()最初の要素を指定 Xする反復子を返します。 指定したキーに一致する、被制御シーケンス内の現在の要素のシーケンスの末尾を検索する場合に使います。

// cliext_hash_multiset_upper_bound.cpp
// compile with: /clr
#include <cliext/hash_set>

typedef cliext::hash_multiset<wchar_t> Myhash_multiset;
int main()
    {
    Myhash_multiset c1;
    c1.insert(L'a');
    c1.insert(L'b');
    c1.insert(L'c');

    // display initial contents " a b c"
    for each (wchar_t elem in c1)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();

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

    System::Console::WriteLine("*upper_bound(L'a') = {0}",
        *c1.upper_bound(L'a'));
    System::Console::WriteLine("*upper_bound(L'b') = {0}",
        *c1.upper_bound(L'b'));
    return (0);
    }
a b c
upper_bound(L'x')==end() = True
*upper_bound(L'a') = b
*upper_bound(L'b') = c

hash_multiset::value_comp

2 つの要素値の順序付けデリゲートをコピーします。

構文

value_compare^ value_comp();

解説

このメンバー関数は、被制御シーケンスの順序付けに使用される順序付けデリゲートを返します。 2 つの要素値を比較する場合に、これを使用します。

// cliext_hash_multiset_value_comp.cpp
// compile with: /clr
#include <cliext/hash_set>

typedef cliext::hash_multiset<wchar_t> Myhash_multiset;
int main()
    {
    Myhash_multiset c1;
    Myhash_multiset::value_compare^ kcomp = c1.value_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();
    return (0);
    }
compare(L'a', L'a') = True
compare(L'a', L'b') = True
compare(L'b', L'a') = False

hash_multiset::value_compare

2 つの要素値の順序付けデリゲートです。

構文

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

解説

この型は、値の引数の順序付けを決定するデリゲートのシノニムです。

// cliext_hash_multiset_value_compare.cpp
// compile with: /clr
#include <cliext/hash_set>

typedef cliext::hash_multiset<wchar_t> Myhash_multiset;
int main()
    {
    Myhash_multiset c1;
    Myhash_multiset::value_compare^ kcomp = c1.value_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();
    return (0);
    }
compare(L'a', L'a') = True
compare(L'a', L'b') = True
compare(L'b', L'a') = False

hash_multiset::value_type

要素の型。

構文

typedef generic_value value_type;

解説

型は、generic_value の同意語。

// cliext_hash_multiset_value_type.cpp
// compile with: /clr
#include <cliext/hash_set>

typedef cliext::hash_multiset<wchar_t> Myhash_multiset;
int main()
    {
    Myhash_multiset c1;
    c1.insert(L'a');
    c1.insert(L'b');
    c1.insert(L'c');

    // display contents " a b c" using value_type
    for (Myhash_multiset::iterator it = c1.begin(); it != c1.end(); ++it)
        {   // store element in value_type object
        Myhash_multiset::value_type val = *it;

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