hash_set (STL/CLR)

Kelas templat menjelaskan objek yang mengontrol urutan elemen dengan panjang yang bervariasi yang memiliki akses dua arah. Anda menggunakan kontainer hash_set untuk mengelola urutan elemen sebagai tabel hash, setiap entri tabel menyimpan daftar node yang ditautkan dua arah, dan setiap simpul menyimpan satu elemen. Nilai setiap elemen digunakan sebagai kunci, untuk mengurutkan urutan.

Dalam deskripsi di bawah ini, GValue sama dengan GKey, yang pada gilirannya sama dengan Key kecuali yang terakhir adalah jenis ref, dalam hal ini Key^adalah .

Sintaks

template<typename Key>
    ref class hash_set
        :   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>
    { ..... };

Parameter

Key
Jenis komponen kunci elemen dalam urutan terkontrol.

Persyaratan

Header:<cliext/hash_set>

Ruang nama:cliext

Deklarasi

Definisi jenis Deskripsi
hash_set::const_iterator Jenis iterator konstan untuk urutan terkontrol.
hash_set::const_reference Jenis referensi konstanta ke elemen.
hash_set::const_reverse_iterator Jenis iterator terbalik konstan untuk urutan terkontrol.
hash_set::difference_type Jenis jarak (mungkin ditandatangani) antara dua elemen.
hash_set::generic_container Jenis antarmuka generik untuk kontainer.
hash_set::generic_iterator Jenis iterator untuk antarmuka generik untuk kontainer.
hash_set::generic_reverse_iterator Jenis iterator terbalik untuk antarmuka generik untuk kontainer.
hash_set::generic_value Jenis elemen untuk antarmuka generik untuk kontainer.
hash_set::hasher Delegasi hash untuk kunci.
hash_set::iterator Jenis iterator untuk urutan yang dikontrol.
hash_set::key_compare Delegasi pemesanan untuk dua kunci.
hash_set::key_type Jenis kunci pemesanan.
hash_set::reference Jenis referensi ke elemen.
hash_set::reverse_iterator Jenis iterator terbalik untuk urutan yang dikontrol.
hash_set::size_type Jenis jarak (non-negatif) antara dua elemen.
hash_set::value_compare Delegasi pengurutan untuk dua nilai elemen.
hash_set::value_type Jenis elemen.
Fungsi anggota Deskripsi
hash_set::begin Menunjuk awal urutan yang dikontrol.
hash_set::bucket_count Menghitung jumlah wadah.
hash_set::clear Menghapus semua elemen.
hash_set::count Menghitung elemen yang cocok dengan kunci tertentu.
hash_set::empty Menguji apakah tidak ada elemen yang ada.
hash_set::end Menunjuk akhir urutan yang dikontrol.
hash_set::equal_range Menemukan rentang yang cocok dengan kunci tertentu.
hash_set::erase Menghapus elemen pada posisi yang ditentukan.
hash_set::find Menemukan elemen yang cocok dengan kunci tertentu.
hash_set::hash_delegate Menyalin delegasi hashing untuk kunci.
hash_set::hash_set Membuat objek kontainer.
hash_set::insert Menambahkan elemen.
hash_set::key_comp Menyalin delegasi pengurutan untuk dua kunci.
hash_set::load_factor Menghitung elemen rata-rata per wadah.
hash_set::lower_bound Menemukan awal rentang yang cocok dengan kunci tertentu.
hash_set::make_value Membuat objek nilai.
hash_set::max_load_factor Mendapatkan atau mengatur elemen maksimum per wadah.
hash_set::rbegin Menunjuk awal urutan terkontrol terbalik.
hash_set::rehash Membangun kembali tabel hash.
hash_set::rend Menunjuk akhir urutan terkontrol terbalik.
hash_set::size Menghitung jumlah elemen.
hash_set::swap Menukar isi dua kontainer.
hash_set::to_array Menyalin urutan terkontrol ke array baru.
hash_set::upper_bound Menemukan akhir rentang yang cocok dengan kunci tertentu.
hash_set::value_comp Menyalin delegasi pengurutan untuk dua nilai elemen.
Operator Deskripsi
hash_set::operator= Menggantikan urutan terkontrol.

Antarmuka

Antarmuka Deskripsi
ICloneable Menduplikasi objek.
IEnumerable Urutan melalui elemen.
ICollection Pertahankan grup elemen.
IEnumerable<T> Urutan melalui elemen yang ditik.
ICollection<T> Pertahankan grup elemen yang diketik.
IHash<Key, Value> Pertahankan kontainer generik.

Keterangan

Objek mengalokasikan dan membebaskan penyimpanan untuk urutan yang dikontrolnya sebagai simpul individual dalam daftar tertaut dua arah. Untuk mempercepat akses, objek juga mempertahankan array pointer dengan panjang yang bervariasi ke dalam daftar (tabel hash), secara efektif mengelola seluruh daftar sebagai urutan sublist, atau wadah. Ini menyisipkan elemen ke dalam wadah yang terus diurutkan dengan mengubah tautan antar simpul, tidak pernah dengan menyalin konten satu simpul ke simpul lain. Itu berarti Anda dapat menyisipkan dan menghapus elemen dengan bebas tanpa mengganggu elemen yang tersisa.

Objek memesan setiap wadah yang dikontrolnya dengan memanggil objek delegasi tersimpan jenis hash_set::key_compare. Anda dapat menentukan objek delegasi tersimpan saat membuat hash_set; jika Anda tidak menentukan objek delegasi, defaultnya adalah perbandingan operator<=(key_type, key_type).

Anda mengakses objek delegasi tersimpan dengan memanggil fungsi hash_set::key_companggota . Objek delegasi semacam itu harus menentukan pengurutan yang setara antara kunci jenis hash_set::key_type. Itu berarti, untuk dua kunci X dan Y:

key_comp()(X, Y) mengembalikan hasil Boolean yang sama pada setiap panggilan.

Jika key_comp()(X, Y) && key_comp()(Y, X) benar, maka X dan Y dikatakan memiliki urutan yang setara.

Aturan pengurutan apa pun yang bertingkah seperti operator<=(key_type, key_type), operator>=(key_type, key_type) atau operator==(key_type, key_type) mendefinisikan pengurutan yang setara.

Kontainer hanya memastikan bahwa elemen yang kuncinya memiliki pengurutan yang setara (dan hash mana dengan nilai bilangan bulat yang sama) yang berdekatan dalam wadah. Tidak seperti kelas templat hash_multiset (STL/CLR), objek kelas hash_set templat memastikan bahwa kunci untuk semua elemen unik. (Tidak ada dua kunci yang memiliki urutan yang setara.)

Objek menentukan wadah mana yang harus berisi kunci pengurutan tertentu dengan memanggil objek delegasi tersimpan dari jenis hash_set::hasher. Anda mengakses objek tersimpan ini dengan memanggil fungsi hash_set::hash_delegate anggota untuk mendapatkan nilai bilangan bulat yang bergantung pada nilai kunci. Anda dapat menentukan objek delegasi tersimpan saat membuat hash_set; jika Anda tidak menentukan objek delegasi, defaultnya adalah fungsi System::Object::hash_value(key_type). Itu berarti, untuk kunci X apa pun dan Y:

hash_delegate()(X) mengembalikan hasil bilangan bulat yang sama pada setiap panggilan.

Jika X dan Y memiliki pengurutan yang setara, maka hash_delegate()(X) harus mengembalikan hasil bilangan bulat yang sama dengan hash_delegate()(Y).

Setiap elemen berfungsi sebagai kunci dan nilai. Urutan diwakili dengan cara yang mengizinkan pencarian, penyisipan, dan penghapusan elemen arbitrer dalam waktu konstan. Artinya, jumlah operasi tidak tergantung pada jumlah elemen dalam urutan, setidaknya dalam kasus terbaik. Selain itu, memasukkan elemen tidak membatalkan iterator, dan menghapus elemen hanya membatalkan iterator yang menunjuk pada elemen yang dihapus.

Namun, jika nilai hash tidak didistribusikan secara seragam, tabel hash dapat berdegenerasi. Secara ekstrem (untuk fungsi hash yang selalu mengembalikan nilai yang sama), pencarian, penyisipan, dan penghapusan sebanding dengan jumlah elemen dalam urutan (waktu linier). Kontainer berusaha untuk memilih fungsi hash yang wajar, ukuran bucket rata-rata, dan ukuran hash-table (jumlah total wadah), tetapi Anda dapat mengambil alih salah satu atau semua pilihan ini. Lihat, misalnya, fungsi hash_set::max_load_factor dan hash_set::rehash.

Mendukung hash_set iterator dua arah, yang berarti Anda dapat melangkah ke elemen yang berdekatan mengingat iterator yang menunjuk elemen dalam urutan terkontrol. Simpul kepala khusus sesuai dengan iterator yang dikembalikan oleh end(). Anda dapat mengurangi iterator ini untuk mencapai elemen terakhir dalam urutan terkontrol, jika ada. Anda dapat menaikkan hash_set iterator untuk mencapai simpul kepala, dan kemudian akan dibandingkan dengan end(). Tetapi Anda tidak dapat mendereferensikan iterator yang dikembalikan oleh end().

Anda tidak dapat merujuk ke elemen secara hash_set langsung mengingat posisi numeriknya. Itu membutuhkan iterator akses acak.

Iterator hash_set menyimpan handel ke simpul terkait hash_set , yang pada gilirannya menyimpan handel ke kontainer terkait. Anda hanya dapat menggunakan iterator dengan objek kontainer terkait. Iterator hash_set tetap valid selama simpul terkait hash_set dikaitkan dengan beberapa hash_set. Selain itu, iterator yang valid dapat didereferensikan. Anda dapat menggunakannya untuk mengakses atau mengubah nilai elemen yang ditunjuknya, selama tidak sama dengan end().

Menghapus atau menghapus elemen memanggil destruktor untuk nilai tersimpannya. Menghancurkan kontainer akan menghapus semua elemen. Dengan demikian, kontainer yang jenis elemennya adalah kelas ref memastikan bahwa tidak ada elemen yang lebih lama dari kontainer. Namun, kontainer handel tidak menghancurkan elemennya.

Anggota

hash_set::begin

Menunjuk awal urutan yang dikontrol.

Sintaks

iterator begin();

Keterangan

Fungsi anggota mengembalikan iterator dua arah yang menunjuk elemen pertama dari urutan yang dikontrol, atau tepat di luar akhir urutan kosong. Anda menggunakannya untuk mendapatkan iterator yang menunjuk current awal urutan terkontrol, tetapi statusnya dapat berubah jika panjang urutan terkontrol berubah.

Contoh

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

typedef cliext::hash_set<wchar_t> Myhash_set;
int main()
    {
    Myhash_set 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_set::iterator it = c1.begin();
    System::Console::WriteLine("*begin() = {0}", *it);
    System::Console::WriteLine("*++begin() = {0}", *++it);
    return (0);
    }

hash_set::bucket_count

Menghitung jumlah wadah.

Sintaks

int bucket_count();

Keterangan

Fungsi anggota mengembalikan jumlah wadah saat ini. Anda menggunakannya untuk menentukan ukuran tabel hash.

Contoh

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

typedef cliext::hash_set<wchar_t> Myhash_set;
int main()
    {
    Myhash_set 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_set::clear

Menghapus semua elemen.

Sintaks

void clear();

Keterangan

Fungsi anggota secara efektif memanggil erase(begin(), end()). Anda menggunakannya untuk memastikan bahwa urutan yang dikontrol kosong.

Contoh

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

typedef cliext::hash_set<wchar_t> Myhash_set;
int main()
    {
    Myhash_set 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_set::const_iterator

Jenis iterator konstan untuk urutan terkontrol.

Sintaks

typedef T2 const_iterator;

Keterangan

Jenis ini menjelaskan objek jenis yang tidak ditentukan T2 yang dapat berfungsi sebagai iterator dua arah konstan untuk urutan yang dikontrol.

Contoh

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

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

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

hash_set::const_reference

Jenis referensi konstanta ke elemen.

Sintaks

typedef value_type% const_reference;

Keterangan

Jenis ini menjelaskan referensi konstan ke elemen.

Contoh

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

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

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

hash_set::const_reverse_iterator

Jenis iterator terbalik konstan untuk urutan terkontrol.

Sintaks

typedef T4 const_reverse_iterator;

Keterangan

Jenis menjelaskan objek jenis yang tidak ditentukan T4 yang dapat berfungsi sebagai iterator terbalik konstan untuk urutan yang dikontrol.

Contoh

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

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

    // display contents " a b c" reversed
    Myhash_set::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_set::count

Menemukan jumlah elemen yang cocok dengan kunci tertentu.

Sintaks

size_type count(key_type key);

Parameter

key
Nilai kunci yang akan dicari.

Keterangan

Fungsi anggota mengembalikan jumlah elemen dalam urutan terkontrol yang memiliki pengurutan yang setara dengan key. Anda menggunakannya untuk menentukan jumlah elemen yang saat ini berada dalam urutan terkontrol yang cocok dengan kunci yang ditentukan.

Contoh

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

typedef cliext::hash_set<wchar_t> Myhash_set;
int main()
    {
    Myhash_set 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_set::difference_type

Jenis jarak yang ditandatangani antara dua elemen.

Sintaks

typedef int difference_type;

Keterangan

Jenis ini menjelaskan jumlah elemen yang mungkin negatif.

Contoh

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

typedef cliext::hash_set<wchar_t> Myhash_set;
int main()
    {
    Myhash_set 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_set::difference_type diff = 0;
    for (Myhash_set::iterator it = c1.begin(); it != c1.end(); ++it)
        ++diff;
    System::Console::WriteLine("end()-begin() = {0}", diff);

    // compute negative difference
    diff = 0;
    for (Myhash_set::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_set::empty

Menguji apakah tidak ada elemen yang ada.

Sintaks

bool empty();

Keterangan

Fungsi anggota mengembalikan true untuk urutan yang dikontrol kosong. Ini setara dengan size() == 0. Anda menggunakannya untuk menguji apakah hash_set kosong.

Contoh

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

typedef cliext::hash_set<wchar_t> Myhash_set;
int main()
    {
    Myhash_set 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_set::end

Menunjuk akhir urutan yang dikontrol.

Sintaks

iterator end();

Keterangan

Fungsi anggota mengembalikan iterator dua arah yang menunjuk tepat di luar akhir urutan yang dikontrol. Anda menggunakannya untuk mendapatkan iterator yang menunjuk akhir urutan yang dikontrol; statusnya tidak berubah jika panjang urutan terkontrol berubah.

Contoh

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

typedef cliext::hash_set<wchar_t> Myhash_set;
int main()
    {
    Myhash_set 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_set::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_set::equal_range

Menemukan rentang yang cocok dengan kunci tertentu.

Sintaks

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

Parameter

key
Nilai kunci yang akan dicari.

Keterangan

Fungsi anggota mengembalikan sepasang iterator cliext::pair<iterator, iterator>(lower_bound(key), upper_bound(key)). Anda menggunakannya untuk menentukan rentang elemen yang saat ini berada dalam urutan terkontrol yang cocok dengan kunci yang ditentukan.

Contoh

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

typedef cliext::hash_set<wchar_t> Myhash_set;
typedef Myhash_set::pair_iter_iter Pairii;
int main()
    {
    Myhash_set 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_set::erase

Menghapus elemen pada posisi yang ditentukan.

Sintaks

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

Parameter

first
Awal rentang untuk menghapus.

key
Nilai kunci untuk menghapus.

last
Akhir rentang untuk menghapus.

where
Elemen untuk menghapus.

Keterangan

Fungsi anggota pertama menghapus elemen urutan terkontrol yang diarahkan oleh where, dan mengembalikan iterator yang menunjuk elemen pertama yang tersisa di luar elemen yang dihapus, atau end() jika tidak ada elemen tersebut. Anda menggunakannya untuk menghapus satu elemen.

Fungsi anggota kedua menghapus elemen urutan terkontrol dalam rentang [first, last), dan mengembalikan iterator yang menunjuk elemen pertama yang tersisa di luar elemen apa pun yang dihapus, atau end() jika tidak ada elemen tersebut. Anda menggunakannya untuk menghapus nol atau lebih elemen yang berdada.

Fungsi anggota ketiga menghapus elemen apa pun dari urutan terkontrol yang kuncinya memiliki urutan yang setara dengan key, dan mengembalikan hitungan jumlah elemen yang dihapus. Anda menggunakannya untuk menghapus dan menghitung semua elemen yang cocok dengan kunci tertentu.

Setiap penghapusan elemen membutuhkan waktu yang sebanding dengan logaritma jumlah elemen dalam urutan yang dikontrol.

Contoh

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

typedef cliext::hash_set<wchar_t> Myhash_set;
int main()
    {
    Myhash_set 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_set::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_set::find

Menemukan elemen yang cocok dengan kunci tertentu.

Sintaks

iterator find(key_type key);

Parameter

key
Nilai kunci yang akan dicari.

Keterangan

Jika setidaknya satu elemen dalam urutan terkontrol memiliki urutan yang setara dengan key, fungsi anggota mengembalikan iterator yang menunjuk salah satu elemen tersebut; jika tidak, ia mengembalikan end(). Anda menggunakannya untuk menemukan elemen yang saat ini berada dalam urutan terkontrol yang cocok dengan kunci yang ditentukan.

Contoh

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

typedef cliext::hash_set<wchar_t> Myhash_set;
int main()
    {
    Myhash_set 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_set::generic_container

Jenis antarmuka generik untuk kontainer.

Sintaks

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

Keterangan

Jenis menjelaskan antarmuka generik untuk kelas kontainer templat ini.

Contoh

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

typedef cliext::hash_set<wchar_t> Myhash_set;
int main()
    {
    Myhash_set 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_set::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_set::generic_iterator

Jenis iterator untuk digunakan dengan antarmuka generik untuk kontainer.

Sintaks

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

Keterangan

Jenis ini menjelaskan iterator generik yang dapat digunakan dengan antarmuka generik untuk kelas kontainer templat ini.

Contoh

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

typedef cliext::hash_set<wchar_t> Myhash_set;
int main()
    {
    Myhash_set 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_set::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_set::generic_iterator gcit = gc1->begin();
    Myhash_set::generic_value gcval = *gcit;
    System::Console::WriteLine("{0} ", gcval);
    return (0);
    }
a b c
a b c
a

hash_set::generic_reverse_iterator

Jenis iterator terbalik untuk digunakan dengan antarmuka generik untuk kontainer.

Sintaks

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

Keterangan

Jenis ini menjelaskan iterator terbalik generik yang dapat digunakan dengan antarmuka generik untuk kelas kontainer templat ini.

Contoh

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

typedef cliext::hash_set<wchar_t> Myhash_set;
int main()
    {
    Myhash_set 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_set::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_set::generic_reverse_iterator gcit = gc1->rbegin();
    Myhash_set::generic_value gcval = *gcit;
    System::Console::WriteLine("{0} ", gcval);
    return (0);
    }
a b c
a b c
c

hash_set::generic_value

Jenis elemen untuk digunakan dengan antarmuka generik untuk kontainer.

Sintaks

typedef GValue generic_value;

Keterangan

Jenis menjelaskan objek jenis GValue yang menjelaskan nilai elemen tersimpan untuk digunakan dengan antarmuka generik untuk kelas kontainer templat ini.

Contoh

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

typedef cliext::hash_set<wchar_t> Myhash_set;
int main()
    {
    Myhash_set 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_set::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_set::generic_iterator gcit = gc1->begin();
    Myhash_set::generic_value gcval = *gcit;
    System::Console::WriteLine("{0} ", gcval);
    return (0);
    }
a b c
a b c
a

hash_set::hash_delegate

Menemukan elemen yang cocok dengan kunci tertentu.

Sintaks

hasher^ hash_delegate();

Keterangan

Fungsi anggota mengembalikan delegasi yang digunakan untuk mengonversi nilai kunci menjadi bilangan bulat. Anda menggunakannya untuk hash kunci.

Contoh

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

typedef cliext::hash_set<wchar_t> Myhash_set;
int main()
    {
    Myhash_set c1;
    Myhash_set::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_set::hash_set

Membuat objek kontainer.

Sintaks

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

Parameter

first
Awal rentang yang akan disisipkan.

hashfn
Fungsi hash untuk memetakan kunci ke wadah.

last
Akhir rentang untuk disisipkan.

pred
Memesan predikat untuk urutan yang dikendalikan.

right
Objek atau rentang untuk disisipkan.

Keterangan

Konstruktor:

hash_set();

menginisialisasi urutan terkontrol tanpa elemen, dengan predikat key_compare()pengurutan default , dan dengan fungsi hash default. Anda menggunakannya untuk menentukan urutan awal yang dikontrol kosong, dengan predikat pengurutan default dan fungsi hash.

Konstruktor:

explicit hash_set(key_compare^ pred);

menginisialisasi urutan terkontrol tanpa elemen, dengan predikat predpengurutan , dan dengan fungsi hash default. Anda menggunakannya untuk menentukan urutan awal yang dikontrol kosong, dengan predikat pengurutan yang ditentukan dan fungsi hash default.

Konstruktor:

hash_set(key_compare^ pred, hasher^ hashfn);

menginisialisasi urutan terkontrol tanpa elemen, dengan predikat predpengurutan , dan dengan fungsi hashfnhash . Anda menggunakannya untuk menentukan urutan awal yang dikontrol kosong, dengan predikat pengurutan dan fungsi hash yang ditentukan.

Konstruktor:

hash_set(hash_set<Key>% right);

menginisialisasi urutan terkontrol dengan urutan [right.begin(), right.end()), dengan predikat pengurutan default, dan dengan fungsi hash default. Anda menggunakannya untuk menentukan urutan terkontrol awal yang merupakan salinan urutan yang dikontrol hash_set oleh objek right, dengan predikat pengurutan default dan fungsi hash.

Konstruktor:

hash_set(hash_set<Key>^ right);

menginisialisasi urutan terkontrol dengan urutan [right->begin(), right->end()), dengan predikat pengurutan default, dan dengan fungsi hash default. Anda menggunakannya untuk menentukan urutan terkontrol awal yang merupakan salinan urutan yang dikontrol hash_set oleh objek right, dengan predikat pengurutan default dan fungsi hash.

Konstruktor:

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

menginisialisasi urutan terkontrol dengan urutan [first, last), dengan predikat pengurutan default, dan dengan fungsi hash default. Anda menggunakannya untuk membuat urutan terkontrol sebagai salinan urutan lain, dengan predikat pengurutan default dan fungsi hash.

Konstruktor:

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

menginisialisasi urutan terkontrol dengan urutan [first, last), dengan predikat predpengurutan , dan dengan fungsi hash default. Anda menggunakannya untuk membuat urutan terkontrol sebagai salinan urutan lain, dengan predikat pengurutan yang ditentukan dan fungsi hash default.

Konstruktor:

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

menginisialisasi urutan terkontrol dengan urutan [first, last), dengan predikat predpengurutan , dan dengan fungsi hashfnhash . Anda menggunakannya untuk membuat urutan terkontrol sebagai salinan urutan lain, dengan predikat urutan dan fungsi hash yang ditentukan.

Konstruktor:

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

menginisialisasi urutan terkontrol dengan urutan yang ditunjuk oleh enumerator right, dengan predikat pengurutan default, dan dengan fungsi hash default. Anda menggunakannya untuk membuat urutan terkontrol sebagai salinan urutan lain yang dijelaskan oleh enumerator, dengan predikat pengurutan default dan fungsi hash.

Konstruktor:

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

menginisialisasi urutan terkontrol dengan urutan yang ditunjuk oleh enumerator right, dengan predikat predpengurutan , dan dengan fungsi hash default. Anda menggunakannya untuk membuat urutan terkontrol salinan urutan lain yang dijelaskan oleh enumerator, dengan predikat pengurutan yang ditentukan dan fungsi hash default.

Konstruktor:

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

menginisialisasi urutan terkontrol dengan urutan yang ditunjuk oleh enumerator right, dengan predikat predpengurutan , dan dengan fungsi hashfnhash . Anda menggunakannya untuk membuat urutan terkontrol salinan urutan lain yang dijelaskan oleh enumerator, dengan predikat pengurutan dan fungsi hash yang ditentukan.

Contoh

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

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

typedef cliext::hash_set<wchar_t> Myhash_set;
int main()
    {
// construct an empty container
    Myhash_set 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_set 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_set c2h(cliext::greater_equal<wchar_t>(),
        gcnew Myhash_set::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_set 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_set 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_set c4h(c1.begin(), c1.end(),
        cliext::greater_equal<wchar_t>(),
        gcnew Myhash_set::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_set 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_set 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_set c6h(   // NOTE: cast is not needed
        (System::Collections::Generic::IEnumerable<wchar_t>^)%c3,
            cliext::greater_equal<wchar_t>(),
                gcnew Myhash_set::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_set c7(c4);
    for each (wchar_t elem in c7)
        System::Console::Write("{0} ", elem);
    System::Console::WriteLine();

    // construct by copying another container
    Myhash_set 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_set::hasher

Delegasi hash untuk kunci.

Sintaks

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

Keterangan

Jenis menjelaskan delegasi yang mengonversi nilai kunci menjadi bilangan bulat.

Contoh

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

typedef cliext::hash_set<wchar_t> Myhash_set;
int main()
    {
    Myhash_set c1;
    Myhash_set::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_set::insert

Menambahkan elemen.

Sintaks

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

Parameter

first
Awal rentang yang akan disisipkan.

last
Akhir rentang untuk disisipkan.

right
Enumerasi untuk disisipkan.

val
Nilai kunci untuk disisipkan.

where
Di mana dalam kontainer untuk disisipkan (petunjuk saja).

Keterangan

Setiap fungsi anggota menyisipkan urutan yang ditentukan oleh operand yang tersisa.

Fungsi anggota pertama berupaya menyisipkan elemen dengan nilai val, dan mengembalikan sepasang nilai X. Jika X.second benar, X.first menunjuk elemen yang baru disisipkan; jika tidak X.first menunjuk elemen dengan pengurutan yang setara yang sudah ada dan tidak ada elemen baru yang dimasukkan. Anda menggunakannya untuk menyisipkan satu elemen.

Fungsi anggota kedua menyisipkan elemen dengan nilai val, menggunakan where sebagai petunjuk (untuk meningkatkan performa), dan mengembalikan iterator yang menunjuk elemen yang baru dimasukkan. Anda menggunakannya untuk menyisipkan satu elemen yang mungkin berada di samping elemen yang Anda ketahui.

Fungsi anggota ketiga menyisipkan urutan [first, last). Anda menggunakannya untuk menyisipkan nol atau lebih elemen yang disalin dari urutan lain.

Fungsi anggota keempat menyisipkan urutan yang ditunjuk oleh right. Anda menggunakannya untuk menyisipkan urutan yang dijelaskan oleh enumerator.

Setiap penyisipan elemen membutuhkan waktu sebanding dengan logaritma jumlah elemen dalam urutan yang dikontrol. Penyisipan dapat terjadi dalam waktu konstanta yang diamortisasi, namun, mengingat petunjuk yang menunjuk elemen di samping titik penyisipan.

Contoh

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

typedef cliext::hash_set<wchar_t> Myhash_set;
typedef Myhash_set::pair_iter_bool Pairib;
int main()
    {
    Myhash_set 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
    Pairib pair1 = c1.insert(L'x');
    System::Console::WriteLine("insert(L'x') = [{0} {1}]",
        *pair1.first, pair1.second);

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

    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_set c2;
    Myhash_set::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_set 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 True]
insert(L'b') = [b False]
a b c x
insert(begin(), L'y') = y
a b c x y
a b c x
a b c x y

hash_set::iterator

Jenis iterator untuk urutan yang dikontrol.

Sintaks

typedef T1 iterator;

Keterangan

Jenis ini menjelaskan objek jenis yang tidak ditentukan T1 yang dapat berfungsi sebagai iterator dua arah untuk urutan terkontrol.

Contoh

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

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

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

hash_set::key_comp

Menyalin delegasi pengurutan untuk dua kunci.

Sintaks

key_compare^key_comp();

Keterangan

Fungsi anggota mengembalikan delegasi pengurutan yang digunakan untuk mengurutkan urutan yang dikontrol. Anda menggunakannya untuk membandingkan dua kunci.

Contoh

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

typedef cliext::hash_set<wchar_t> Myhash_set;
int main()
    {
    Myhash_set c1;
    Myhash_set::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_set 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_set::key_compare

Delegasi pemesanan untuk dua kunci.

Sintaks

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

Keterangan

Jenis adalah sinonim untuk delegasi yang menentukan pengurutan argumen kuncinya.

Contoh

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

typedef cliext::hash_set<wchar_t> Myhash_set;
int main()
    {
    Myhash_set c1;
    Myhash_set::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_set 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_set::key_type

Jenis kunci pemesanan.

Sintaks

typedef Key key_type;

Keterangan

Jenisnya adalah sinonim untuk parameter Keytemplat .

Contoh

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

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

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

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

hash_set::load_factor

Menghitung elemen rata-rata per wadah.

Sintaks

float load_factor();

Keterangan

Fungsi anggota mengembalikan (float)size() / bucket_count(). Anda menggunakannya untuk menentukan ukuran wadah rata-rata.

Contoh

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

typedef cliext::hash_set<wchar_t> Myhash_set;
int main()
    {
    Myhash_set 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_set::lower_bound

Menemukan awal rentang yang cocok dengan kunci tertentu.

Sintaks

iterator lower_bound(key_type key);

Parameter

key
Nilai kunci yang akan dicari.

Keterangan

Fungsi anggota menentukan elemen X pertama dalam urutan terkontrol yang hash ke wadah yang sama dengan key dan memiliki urutan yang setara dengan key. Jika tidak ada elemen seperti itu, elemen tersebut mengembalikan end(); jika tidak, elemen tersebut mengembalikan iterator yang menunjuk X. Anda menggunakannya untuk menemukan awal urutan elemen yang saat ini dalam urutan terkontrol yang cocok dengan kunci yang ditentukan.

Contoh

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

typedef cliext::hash_set<wchar_t> Myhash_set;
int main()
    {
    Myhash_set 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_set::make_value

Membuat objek nilai.

Sintaks

static value_type make_value(key_type key);

Parameter

key
Nilai kunci yang akan digunakan.

Keterangan

Fungsi anggota mengembalikan value_type objek yang kuncinya adalah key. Anda menggunakannya untuk menyusun objek yang cocok untuk digunakan dengan beberapa fungsi anggota lainnya.

Contoh

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

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

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

hash_set::max_load_factor

Mendapatkan atau mengatur elemen maksimum per wadah.

Sintaks

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

Parameter

new_factor
Faktor beban maksimum baru untuk disimpan.

Keterangan

Fungsi anggota pertama mengembalikan faktor beban maksimum yang disimpan saat ini. Anda menggunakannya untuk menentukan ukuran wadah rata-rata maksimum.

Fungsi anggota kedua menggantikan faktor beban maksimum penyimpanan dengan new_factor. Tidak ada pembuahan ulang otomatis yang terjadi sampai penyisipan berikutnya.

Contoh

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

typedef cliext::hash_set<wchar_t> Myhash_set;
int main()
    {
    Myhash_set 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);
    }

hash_set::operator=

Menggantikan urutan terkontrol.

Sintaks

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

Parameter

right
Kontainer untuk disalin.

Keterangan

Operator anggota menyalin right ke objek, lalu mengembalikan *this. Anda menggunakannya untuk mengganti urutan terkontrol dengan salinan urutan terkontrol di right.

Contoh

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

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

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

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

hash_set::rbegin

Menunjuk awal urutan terkontrol terbalik.

Sintaks

reverse_iterator rbegin();

Keterangan

Fungsi anggota mengembalikan iterator terbalik yang menunjuk elemen terakhir dari urutan yang dikontrol, atau tepat di luar awal urutan kosong. Oleh karena itu, ini menunjuk beginning urutan terbalik. Anda menggunakannya untuk mendapatkan iterator yang menunjuk current awal urutan terkontrol yang terlihat dalam urutan terbalik, tetapi statusnya dapat berubah jika panjang urutan terkontrol berubah.

Contoh

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

typedef cliext::hash_set<wchar_t> Myhash_set;
int main()
    {
    Myhash_set 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_set::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_set::reference

Jenis referensi ke elemen.

Sintaks

typedef value_type% reference;

Keterangan

Jenis ini menjelaskan referensi ke elemen.

Contoh

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

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

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

hash_set::rehash

Membangun kembali tabel hash.

Sintaks

void rehash();

Keterangan

Fungsi anggota membangun kembali tabel hash, memastikan bahwa load_factor() <= max_load_factor(). Jika tidak, tabel hash meningkat ukurannya hanya sesuai kebutuhan setelah penyisipan. (Ukurannya tidak pernah menurun secara otomatis.) Anda menggunakannya untuk menyesuaikan ukuran tabel hash.

Contoh

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

typedef cliext::hash_set<wchar_t> Myhash_set;
int main()
    {
    Myhash_set 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_set::rend

Menunjuk akhir urutan terkontrol terbalik.

Sintaks

reverse_iterator rend();

Keterangan

Fungsi anggota mengembalikan iterator terbalik yang menunjuk tepat di luar awal urutan yang dikontrol. Oleh karena itu, ini menunjuk end urutan terbalik. Anda menggunakannya untuk mendapatkan iterator yang menunjuk current akhir urutan terkontrol yang terlihat dalam urutan terbalik, tetapi statusnya dapat berubah jika panjang urutan terkontrol berubah.

Contoh

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

typedef cliext::hash_set<wchar_t> Myhash_set;
int main()
    {
    Myhash_set 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_set::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_set::reverse_iterator

Jenis iterator terbalik untuk urutan yang dikontrol.

Sintaks

typedef T3 reverse_iterator;

Keterangan

Jenis menjelaskan objek jenis yang tidak ditentukan T3 yang dapat berfungsi sebagai iterator terbalik untuk urutan yang dikontrol.

Contoh

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

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

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

hash_set::size

Menghitung jumlah elemen.

Sintaks

size_type size();

Keterangan

Fungsi anggota mengembalikan panjang urutan yang dikontrol. Anda menggunakannya untuk menentukan jumlah elemen yang saat ini berada dalam urutan terkontrol. Jika yang Anda pedulikan hanyalah apakah urutannya memiliki ukuran bukan nol, lihat empty().

Contoh

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

typedef cliext::hash_set<wchar_t> Myhash_set;
int main()
    {
    Myhash_set 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_set::size_type

Jenis jarak yang ditandatangani antara dua elemen.

Sintaks

typedef int size_type;

Keterangan

Jenis ini menjelaskan jumlah elemen non-negatif.

Contoh

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

typedef cliext::hash_set<wchar_t> Myhash_set;
int main()
    {
    Myhash_set 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_set::size_type diff = 0;
    for (Myhash_set::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_set::swap

Menukar isi dua kontainer.

Sintaks

void swap(hash_set<Key>% right);

Parameter

right
Kontainer untuk menukar konten dengan.

Keterangan

Fungsi anggota menukar urutan terkontrol antara this dan right. Ini melakukannya dalam waktu konstan dan tidak melemparkan pengecualian. Anda menggunakannya sebagai cara cepat untuk bertukar konten dua kontainer.

Contoh

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

typedef cliext::hash_set<wchar_t> Myhash_set;
int main()
    {
    Myhash_set 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_set 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_set::to_array

Menyalin urutan terkontrol ke array baru.

Sintaks

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

Keterangan

Fungsi anggota mengembalikan array yang berisi urutan terkontrol. Anda menggunakannya untuk mendapatkan salinan urutan terkontrol dalam bentuk array.

Contoh

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

typedef cliext::hash_set<wchar_t> Myhash_set;
int main()
    {
    Myhash_set 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_set::upper_bound

Menemukan akhir rentang yang cocok dengan kunci tertentu.

Sintaks

iterator upper_bound(key_type key);

Parameter

key
Nilai kunci yang akan dicari.

Keterangan

Fungsi anggota menentukan elemen X terakhir dalam urutan terkontrol yang hash ke wadah yang sama dengan key dan memiliki urutan yang setara dengan key. Jika tidak ada elemen seperti itu, atau jika X merupakan elemen terakhir dalam urutan yang dikontrol, elemen tersebut mengembalikan end(); jika tidak, elemen tersebut mengembalikan iterator yang menunjuk elemen pertama di luar X. Anda menggunakannya untuk menemukan akhir urutan elemen yang saat ini dalam urutan terkontrol yang cocok dengan kunci yang ditentukan.

Contoh

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

typedef cliext::hash_set<wchar_t> Myhash_set;
int main()
    {
    Myhash_set 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_set::value_comp

Menyalin delegasi pengurutan untuk dua nilai elemen.

Sintaks

value_compare^ value_comp();

Keterangan

Fungsi anggota mengembalikan delegasi pengurutan yang digunakan untuk mengurutkan urutan yang dikontrol. Anda menggunakannya untuk membandingkan dua nilai elemen.

Contoh

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

typedef cliext::hash_set<wchar_t> Myhash_set;
int main()
    {
    Myhash_set c1;
    Myhash_set::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_set::value_compare

Delegasi pengurutan untuk dua nilai elemen.

Sintaks

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

Keterangan

Jenis adalah sinonim untuk delegasi yang menentukan urutan argumen nilainya.

Contoh

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

typedef cliext::hash_set<wchar_t> Myhash_set;
int main()
    {
    Myhash_set c1;
    Myhash_set::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_set::value_type

Jenis elemen.

Sintaks

typedef generic_value value_type;

Keterangan

Jenisnya adalah sinonim untuk generic_value.

Contoh

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

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

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

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