hash_multiset (STL/CLR)

樣板類別描述一個物件,該物件控制具有雙向存取權之元素的不同長度序列。 您可以使用容器 hash_multiset 來管理元素序列做為雜湊表、儲存節點雙向連結清單的每個資料表專案,以及每個儲存一個元素的節點。 每個元素的值會用來做為索引鍵,以便排序序列。

在下列描述中, GValue 與 相同 GKey ,這反過來會與 Key 相同,除非後者是 ref 類型,在此情況下為 Key^

語法

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 兩個元素之間的 (可能帶正負號) 距離的類型。
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 兩個索引鍵的排序委派。
hash_multiset::key_type 排序索引鍵的類型。
hash_multiset::reference 項目的參考類型。
hash_multiset::reverse_iterator 受控制序列的反向迭代器類型。
hash_multiset::size_type 兩個專案之間 (非負數) 距離的類型。
hash_multiset::value_compare 兩個元素值的排序委派。
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 複製兩個索引鍵的排序委派。
hash_multiset::load_factor 計算每個值區的平均項目數。
hash_multiset::lower_bound 尋找符合指定索引鍵的範圍開頭。
hash_multiset::make_value 建構值物件。
hash_multiset::max_load_factor 取得或設定每個 Bucket 最大項目數。
hash_multiset::rbegin 指定反向受控制序列的開頭。
hash_multiset::rehash 重建雜湊資料表。
hash_multiset::rend 指定反向受控制序列的結尾。
hash_multiset::size 計算元素的數目。
hash_multiset::swap 交換兩個容器的內容。
hash_multiset::to_array 將受控制序列複製到新的陣列。
hash_multiset::upper_bound 尋找符合指定索引鍵的範圍結尾。
hash_multiset::value_comp 複製兩個元素值的排序委派。
運算子 描述
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 索引鍵之間的對等順序。 這表示,針對任何兩個索引鍵 XY

key_comp()(X, Y) 會在每個呼叫上傳回相同的布林值結果。

如果 key_comp()(X, Y) && key_comp()(Y, X) 為 true,則 X 表示 Y 具有對等的排序。

任何行為類似 operator<=(key_type, key_type) 的排序規則, operator>=(key_type, key_type)operator==(key_type, key_type) 定義對等的排序。

容器只會確保索引鍵具有對等順序的專案(以及相同整數值的雜湊)在貯體內相鄰。 不同于範本類別 (STL/CLR), 樣板類別 hash_sethash_multiset 的物件不需要所有元素的索引鍵是唯一的。 (兩個或多個索引鍵可以有對等的排序。

物件會藉由呼叫 類型的 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

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();

備註

成員函式會傳回目前的 Bucket 數目。 您可以使用它來判斷雜湊表的大小。

範例

// 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

兩個專案之間帶正負號距離的類型。

語法

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() 這類專案,則傳回反覆運算器。 您可以使用它來移除單一元素。

第二個成員函式會移除範圍 [ firstlast ] 中受控制序列的元素,並傳回反覆運算器,指定任何移除之元素以外的第一個元素,如果沒有 end() 這類專案,則傳回反覆運算器。 您可以使用它來移除零個或多個連續元素。

第三個成員函式會移除受控制序列的任何專案,其索引鍵的排序 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
要搜尋的索引鍵值。

備註

如果受控制序列中至少有一個專案具有對等的順序 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() 使用預設順序述詞以及預設雜湊函式,初始化受控制序列。 您可以使用它來指定一個初始受控制序列,這是由 hash_multiset 物件 right 所控制之序列的複本,以及預設排序述詞和雜湊函式。

建構函式:

hash_multiset(hash_multiset<Key>^ right);

使用序列 [ right->begin()right->end() 使用預設順序述詞以及預設雜湊函式,初始化受控制序列。 您可以使用它來指定一個初始受控制序列,這是由 hash_multiset 物件 right 所控制之序列的複本,以及預設排序述詞和雜湊函式。

建構函式:

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

使用序列 [ firstlast 使用預設順序述詞以及預設雜湊函式,初始化受控制序列。 您可以使用它讓受控制序列成為另一個序列的複本,並使用預設順序述詞和雜湊函式。

建構函式:

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

使用順序述 pred 詞 ,並使用預設雜湊函式,使用序列 [ firstlast 初始化受控制序列。 您可以使用它讓受控制序列成為另一個序列的複本,並搭配指定的排序述詞和預設雜湊函式。

建構函式:

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

使用序列 [ firstlast 使用排序述詞 pred ,以及雜湊函 hashfn 式 ,初始化受控制序列。 您可以使用它讓受控制序列成為另一個序列的複本,並搭配指定的排序述詞和雜湊函式。

建構函式:

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 的專案,並傳回反覆運算器,指定新插入的專案。 您可以使用它來插入單一元素。

第二個成員函式會使用 where 作為提示來插入具有 值 val 的專案,並傳回指定新插入元素的反覆運算器。 您可以使用它來插入可能位於您知道之專案旁邊的單一元素。

第三個成員函式會插入序列 [ firstlast 。 您可以使用它插入從另一個序列複製的零個或多個專案。

第四個成員函式會插入 所 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

複製兩個索引鍵的排序委派。

語法

key_compare^key_comp();

備註

成員函式會傳回用來排序受控制序列的排序委派。 您可以使用它來比較兩個索引鍵。

範例

// 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

兩個索引鍵的排序委派。

語法

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
要搜尋的索引鍵值。

備註

成員函式會決定受控制序列中的第一個元素,該元素 X 會雜湊至與 相同的貯 key 體,並且具有對等的順序 key 。 如果不存在這類專案,則會傳 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
要使用的索引鍵值。

備註

成員函式會傳 value_type 回索引鍵為 key 的物件。 您可以使用它來撰寫適合與數個其他成員函式搭配使用的物件。

範例

// 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

取得或設定每個 Bucket 最大項目數。

語法

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

參數

new_factor
要儲存的新最大負載因數。

備註

第一個成員函式會傳回目前儲存的最大負載因數。 您可以使用它來判斷平均貯體大小上限。

第二個成員函式會將存放區最大負載因數取代為 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();

備註

成員函式會傳回受控制序列的長度。 您可以使用它來判斷目前在受控制序列中的元素數目。 如果您關心的只是序列是否具有非零大小,請參閱 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

兩個項目之間帶正負號距離的類型。

語法

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

交換兩個容器的內容。

語法

void swap(hash_multiset<Key>% right);

參數

right
要交換內容的容器。

備註

成員函式會交換 thisright 之間受控制的序列。 它會在固定時間內執行此動作,而且不會擲回任何例外狀況。 您可以使用它作為交換兩個容器內容的快速方式。

範例

// 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
要搜尋的索引鍵值。

備註

成員函式會決定受控制序列中的最後一個專案,該元素 X 會雜湊至與 相同的貯 key 體,而且其順序 key 相當於 。 如果不存在這類專案,或者如果 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

複製兩個元素值的排序委派。

語法

value_compare^ value_comp();

備註

成員函式會傳回用來排序受控制序列的排序委派。 您可以使用它來比較兩個元素值。

範例

// 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

兩個元素值的排序委派。

語法

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