Not
Bu sayfaya erişim yetkilendirme gerektiriyor. Oturum açmayı veya dizinleri değiştirmeyi deneyebilirsiniz.
Bu sayfaya erişim yetkilendirme gerektiriyor. Dizinleri değiştirmeyi deneyebilirsiniz.
Not
Bu, API artık kullanılmıyor. Bunun alternatifi Sınıf'tırunordered_map.
Her öğenin, değeri benzersiz ve ilişkili bir veri değeri olan bir sıralama anahtarına sahip bir çift olduğu bir koleksiyondan hızla veri depolar ve alır.
Sözdizimi
template <class Key,
class Type,
class Traits=hash_compare<Key, less<Key>>,
class Allocator=allocator<pair <const Key, Type>>>
class hash_map
Parametreler
Key
içinde hash_mapdepolanacak anahtar veri türü.
Type
içinde hash_mapdepolanacak öğe veri türü.
Traits
İki işlev nesnesi içeren tür, sınıftan biri, göreli düzenlerini belirlemek için iki öğe değerini sıralama anahtarları olarak karşılaştırabilir ve öğelerin birli koşul eşleme anahtar değerlerini türündeki size_tişaretsiz tamsayılarla eşleyen bir karma işlevidir. Bu bağımsız değişken isteğe bağlıdır ve hash_compare<Key, less<Key>> varsayılan değerdir.
Allocator
's ayırma ve belleği serbest bırakma hakkındaki hash_mapayrıntıları kapsülleyen depolanan ayırıcı nesnesini temsil eden tür. Bu bağımsız değişken isteğe bağlıdır ve varsayılan değerdir allocator<pair <const Key, Type>>.
Açıklamalar
Şu hash_map şekildedir:
İlişkili bir anahtar değerine dayalı öğe değerlerinin verimli alınmasını destekleyen bir değişken boyutu kapsayıcı olan ilişkilendirilebilir bir kapsayıcı.
Çift yönlüdür, çünkü öğelerine erişmek için çift yönlü bir yineleyici sağlar.
Karma, çünkü öğeleri öğelerinin anahtar değerlerine uygulanan bir karma işlevinin değerine göre demetler halinde gruplandırılır.
Benzersizdir, çünkü öğelerinin her birinde benzersiz bir anahtar olması gerekir.
Bir çift ilişkilendirilebilir kapsayıcıdır, çünkü veri öğelerinin değerleri kendi anahtar değerlerinden farklıdır.
Sınıf şablonu, sağladığı işlevsellik genel olduğundan ve öğeler veya anahtarlar olarak yer alan belirli veri türlerinden çok bağımsızdır. Öğeler ve anahtarlar için kullanılacak veri türleri, karşılaştırma işlevi ve ayırıcı ile birlikte bir sınıf şablonunda parametreler olarak belirtilir.
Sıralamaya göre karma oluşturmanın temel avantajı daha yüksek verimliliktir; başarılı bir karma ekleme, silme işlemleri gerçekleştirir ve sıralama teknikleri için kapsayıcıdaki öğe sayısının logaritmasıyla orantılı bir süreyle karşılaştırıldığında sabit ortalama süre bulur. içindeki bir öğenin hash_mapdeğeri, ancak ilişkili anahtar değeri doğrudan değiştirilebilir. Bunun yerine, eski öğelerle ilişkili anahtar değerleri silinmeli ve eklenen yeni öğelerle ilişkili yeni anahtar değerleri eklenmelidir.
Kapsayıcı türünün seçimi genelde uygulamanın gerektirdiği arama ve ekleme türüne dayalı olmalıdır. Karma ilişkilendirme kapsayıcıları arama, ekleme ve kaldırma işlemleri için iyileştirilmiştir. Bu işlemleri açıkça destekleyen üye işlevleri, iyi tasarlanmış bir karma işleviyle kullanıldığında verimlidir ve bunları ortalama sabit olan ve kapsayıcıdaki öğe sayısına bağımlı olmayan bir zamanda gerçekleştirir. İyi tasarlanmış bir karma işlevi, karma değerlerin tekdüzen bir dağılımını oluşturur ve çakışma sayısını en aza indirir. Burada, farklı anahtar değerleri aynı karma değere eşlendiğinde çakışma olduğu söylenir. En kötü durumda, mümkün olan en kötü karma işleviyle, işlem sayısı dizideki öğe sayısıyla orantılıdır (doğrusal süre).
hash_map, değerleri anahtarlarıyla ilişkilendiren koşullar uygulama tarafından karşılandığında tercih edilen ilişkilendirilebilir kapsayıcı olmalıdır. Bu tür bir yapı için model, tanımları sağlayan ilişkili dize değerlerine sahip benzersiz olarak oluşan anahtar sözcüklerin sıralı bir listesidir. Bunun yerine, sözcüklerin birden fazla doğru tanımı varsa ve böylece anahtarlar benzersiz değilse, tercih edilecek kapsayıcı bir hash_multimap olacaktır. Öte yandan, yalnızca sözcüklerin listesi depolanıyorsa, hash_set doğru kapsayıcı a olacaktır. Sözcüklerin birden çok örneğine izin verilseydi, hash_multiset uygun kapsayıcı yapısı olacaktır.
, hash_map sınıfının Traitsdepolanmış karma value_compare nesnesini çağırarak denetlediği sırayı sıralar. Bu depolanan nesneye üye işlevi key_compçağrılarak erişilebilir. Böyle bir işlev nesnesi sınıfının hash_compare<Key, less<Key>>nesnesiyle aynı şekilde davranmalıdır. Özellikle, türündeki Keytüm değerler Key için çağrısı Traits(Key) türündeki size_tdeğerlerin dağılımını verir. Daha fazla bilgi için bkz. hash_compare.
Genel olarak, öğelerin bu düzeni oluşturmak için yalnızca karşılaştırılabilirden daha az olması gerekir: böylece, herhangi iki öğe göz önüne alındığında, eşdeğer oldukları (diğerinden küçük olmadığı anlamına gelir) veya birinin diğerinden küçük olduğu belirlenebilir. Bu, denk olmayan öğeler arasında bir sıralamaya neden olur. Daha teknik bir not üzerinde, karşılaştırma işlevi standart matematiksel anlamda katı bir zayıf sıralama sevk eden ikili bir koşuldur. f(x y) ikili koşulu, iki bağımsız değişken nesnesine ve x veya ydönüş değerine true sahip bir işlev nesnesidirfalse.
hash_map İkili koşul esnek değilse, antisymetrik ve geçişliyse ve denklik geçişliyse, iki nesnenin x denk olduğu ve y hem f(x, y) hem de f(y, x) olduğunda eşdeğer olarak tanımlandığı bir sıralama, katı bir zayıf sıralamadırfalse. Anahtarlar arasındaki eşitliğinin daha güçlü koşulu bu denkliğin yerini alırsa, sıralama (içindeki tüm öğelerin birbirine göre sıralanması anlamında) toplam haline gelir ve eşleşen anahtarlar birbirinden ayırt edilemez olacaktır.
Denetlenen dizideki öğelerin gerçek sırası karma işlevine, sıralama işlevine ve kapsayıcı nesnesinde depolanan karma tablosunun geçerli boyutuna bağlıdır. Karma tablosunun geçerli boyutunu belirleyemezsiniz, bu nedenle denetimli dizideki öğelerin sırasını genel olarak tahmin edebilirsiniz. Öğelerin eklenmesi hiçbir yineleyiciyi geçersiz kılmaz; öğelerin kaldırılması yalnızca özellikle kaldırılan öğeleri gösteren yineleyicileri geçersiz kılar.
sınıfı tarafından hash_map sağlanan yineleyici çift yönlü bir yineleyicidir, ancak sınıf üyesi işlev görür insert ve hash_map şablon parametresi olarak işlev gereksinimleri çift yönlü yineleyiciler sınıfı tarafından garanti edilenden daha düşük olan daha zayıf bir giriş yineleyicisi olarak kabul edilen sürümlere sahiptir. Farklı yineleyici kavramları, işlevselliklerindeki iyileştirmelere göre ilgili bir aile biçimlendirir. Her yineleyici kavramının kendi gereksinimler kümesi vardır ve bunlarla çalışan algoritmaların kendi varsayımlarını yineleyici türü tarafından sağlanan gereksinimlerle sınırlaması gerekir. Bir giriş yineleyicinin bazı nesnelere başvurusunun kaldırılacağı ve dizideki sonraki yineleyiciye artırılabileceği varsayılabilir. Bu çok az işlev kümesidir, ancak sınıf üyesi işlevleri bağlamında bir dizi yineleyici [First, Last) hakkında anlamlı bir şekilde konuşabilmek yeterlidir.
Oluşturucular
| Oluşturucu | Açıklama |
|---|---|
hash_map |
Boş olan veya başka hash_mapbir öğesinin tümünün veya bir bölümünün kopyası olan bir hash_map oluşturur. |
Tür tanımları
| Tür adı | Açıklama |
|---|---|
allocator_type |
Nesnenin sınıfını allocatorhash_map temsil eden bir tür. |
const_iterator |
içindeki bir öğeyi constokuyabilen çift yönlü bir yineleyici sağlayan türhash_map. |
const_pointer |
içindeki bir const öğeye işaretçi sağlayan tür hash_map. |
const_reference |
okuma ve gerçekleştirme const işlemleri için içinde hash_map depolanan bir const öğeye başvuru sağlayan bir tür. |
const_reverse_iterator |
içindeki constherhangi hash_map bir öğeyi okuyabilen çift yönlü bir yineleyici sağlayan tür. |
difference_type |
Yineleyiciler tarafından işaret edilen öğeler arasındaki bir aralıktaki öğelerinin hash_map sayısını göstermek için kullanılabilecek imzalı bir tamsayı türü. |
iterator |
bir içindeki herhangi bir öğeyi okuyabilen veya değiştirebilen çift yönlü bir yineleyici sağlayan tür hash_map. |
key_compare |
içindeki iki öğeye hash_mapgöre sırasını belirlemek için iki sıralama anahtarını karşılaştırabilen bir işlev nesnesi sağlayan tür. |
key_type |
Türü, öğesinin her öğesini hash_mapoluşturan sıralama anahtarı nesnesini açıklar. |
mapped_type |
içinde depolanan veri türünü temsil eden bir hash_maptür. |
pointer |
içindeki bir öğeye işaretçi sağlayan tür hash_map. |
reference |
içinde depolanan bir öğeye başvuru sağlayan tür hash_map. |
reverse_iterator |
Ters çevrilmiş hash_mapiçindeki bir öğeyi okuyabilen veya değiştirebilen çift yönlü bir yineleyici sağlayan tür. |
size_type |
içindeki öğe sayısını temsil eden işaretsiz bir hash_maptamsayı türü. |
value_type |
içinde göreli düzenlerini hash_mapbelirlemek için iki öğeyi sıralama anahtarları olarak karşılaştırabilen bir işlev nesnesi sağlayan tür. |
Üye işlevleri
| Üye işlevi | Açıklama |
|---|---|
at |
içinde belirtilen anahtar değerine sahip bir öğe hash_map bulur. |
begin |
içindeki ilk öğeyi hash_mapele alan bir yineleyici döndürür. |
cbegin |
içindeki ilk öğeyi hash_mapele alan bir sabit yineleyici döndürür. |
cend |
bir içindeki son öğenin başarılı olduğu konumu ele alan bir hash_mapsabit yineleyici döndürür. |
clear |
öğesinin hash_maptüm öğelerini siler. |
count |
Anahtarı parametre tarafından belirtilen anahtarla eşleşen bir hash_map içindeki öğelerin sayısını döndürür. |
crbegin |
ters çevrilmiş constbir hash_map içindeki ilk öğeyi ele alan bir yineleyici döndürür. |
crend |
Ters çevrilmiş constbir hash_map içindeki son öğeden sonra gelen konumu ele alan bir yineleyici döndürür. |
emplace |
içine yerinde inşa edilmiş bir hash_mapöğe ekler. |
emplace_hint |
Bir yerleştirme ipucuyla içine yerinde hash_mapinşa edilmiş bir öğe ekler. |
empty |
boş hash_map olup olmadığını sınar. |
end |
içindeki son öğenin başarılı olduğu konumu ele alan bir hash_mapyineleyici döndürür. |
equal_range |
Belirtilen anahtardan büyük bir anahtara sahip bir anahtarı olan ilk öğeye hash_map ve anahtara eşit veya daha büyük bir anahtarla içindeki ilk öğeye hash_map sırasıyla bir çift yineleyici döndürür. |
erase |
Belirtilen konumlardan bir öğeyi veya öğe hash_map aralığını kaldırır |
find |
Belirtilen anahtara eşdeğer bir anahtara sahip bir hash_map öğenin konumunu adresleyen bir yineleyici döndürür. |
get_allocator |
oluşturmak için kullanılan nesnesinin allocatorbir kopyasını hash_map döndürür. |
insert |
içine bir öğe veya öğe hash_maparalığı ekler. |
key_comp |
Bir yineleyiciyi, belirtilen bir anahtara eşit veya ondan daha büyük bir anahtar değerine sahip bir içindeki ilk öğeye hash_map döndürür. |
lower_bound |
Bir yineleyiciyi, belirtilen bir anahtara eşit veya ondan daha büyük bir anahtar değerine sahip bir içindeki ilk öğeye hash_map döndürür. |
max_size |
değerinin uzunluk üst sınırını hash_mapdöndürür. |
rbegin |
ters çevrilmiş hash_mapiçindeki ilk öğeyi ele alan bir yineleyici döndürür. |
rend |
Ters çevrilmiş hash_mapbir içindeki son öğeyi başaran konumu ele alan bir yineleyici döndürür. |
size |
içindeki hash_mapöğe sayısını döndürür. |
swap |
İki hash_mapöğesinin öğelerini değiştirir. |
upper_bound |
Belirtilen anahtarın değerinden daha büyük bir hash_map anahtar değeri olan bir içindeki ilk öğeye bir yineleyici döndürür. |
value_comp |
içindeki öğe değerlerini sıralamak için kullanılan karşılaştırma nesnesinin bir hash_mapkopyasını alır. |
İşleçler
| Operatör | Açıklama |
|---|---|
operator[] |
Belirtilen anahtar değerine sahip öğesine hash_map öğe ekler. |
hash_map::operator= |
öğesinin hash_map öğelerini başka hash_mapbir kopyasının kopyasıyla değiştirir. |
Gereksinimler
Üstbilgi:<hash_map>
Ad alanı: stdext
hash_map::allocator_type
Not
Bu, API artık kullanılmıyor. Bunun alternatifi Sınıf'tırunordered_map.
hash_map nesnesi için ayırıcı sınıfını temsil eden bir tür.
typedef list<typename Traits::value_type, typename Traits::allocator_type>::allocator_type allocator_type;
Örnek
kullanan get_allocatorbir örnek için allocator_type örneğine bakın.
hash_map::at
Not
Bu, API artık kullanılmıyor. Bunun alternatifi Sınıf'tırunordered_map.
içinde belirtilen anahtar değerine sahip bir öğe hash_map bulur.
Type& at(const Key& key);
const Type& at(const Key& key) const;
Parametreler
key
Bulunabilecek öğenin anahtar değeri.
Dönüş Değeri
Bulunan öğenin veri değerine başvuru.
Açıklamalar
Bağımsız değişken anahtarı değeri bulunamazsa, işlev sınıfı out_of_range sınıfına ait bir nesnesi oluşturur.
Örnek
// hash_map_at.cpp
// compile with: /EHsc
#include <hash_map>
#include <iostream>
int main( )
{
using namespace std;
using namespace stdext;
typedef pair <const int, int> cInt2Int;
hash_map <int, int> hm1;
// Insert data values
hm1.insert ( cInt2Int ( 1, 10 ) );
hm1.insert ( cInt2Int ( 2, 20 ) );
hm1.insert ( cInt2Int ( 3, 30 ) );
cout << "The values of the mapped elements are:";
for ( int i = 1 ; i <= hm1.size() ; i++ )
cout << " " << hm1.at(i);
cout << "." << endl;
}
hash_map::begin
Not
Bu, API artık kullanılmıyor. Bunun alternatifi Sınıf'tırunordered_map.
içindeki ilk öğeyi hash_mapele alan bir yineleyici döndürür.
const_iterator begin() const;
iterator begin();
Dönüş Değeri
veya konumundaki ilk öğeyi hash_map ele alan ve boş hash_mapbir öğesinin başarılı olduğu çift yönlü yineleyici.
Örnek
// hash_map_begin.cpp
// compile with: /EHsc
#include <hash_map>
#include <iostream>
int main( )
{
using namespace std;
using namespace stdext;
hash_map <int, int> hm1;
hash_map <int, int> :: iterator hm1_Iter;
hash_map <int, int> :: const_iterator hm1_cIter;
typedef pair <int, int> Int_Pair;
hm1.insert ( Int_Pair ( 0, 0 ) );
hm1.insert ( Int_Pair ( 1, 1 ) );
hm1.insert ( Int_Pair ( 2, 4 ) );
hm1_cIter = hm1.begin ( );
cout << "The first element of hm1 is "
<< hm1_cIter -> first << "." << endl;
hm1_Iter = hm1.begin ( );
hm1.erase ( hm1_Iter );
// The following 2 lines would err because the iterator is const
// hm1_cIter = hm1.begin ( );
// hm1.erase ( hm1_cIter );
hm1_cIter = hm1.begin( );
cout << "The first element of hm1 is now "
<< hm1_cIter -> first << "." << endl;
}
The first element of hm1 is 0.
The first element of hm1 is now 1.
hash_map::cbegin
Not
Bu, API artık kullanılmıyor. Bunun alternatifi Sınıf'tırunordered_map.
içindeki ilk öğeyi hash_mapele alan bir sabit yineleyici döndürür.
const_iterator cbegin() const;
Dönüş Değeri
veya konumundaki ilk öğeyi hash_map ele alan ve boş hash_mapbir öğesinin başarılı olduğu sabit çift yönlü yineleyici.
Örnek
// hash_map_cbegin.cpp
// compile with: /EHsc
#include <hash_map>
#include <iostream>
int main( )
{
using namespace std;
using namespace stdext;
hash_map <int, int> hm1;
hash_map <int, int> :: const_iterator hm1_cIter;
typedef pair <int, int> Int_Pair;
hm1.insert ( Int_Pair ( 2, 4 ) );
hm1_cIter = hm1.cbegin ( );
cout << "The first element of hm1 is "
<< hm1_cIter -> first << "." << endl;
}
The first element of hm1 is 2.
hash_map::cend
Not
Bu, API artık kullanılmıyor. Bunun alternatifi Sınıf'tırunordered_map.
bir içindeki son öğenin başarılı olduğu konumu ele alan bir hash_mapsabit yineleyici döndürür.
const_iterator cend() const;
Dönüş Değeri
bir içindeki son öğeyi hash_mapbaşaran konumu ele alan en kısa çift yönlü yineleyici.
hash_map boşsa, öğesini seçinhash_map::cend == hash_map::begin.
Açıklamalar
cend , yineleyicinin sonuna hash_mapulaşıp ulaşmadığını test etmek için kullanılır.
tarafından cend döndürülen değer başvurulmamalıdır.
Örnek
// hash_map_cend.cpp
// compile with: /EHsc
#include <hash_map>
#include <iostream>
int main( )
{
using namespace std;
using namespace stdext;
hash_map <int, int> hm1;
hash_map <int, int> :: const_iterator hm1_cIter;
typedef pair <int, int> Int_Pair;
hm1.insert ( Int_Pair ( 3, 30 ) );
hm1_cIter = hm1.cend( );
hm1_cIter--;
cout << "The value of last element of hm1 is "
<< hm1_cIter -> second << "." << endl;
}
The value of last element of hm1 is 30.
hash_map::clear
Not
Bu, API artık kullanılmıyor. Bunun alternatifi Sınıf'tırunordered_map.
öğesinin hash_maptüm öğelerini siler.
void clear();
Örnek
Aşağıdaki örnekte üye işlevinin kullanımı gösterilmektedir hash_map::clear .
// hash_map_clear.cpp
// compile with: /EHsc
#include <hash_map>
#include <iostream>
int main( )
{
using namespace std;
using namespace stdext;
hash_map<int, int> hm1;
hash_map<int, int>::size_type i;
typedef pair<int, int> Int_Pair;
hm1.insert(Int_Pair(1, 1));
hm1.insert(Int_Pair(2, 4));
i = hm1.size();
cout << "The size of the hash_map is initially "
<< i << "." << endl;
hm1.clear();
i = hm1.size();
cout << "The size of the hash_map after clearing is "
<< i << "." << endl;
}
The size of the hash_map is initially 2.
The size of the hash_map after clearing is 0.
hash_map::const_iterator
Not
Bu, API artık kullanılmıyor. Bunun alternatifi Sınıf'tırunordered_map.
içindeki bir öğeyi constokuyabilen çift yönlü bir yineleyici sağlayan türhash_map.
typedef list<typename Traits::value_type, typename Traits::allocator_type>::const_iterator const_iterator;
Açıklamalar
Bir öğenin değerini değiştirmek için bir tür const_iterator kullanılamaz.
const_iterator tarafından hash_map tanımlanan, ilk üyesi öğenin anahtarı olan ve ikinci üyesi öğesi tarafından tutulan eşlenmiş datum olan türündeki value_typenesneleri pair< const Key, Type >olan öğelere işaret eder.
içindeki bir const_iteratorcIter öğeye işaret eden bir başvuruyu hash_mapgeri almak için işlecini -> kullanın.
öğesinin anahtarının değerine erişmek için, cIter->firstile eşdeğer (*cIter).firstolan kullanın. öğesinin eşlenmiş veri kümesinin değerine erişmek için öğesine cIter->secondeşdeğer (*cIter).secondolan kullanın.
Örnek
kullanan beginbir örnek için const_iterator örneğine bakın.
hash_map::const_pointer
Not
Bu, API artık kullanılmıyor. Bunun alternatifi Sınıf'tırunordered_map.
içindeki bir const öğeye işaretçi sağlayan tür hash_map.
typedef list<typename _Traits::value_type, typename _Traits::allocator_type>::const_pointer const_pointer;
Açıklamalar
Bir öğenin değerini değiştirmek için bir tür const_pointer kullanılamaz.
Çoğu durumda, nesnedeki iteratorhash_map öğelere erişmek için bir kullanılmalıdır.
hash_map::const_reference
Not
Bu, API artık kullanılmıyor. Bunun alternatifi Sınıf'tırunordered_map.
okuma ve gerçekleştirme const işlemleri için içinde hash_map depolanan bir const öğeye başvuru sağlayan bir tür.
typedef list<typename _Traits::value_type, typename _Traits::allocator_type>::const_reference const_reference;
Örnek
// hash_map_const_ref.cpp
// compile with: /EHsc
#include <hash_map>
#include <iostream>
int main( )
{
using namespace std;
using namespace stdext;
hash_map<int, int> hm1;
typedef pair <int, int> Int_Pair;
hm1.insert ( Int_Pair ( 1, 10 ) );
hm1.insert ( Int_Pair ( 2, 20 ) );
// Declare and initialize a const_reference &Ref1
// to the key of the first element
const int &Ref1 = ( hm1.begin( ) -> first );
// The following line would cause an error because the
// non-const_reference cannot be used to access the key
// int &Ref1 = ( hm1.begin( ) -> first );
cout << "The key of the first element in the hash_map is "
<< Ref1 << "." << endl;
// Declare and initialize a reference &Ref2
// to the data value of the first element
int &Ref2 = ( hm1.begin( ) -> second );
cout << "The data value of the first element in the hash_map is "
<< Ref2 << "." << endl;
}
The key of the first element in the hash_map is 1.
The data value of the first element in the hash_map is 10.
hash_map::const_reverse_iterator
Not
Bu, API artık kullanılmıyor. Bunun alternatifi Sınıf'tırunordered_map.
içindeki constherhangi hash_map bir öğeyi okuyabilen çift yönlü bir yineleyici sağlayan tür.
typedef list<typename Traits::value_type, typename Traits::allocator_type>::const_reverse_iterator const_reverse_iterator;
Açıklamalar
Bir tür const_reverse_iterator bir öğenin değerini değiştiremez ve öğesini tersten yinelemek hash_map için kullanılır.
const_reverse_iterator tarafından hash_map tanımlanan, ilk üyesi öğenin anahtarı olan ve ikinci üyesi öğesi tarafından tutulan eşlenmiş datum olan türündeki value_typenesneleri pair< const Key, Type >olan öğelere işaret eder.
içindeki bir const_reverse_iteratorcrIter öğeye işaret eden bir başvuruyu hash_mapgeri almak için işlecini -> kullanın.
öğesinin anahtarının değerine erişmek için, crIter->firstile eşdeğer (*crIter).firstolan kullanın. öğesinin eşlenmiş veri kümesinin değerine erişmek için öğesine crIter->secondeşdeğer (*crIter).firstolan kullanın.
Örnek
nasıl bildirilip kullanılacağına ilişkin bir örnek için rend örneğine const_reverse_iteratorbakın.
hash_map::count
Not
Bu, API artık kullanılmıyor. Bunun alternatifi Sınıf'tırunordered_map.
Anahtarı parametre tarafından belirtilen anahtarla eşleşen bir hash_map içindeki öğelerin sayısını döndürür.
size_type count(const Key& key) const;
Parametreler
key
ile eşleştirilecek hash_mapöğelerin anahtar değeri.
Dönüş Değeri
sıralama anahtarı parametre anahtarıyla eşleşen bir öğe içeriyorsa 1 hash_map ; eşleşen anahtara sahip bir öğe içermiyorsa hash_map 0.
Açıklamalar
Üye işlevi aralıktaki öğe x sayısını döndürür
lower_bound(key), upper_bound(key)
bu, benzersiz bir ilişkilendirici kapsayıcı olan durumunda hash_map0 veya 1'dir.
Örnek
Aşağıdaki örnekte üye işlevinin kullanımı gösterilmektedir hash_map::count .
// hash_map_count.cpp
// compile with: /EHsc
#include <hash_map>
#include <iostream>
int main()
{
using namespace std;
using namespace stdext;
hash_map<int, int> hm1;
hash_map<int, int>::size_type i;
typedef pair<int, int> Int_Pair;
hm1.insert(Int_Pair (1, 1));
hm1.insert(Int_Pair (2, 1));
hm1.insert(Int_Pair (1, 4));
hm1.insert(Int_Pair (2, 1));
// Keys must be unique in hash_map, so duplicates are ignored
i = hm1.count(1);
cout << "The number of elements in hm1 with a sort key of 1 is: "
<< i << "." << endl;
i = hm1.count(2);
cout << "The number of elements in hm1 with a sort key of 2 is: "
<< i << "." << endl;
i = hm1.count(3);
cout << "The number of elements in hm1 with a sort key of 3 is: "
<< i << "." << endl;
}
The number of elements in hm1 with a sort key of 1 is: 1.
The number of elements in hm1 with a sort key of 2 is: 1.
The number of elements in hm1 with a sort key of 3 is: 0.
hash_map::crbegin
Not
Bu, API artık kullanılmıyor. Bunun alternatifi Sınıf'tırunordered_map.
ters çevrilmiş constbir hash_map içindeki ilk öğeyi ele alan bir yineleyici döndürür.
const_reverse_iterator crbegin() const;
Dönüş Değeri
Ters const çevrilmiş hash_map bir içindeki ilk öğeyi veya ters çevrilmemiş hash_mapiçindeki son öğeyi ele alan ters çift yönlü yineleyici.
Açıklamalar
crbegin, ile kullanıldığı gibi hash_map ters çevrilmiş begin bir hash_mapile kullanılır.
dönüş değeriyle crbeginhash_map nesne değiştirilemez.
crbegin geriye doğru yinelemek hash_map için kullanılabilir.
Örnek
// hash_map_crbegin.cpp
// compile with: /EHsc
#include <hash_map>
#include <iostream>
int main( )
{
using namespace std;
using namespace stdext;
hash_map <int, int> hm1;
hash_map <int, int> :: const_reverse_iterator hm1_crIter;
typedef pair <int, int> Int_Pair;
hm1.insert ( Int_Pair ( 3, 30 ) );
hm1_crIter = hm1.crbegin( );
cout << "The first element of the reversed hash_map hm1 is "
<< hm1_crIter -> first << "." << endl;
}
The first element of the reversed hash_map hm1 is 3.
hash_map::crend
Not
Bu, API artık kullanılmıyor. Bunun alternatifi Sınıf'tırunordered_map.
Ters çevrilmiş constbir hash_map içindeki son öğeden sonra gelen konumu ele alan bir yineleyici döndürür.
const_reverse_iterator crend() const;
Dönüş Değeri
Ters const çevrilmiş bir öğedeki son öğeyi (ters hash_map çevrilmemiş hash_mapöğedeki ilk öğeden önce gelen konum) başarılı olan konumu ele alan ters çift yönlü yineleyici.
Açıklamalar
crend, ile kullanıldığı gibi hash_map ters çevrilmiş hash_map::end bir hash_mapile kullanılır.
dönüş değeriyle crendhash_map nesne değiştirilemez.
crend , ters yineleyicinin sonuna hash_mapulaşıp ulaşmadığını test etmek için kullanılabilir.
tarafından crend döndürülen değer başvurulmamalıdır.
Örnek
// hash_map_crend.cpp
// compile with: /EHsc
#include <hash_map>
#include <iostream>
int main( )
{
using namespace std;
using namespace stdext;
hash_map <int, int> hm1;
hash_map <int, int> :: const_reverse_iterator hm1_crIter;
typedef pair <int, int> Int_Pair;
hm1.insert ( Int_Pair ( 3, 30 ) );
hm1_crIter = hm1.crend( );
hm1_crIter--;
cout << "The last element of the reversed hash_map hm1 is "
<< hm1_crIter -> first << "." << endl;
}
The last element of the reversed hash_map hm1 is 3.
hash_map::difference_type
Not
Bu, API artık kullanılmıyor. Bunun alternatifi Sınıf'tırunordered_map.
Yineleyiciler tarafından işaret edilen öğeler arasındaki bir aralıktaki öğelerinin hash_map sayısını göstermek için kullanılabilecek imzalı bir tamsayı türü.
typedef list<typename _Traits::value_type, typename _Traits::allocator_type>::difference_type difference_type;
Örnek
// hash_map_diff_type.cpp
// compile with: /EHsc
#include <iostream>
#include <hash_map>
#include <algorithm>
int main( )
{
using namespace std;
using namespace stdext;
hash_map <int, int> hm1;
typedef pair <int, int> Int_Pair;
hm1.insert ( Int_Pair ( 2, 20 ) );
hm1.insert ( Int_Pair ( 1, 10 ) );
hm1.insert ( Int_Pair ( 3, 20 ) );
// The following won't insert, because map keys are unique
hm1.insert ( Int_Pair ( 2, 30 ) );
hash_map <int, int>::iterator hm1_Iter, hm1_bIter, hm1_eIter;
hm1_bIter = hm1.begin( );
hm1_eIter = hm1.end( );
// Count the number of elements in a hash_map
hash_map <int, int>::difference_type df_count = 0;
hm1_Iter = hm1.begin( );
while ( hm1_Iter != hm1_eIter)
{
df_count++;
hm1_Iter++;
}
cout << "The number of elements in the hash_map hm1 is: "
<< df_count << "." << endl;
cout << "The keys of the mapped elements are:";
for ( hm1_Iter= hm1.begin( ) ; hm1_Iter!= hm1.end( ) ;
hm1_Iter++)
cout << " " << hm1_Iter-> first;
cout << "." << endl;
cout << "The values of the mapped elements are:";
for ( hm1_Iter= hm1.begin( ) ; hm1_Iter!= hm1.end( ) ;
hm1_Iter++)
cout << " " << hm1_Iter-> second;
cout << "." << endl;
}
The number of elements in the hash_map hm1 is: 3.
The keys of the mapped elements are: 1 2 3.
The values of the mapped elements are: 10 20 20.
hash_map::emplace
Not
Bu, API artık kullanılmıyor. Bunun alternatifi Sınıf'tırunordered_map.
içine yerinde inşa edilmiş bir hash_mapöğe ekler.
template <class ValTy>
pair <iterator, bool>
emplace(
ValTy&& val);
Parametreler
val
Zaten bu öğeyi (veya daha genel olarak, anahtarı eşdeğer sıralanmış hash_map bir öğe) içermediği sürece hash_map içine eklenecek bir öğeyi taşımak için kullanılan değer.
Dönüş Değeri
emplace Üye işlevi, ekleme bool yapılıp yapılmadığı ve anahtarı sıralamada true eşdeğer bir değere sahip olan ve false bileşeni yeni öğenin eklendiği adresi veya öğenin zaten bulunduğu adresi döndüren hash_map bir öğe içeriyorsa bileşeni döndüren bir çift iterator döndürür.
Bu üye işlevi iteratortarafından döndürülen bir çiftin pr bileşenine erişmek pr.first için kullanın ve başvuruyu geri almak için kullanın*(pr.first). Bu üye işlevi booltarafından döndürülen bir çiftin pr bileşenine erişmek pr.second için kullanın ve başvuruyu geri almak için kullanın*(pr.second).
Açıklamalar
hash_map::value_type Bir öğenin değeri bir çifttir, böylece bir öğenin değeri ilk bileşen anahtar değerine eşit, ikinci bileşen de öğenin veri değerine eşit olan sıralı bir çift olur.
Örnek
// hash_map_emplace.cpp
// compile with: /EHsc
#include <hash_map>
#include <iostream>
#include <string>
int main()
{
using namespace std;
using namespace stdext;
hash_map<int, string> hm1;
typedef pair<int, string> is1(1, "a");
hm1.emplace(move(is1));
cout << "After the emplace insertion, hm1 contains:" << endl
<< " " << hm1.begin()->first
<< " => " << hm1.begin()->second
<< endl;
}
After the emplace insertion, hm1 contains:
1 => a
hash_map::emplace_hint
Not
Bu, API artık kullanılmıyor. Bunun alternatifi Sınıf'tırunordered_map.
Bir yerleştirme ipucuyla içine yerinde hash_mapinşa edilmiş bir öğe ekler.
template <class ValTy>
iterator emplace_hint(
const_iterator _Where,
ValTy&& val);
Parametreler
val
Zaten bu öğeyi (veya daha genel olarak, anahtarı eşdeğer sıralanmış hash_map bir öğe) içermediği sürece hash_map içine eklenecek bir öğeyi taşımak için kullanılan değer.
c
Doğru ekleme noktasını aramaya başlama yeriyle ilgili bir ipucu.
Dönüş Değeri
Üye işlevi, hash_multimap::emplace yeni öğenin içine hash_mapeklendiği veya eşdeğer sıralamaya sahip mevcut öğenin bulunduğu konumu gösteren bir yineleyici döndürür.
Açıklamalar
hash_map::value_type Bir öğenin değeri bir çifttir, böylece bir öğenin değeri ilk bileşen anahtar değerine eşit, ikinci bileşen de öğenin veri değerine eşit olan sıralı bir çift olur.
Ekleme noktası hemen izlerse _Where, ekleme işlemi logaritmik saat yerine amorti edilmiş sabit sürede gerçekleşebilir.
Örnek
// hash_map_emplace_hint.cpp
// compile with: /EHsc
#include <hash_map>
#include <iostream>
#include <string>
int main()
{
using namespace std;
using namespace stdext;
hash_map<int, string> hm1;
typedef pair<int, string> is1(1, "a");
hm1.emplace(hm1.begin(), move(is1));
cout << "After the emplace, hm1 contains:" << endl
<< " " << hm1.begin()->first
<< " => " << hm1.begin()->second
<< endl;
}
After the emplace insertion, hm1 contains:
1 => a
hash_map::empty
Not
Bu, API artık kullanılmıyor. Bunun alternatifi Sınıf'tırunordered_map.
boş hash_map olup olmadığını sınar.
bool empty() const;
Dönüş Değeri
true
hash_map boşsa; falsehash_map yoksa.
Örnek
// hash_map_empty.cpp
// compile with: /EHsc
#include <hash_map>
#include <iostream>
int main( )
{
using namespace std;
using namespace stdext;
hash_map <int, int> hm1, hm2;
typedef pair <int, int> Int_Pair;
hm1.insert ( Int_Pair ( 1, 1 ) );
if ( hm1.empty( ) )
cout << "The hash_map hm1 is empty." << endl;
else
cout << "The hash_map hm1 is not empty." << endl;
if ( hm2.empty( ) )
cout << "The hash_map hm2 is empty." << endl;
else
cout << "The hash_map hm2 is not empty." << endl;
}
The hash_map hm1 is not empty.
The hash_map hm2 is empty.
hash_map::end
Not
Bu, API artık kullanılmıyor. Bunun alternatifi Sınıf'tırunordered_map.
içindeki son öğenin başarılı olduğu konumu ele alan bir hash_mapyineleyici döndürür.
const_iterator end() const;
iterator end();
Dönüş Değeri
bir içindeki son öğenin başarılı olduğu konumu ele alan çift yönlü yineleyici hash_map.
hash_map boşsa, öğesini seçinhash_map::end == hash_map::begin.
Açıklamalar
end , yineleyicinin sonuna hash_mapulaşıp ulaşmadığını test etmek için kullanılır.
tarafından end döndürülen değer başvurulmamalıdır.
Örnek
// hash_map_end.cpp
// compile with: /EHsc
#include <hash_map>
#include <iostream>
int main( )
{
using namespace std;
using namespace stdext;
hash_map <int, int> hm1;
hash_map <int, int> :: iterator hm1_Iter;
hash_map <int, int> :: const_iterator hm1_cIter;
typedef pair <int, int> Int_Pair;
hm1.insert ( Int_Pair ( 1, 10 ) );
hm1.insert ( Int_Pair ( 2, 20 ) );
hm1.insert ( Int_Pair ( 3, 30 ) );
hm1_cIter = hm1.end( );
hm1_cIter--;
cout << "The value of last element of hm1 is "
<< hm1_cIter -> second << "." << endl;
hm1_Iter = hm1.end( );
hm1_Iter--;
hm1.erase ( hm1_Iter );
// The following 2 lines would err because the iterator is const
// hm1_cIter = hm1.end ( );
// hm1_cIter--;
// hm1.erase ( hm1_cIter );
hm1_cIter = hm1.end( );
hm1_cIter--;
cout << "The value of last element of hm1 is now "
<< hm1_cIter -> second << "." << endl;
}
The value of last element of hm1 is 30.
The value of last element of hm1 is now 20.
hash_map::equal_range
Not
Bu, API artık kullanılmıyor. Bunun alternatifi Sınıf'tırunordered_map.
Belirtilen anahtardan büyük bir anahtara sahip bir anahtarı olan içindeki ilk öğeye hash_map ve anahtara eşit veya daha büyük bir anahtarla içindeki ilk öğeye hash_map sırasıyla bir yineleyici çifti döndürür.
pair <const_iterator, const_iterator> equal_range (const Key& key) const;
pair <iterator, iterator> equal_range (const Key& key);
Parametreler
key
Aranmakta olan öğenin hash_map sıralama anahtarıyla karşılaştırılacak bağımsız değişken anahtarı değeri.
Dönüş Değeri
Birincisi anahtarın, ikincisi de anahtarın çifti olacak lower_bound şekilde upper_bound bir çift yineleyici.
Üye işlevi tarafından döndürülen bir çiftin pr ilk yineleyicisine erişmek için ve komutunu kullanarak pr.first alt sınır yineleyicisini kullanın *(pr.first). Üye işlevi tarafından döndürülen bir çiftin pr ikinci yineleyicisine erişmek için ve komutunu kullanarak pr.second üst sınır yineleyicisini kullanın *(pr.second).
Örnek
// hash_map_equal_range.cpp
// compile with: /EHsc
#include <hash_map>
#include <iostream>
int main( )
{
using namespace std;
using namespace stdext;
typedef hash_map <int, int> IntMap;
IntMap hm1;
hash_map <int, int> :: const_iterator hm1_RcIter;
typedef pair <int, int> Int_Pair;
hm1.insert ( Int_Pair ( 1, 10 ) );
hm1.insert ( Int_Pair ( 2, 20 ) );
hm1.insert ( Int_Pair ( 3, 30 ) );
pair <IntMap::const_iterator, IntMap::const_iterator> p1, p2;
p1 = hm1.equal_range( 2 );
cout << "The lower bound of the element with "
<< "a key of 2 in the hash_map hm1 is: "
<< p1.first -> second << "." << endl;
cout << "The upper bound of the element with "
<< "a key of 2 in the hash_map hm1 is: "
<< p1.second -> second << "." << endl;
// Compare the upper_bound called directly
hm1_RcIter = hm1.upper_bound( 2 );
cout << "A direct call of upper_bound( 2 ) gives "
<< hm1_RcIter -> second << "," << endl
<< "matching the 2nd element of the pair"
<< " returned by equal_range( 2 )." << endl;
p2 = hm1.equal_range( 4 );
// If no match is found for the key,
// both elements of the pair return end( )
if ( ( p2.first == hm1.end( ) ) && ( p2.second == hm1.end( ) ) )
cout << "The hash_map hm1 doesn't have an element "
<< "with a key less than 40." << endl;
else
cout << "The element of hash_map hm1 with a key >= 40 is: "
<< p1.first -> first << "." << endl;
}
The lower bound of the element with a key of 2 in the hash_map hm1 is: 20.
The upper bound of the element with a key of 2 in the hash_map hm1 is: 30.
A direct call of upper_bound( 2 ) gives 30,
matching the 2nd element of the pair returned by equal_range( 2 ).
The hash_map hm1 doesn't have an element with a key less than 40.
hash_map::erase
Not
Bu, API artık kullanılmıyor. Bunun alternatifi Sınıf'tırunordered_map.
Belirtilen konumlardan bir öğeyi veya bir hash_map öğe aralığını kaldırır veya belirtilen bir anahtarla eşleşen öğeleri kaldırır.
iterator erase(iterator _Where);
iterator erase(iterator first, iterator last);
size_type erase(const key_type& key);
Parametreler
_Where
öğesinden hash_mapkaldırılacak öğenin konumu.
first
öğesinden hash_mapkaldırılan ilk öğenin konumu.
last
konumundan kaldırılan son öğenin hemen ötesindeki hash_mapkonumu.
key
öğesinden hash_mapkaldırılacak öğelerin anahtar değeri.
Dönüş Değeri
İlk iki üye işlevi için, kaldırılan öğelerin ötesinde kalan ilk öğeyi belirten çift yönlü bir yineleyici veya böyle bir öğe yoksa sonuna hash_map yönelik bir işaretçi.
Üçüncü üye işlevi için, öğesinden hash_mapkaldırılan öğe sayısını döndürür.
Açıklamalar
Üye işlevleri hiçbir zaman özel durum oluşturmaz.
Örnek
Aşağıdaki örnekte üye işlevinin kullanımı gösterilmektedir hash_map::erase .
// hash_map_erase.cpp
// compile with: /EHsc
#include <hash_map>
#include <iostream>
int main()
{
using namespace std;
using namespace stdext;
hash_map<int, int> hm1, hm2, hm3;
hash_map<int, int> :: iterator pIter, Iter1, Iter2;
int i;
hash_map<int, int>::size_type n;
typedef pair<int, int> Int_Pair;
for (i = 1; i < 5; i++)
{
hm1.insert(Int_Pair (i, i));
hm2.insert(Int_Pair (i, i*i));
hm3.insert(Int_Pair (i, i-1));
}
// The 1st member function removes an element at a given position
Iter1 = ++hm1.begin();
hm1.erase(Iter1);
cout << "After the 2nd element is deleted, the hash_map hm1 is:";
for (pIter = hm1.begin(); pIter != hm1.end(); pIter++)
cout << " " << pIter -> second;
cout << "." << endl;
// The 2nd member function removes elements
// in the range [ first, last)
Iter1 = ++hm2.begin();
Iter2 = --hm2.end();
hm2.erase(Iter1, Iter2);
cout << "After the middle two elements are deleted, "
<< "the hash_map hm2 is:";
for (pIter = hm2.begin(); pIter != hm2.end(); pIter++)
cout << " " << pIter -> second;
cout << "." << endl;
// The 3rd member function removes elements with a given key
n = hm3.erase(2);
cout << "After the element with a key of 2 is deleted,\n"
<< "the hash_map hm3 is:";
for (pIter = hm3.begin(); pIter != hm3.end(); pIter++)
cout << " " << pIter -> second;
cout << "." << endl;
// The 3rd member function returns the number of elements removed
cout << "The number of elements removed from hm3 is: "
<< n << "." << endl;
// The dereferenced iterator can also be used to specify a key
Iter1 = ++hm3.begin();
hm3.erase(Iter1);
cout << "After another element with a key equal to that"
<< endl;
cout << "of the 2nd element is deleted, "
<< "the hash_map hm3 is:";
for (pIter = hm3.begin(); pIter != hm3.end(); pIter++)
cout << " " << pIter -> second;
cout << "." << endl;
}
After the 2nd element is deleted, the hash_map hm1 is: 1 3 4.
After the middle two elements are deleted, the hash_map hm2 is: 1 16.
After the element with a key of 2 is deleted,
the hash_map hm3 is: 0 2 3.
The number of elements removed from hm3 is: 1.
After another element with a key equal to that
of the 2nd element is deleted, the hash_map hm3 is: 0 3.
hash_map::find
Not
Bu, API artık kullanılmıyor. Bunun alternatifi Sınıf'tırunordered_map.
Belirtilen anahtara eşdeğer bir anahtara sahip bir hash_map öğenin konumunu adresleyen bir yineleyici döndürür.
iterator find(const Key& key);
const_iterator find(const Key& key) const;
Parametreler
key
Aranmakta olan öğenin hash_map sıralama anahtarıyla eşleştirilecek anahtar değeri.
Dönüş Değeri
Belirtilen anahtara sahip bir öğenin konumunu veya anahtar için eşleşme bulunamazsa içindeki hash_map son öğenin başarılı olduğu konumu ele alan bir yineleyici.
Açıklamalar
find , sıralama anahtarı, karşılaştırılabilirlikten küçük bir ilişkiyi temel alan bir sıralamaya neden olan bir ikili koşul altındaki bağımsız değişken anahtarına eşdeğer olan bir öğeyi hash_map ele alan bir yineleyici döndürür.
değerinin dönüş değeri find bir const_iteratorhash_map öğesine atanmışsa nesnesi değiştirilemez. dönüş değeri find bir iteratorhash_map öğesine atanmışsa nesnesi değiştirilebilir
Örnek
// hash_map_find.cpp
// compile with: /EHsc
#include <hash_map>
#include <iostream>
int main( )
{
using namespace std;
using namespace stdext;
hash_map <int, int> hm1;
hash_map <int, int> :: const_iterator hm1_AcIter, hm1_RcIter;
typedef pair <int, int> Int_Pair;
hm1.insert ( Int_Pair ( 1, 10 ) );
hm1.insert ( Int_Pair ( 2, 20 ) );
hm1.insert ( Int_Pair ( 3, 30 ) );
hm1_RcIter = hm1.find( 2 );
cout << "The element of hash_map hm1 with a key of 2 is: "
<< hm1_RcIter -> second << "." << endl;
// If no match is found for the key, end( ) is returned
hm1_RcIter = hm1.find( 4 );
if ( hm1_RcIter == hm1.end( ) )
cout << "The hash_map hm1 doesn't have an element "
<< "with a key of 4." << endl;
else
cout << "The element of hash_map hm1 with a key of 4 is: "
<< hm1_RcIter -> second << "." << endl;
// The element at a specific location in the hash_map can be found
// using a dereferenced iterator addressing the location
hm1_AcIter = hm1.end( );
hm1_AcIter--;
hm1_RcIter = hm1.find( hm1_AcIter -> first );
cout << "The element of hm1 with a key matching "
<< "that of the last element is: "
<< hm1_RcIter -> second << "." << endl;
}
The element of hash_map hm1 with a key of 2 is: 20.
The hash_map hm1 doesn't have an element with a key of 4.
The element of hm1 with a key matching that of the last element is: 30.
hash_map::get_allocator
Not
Bu, API artık kullanılmıyor. Bunun alternatifi Sınıf'tırunordered_map.
oluşturmak için kullanılan ayırıcı nesnesinin hash_mapbir kopyasını döndürür.
Allocator get_allocator() const;
Dönüş Değeri
tarafından hash_mapkullanılan ayırıcı.
Açıklamalar
sınıfı için ayırıcılar, sınıfın hash_map depolamayı nasıl yöneteceğini belirtir. C++ Standart Kitaplığı kapsayıcı sınıfları ile sağlanan varsayılan ayırıcılar çoğu programlama gereksinimi için yeterlidir. Kendi ayırıcı sınıfınızı yazmak ve kullanmak gelişmiş bir C++ konusudur.
Örnek
// hash_map_get_allocator.cpp
// compile with: /EHsc
#include <hash_map>
#include <iostream>
int main( )
{
using namespace std;
using namespace stdext;
hash_map <int, int>::allocator_type hm1_Alloc;
hash_map <int, int>::allocator_type hm2_Alloc;
hash_map <int, double>::allocator_type hm3_Alloc;
hash_map <int, int>::allocator_type hm4_Alloc;
// The following lines declare objects
// that use the default allocator.
hash_map <int, int> hm1;
hash_map <int, int> hm2;
hash_map <int, double> hm3;
hm1_Alloc = hm1.get_allocator( );
hm2_Alloc = hm2.get_allocator( );
hm3_Alloc = hm3.get_allocator( );
cout << "The number of integers that can be allocated"
<< endl << "before free memory is exhausted: "
<< hm2.max_size( ) << "." << endl;
cout << "The number of doubles that can be allocated"
<< endl << "before free memory is exhausted: "
<< hm3.max_size( ) << "." << endl;
// The following line creates a hash_map hm4
// with the allocator of hash_map hm1.
hash_map <int, int> hm4( less<int>( ), hm1_Alloc );
hm4_Alloc = hm4.get_allocator( );
// Two allocators are interchangeable if
// storage allocated from each can be
// deallocated with the other
if( hm1_Alloc == hm4_Alloc )
{
cout << "The allocators are interchangeable."
<< endl;
}
else
{
cout << "The allocators are not interchangeable."
<< endl;
}
}
hash_map::hash_map
Not
Bu, API artık kullanılmıyor. Bunun alternatifi Sınıf'tırunordered_map.
Boş olan veya başka hash_mapbir öğesinin tümünün veya bir bölümünün kopyası olan bir hash_map oluşturur.
hash_map();
explicit hash_map(
const Traits& Comp);
hash_map(
const Traits& Comp,
const Allocator& Al);
hash_map(
const hash_map& Right);
hash_map(
hash_map&& Right);
hash_map(
initializer_list<Type> IList);hash_map(initializer_list<Type> IList,
const key_compare& Comp);
hash_map(
initializer_list<Type> IList,
const key_compare& Comp,
const allocator_type& Al);
template <class InputIterator>
hash_map(
InputIterator First,
InputIterator Last);
template <class InputIterator>
hash_map(
InputIterator First,
InputIterator Last,
const Traits& Comp);
template <class InputIterator>
hash_map(
InputIterator First,
InputIterator Last,
const Traits& Comp,
const Allocator& Al
Parametreler
Al
Bu hash_map nesne için kullanılacak depolama ayırıcı sınıfı, varsayılan olarak Allocatorolarak kullanılır.
Comp
içindeki öğeleri Traitssıralamak için kullanılan const hash_map türündeki karşılaştırma işlevi, varsayılan olarak hash_compareolarak kullanılır.
Right
hash_map Bu haritanın bir kopyası olması gerekir.
First
Kopyalanacak öğe aralığındaki ilk öğenin konumu.
Last
Kopyalanacak öğe aralığının ötesindeki ilk öğenin konumu.
IList
initializer_list
Açıklamalar
Tüm oluşturucular için hash_map bellek depolamasını yöneten ve daha sonra çağrılarak get_allocatordöndürülebilen bir ayırıcı nesnesi türünü depolar. Ayırıcı parametresi genellikle sınıf bildirimlerinde ve alternatif ayırıcıları değiştirmek için kullanılan önişlem makrolarında atlanır.
Tüm oluşturucular kendi öğesini hash_mapbaşlatır.
Tüm oluşturucular, anahtarları Traits arasında bir düzen oluşturmak için kullanılan ve daha sonra çağrılarak hash_mapdöndürülebilecek türde key_comp bir işlev nesnesi depolar.
İlk üç oluşturucu boş bir başlangıç hash_mapbelirtin, buna ek olarak, ikincisi öğelerin sırasını oluştururken kullanılacak karşılaştırma işlevinin türünü (Comp) belirtir ve üçüncüsü kullanılacak ayırıcı türünü (Al) açıkça belirtir. anahtar sözcüğü explicit belirli türdeki otomatik tür dönüştürmelerini gizler.
Dördüncü oluşturucu, öğesinin hash_mapRightbir kopyasını belirtir.
Sonraki üç oluşturucu, sınıfın [First, Last) ve ayırıcının karşılaştırma işlevinin türünü belirtirken açıklığı artırarak aralığını hash_mapTraits kopyalar.
Son oluşturucu öğesini hash_mapRighttaşır.
hash_map::insert
Not
Bu, API artık kullanılmıyor. Bunun alternatifi Sınıf'tırunordered_map.
içine bir öğe veya öğe hash_maparalığı ekler.
pair <iterator, bool> insert(
const value_type& val);
iterator insert(
const_iterator _Where,
const value_type& val);
template <class InputIterator>
void insert(
InputIterator first,
InputIterator last);
template <class ValTy>
pair <iterator, bool>
insert(
ValTy&& val);
template <class ValTy>
iterator insert(
const_iterator _Where,
ValTy&& val);
Parametreler
val
Öğesi zaten bu öğeyi (veya daha genel olarak, anahtarı eşdeğer olarak sıralanmış olan bir öğe) içermediği sürece hash_map içine eklenecek hash_map öğenin değeri.
_Where
Doğru ekleme noktasını aramaya başlama yeriyle ilgili bir ipucu.
first
bir öğesinden hash_mapkopyalanacak ilk öğenin konumu.
last
bir öğesinden hash_mapkopyalanacak son öğenin hemen ötesindeki konum.
Dönüş Değeri
İlk insert üye işlevi, ekleme yapıldıysa ve anahtarı sıralamada eşdeğer bir değere sahip olan ve booltrue yineleyici bileşeni yeni bir öğenin eklendiği adresi veya öğenin zaten bulunduğu adresi döndüren bir öğe içeriyorsa bileşeni döndüren false bir çift hash_map döndürür.
Bu üye işlevi prtarafından döndürülen bir çiftin pr.first yineleyici bileşenine erişmek için kullanın ve başvuruyu geri almak için kullanın(pr.first). Bu üye işlevi booltarafından döndürülen bir çiftin pr bileşenine erişmek pr.second için kullanın ve başvuruyu geri almak için kullanın(pr.second).
İpucu sürümü olan ikinci insert üye işlevi, yeni öğenin içine hash_mapeklendiği konumu gösteren bir yineleyici döndürür.
Son iki insert üye işlevi, eklenen değerin yapısını taşımaları dışında ilk iki işlevle aynı şekilde davranır.
Açıklamalar
value_type Bir öğenin değeri bir çifttir, böylece bir öğenin değeri ilk bileşen anahtar değerine eşit, ikinci bileşen de öğenin veri değerine eşit olan sıralı bir çift olur.
Ekleme noktası hemen izlerse _Whereekleme ipucu sürümü için logaritmik saat yerine amorti edilmiş sabit sürede gerçekleşebilir.
Üçüncü üye işlevi, öğe değerlerinin hash_map sırasını belirtilen küme aralığındaki *[First, Last)* yineleyici tarafından ele alınan her öğeye karşılık gelen bir öğeye ekler.
Örnek
// hash_map_insert.cpp
// compile with: /EHsc
#include <hash_map>
#include <iostream>
#include <string>
int main()
{
using namespace std;
using namespace stdext;
hash_map<int, int>::iterator hm1_pIter, hm2_pIter;
hash_map<int, int> hm1, hm2;
typedef pair<int, int> Int_Pair;
hm1.insert(Int_Pair(1, 10));
hm1.insert(Int_Pair(2, 20));
hm1.insert(Int_Pair(3, 30));
hm1.insert(Int_Pair(4, 40));
cout << "The original elements (Key => Value) of hm1 are:";
for (hm1_pIter = hm1.begin(); hm1_pIter != hm1.end(); hm1_pIter++)
cout << endl << " " << hm1_pIter -> first << " => "
<< hm1_pIter->second;
cout << endl;
pair< hash_map<int,int>::iterator, bool > pr;
pr = hm1.insert(Int_Pair(1, 10));
if (pr.second == true)
{
cout << "The element 10 was inserted in hm1 successfully."
<< endl;
}
else
{
cout << "The element 10 already exists in hm1\n"
<< "with a key value of "
<< "((pr.first) -> first) = " << (pr.first)->first
<< "." << endl;
}
// The hint version of insert
hm1.insert(--hm1.end(), Int_Pair(5, 50));
cout << "After the insertions, the elements of hm1 are:";
for (hm1_pIter = hm1.begin(); hm1_pIter != hm1.end(); hm1_pIter++)
cout << endl << hm1_pIter -> first << " => "
<< hm1_pIter->second;
cout << endl;
hm2.insert(Int_Pair(10, 100));
// The templatized version inserting a range
hm2.insert( ++hm1.begin(), --hm1.end() );
cout << "After the insertions, the elements of hm2 are:";
for (hm2_pIter = hm2.begin(); hm2_pIter != hm2.end(); hm2_pIter++)
cout << endl << hm2_pIter -> first << " => "
<< hm2_pIter->second;
cout << endl;
// The templatized versions move constructing elements
hash_map<int, string> hm3, hm4;
pair<int, string> is1(1, "a"), is2(2, "b");
hm3.insert(move(is1));
cout << "After the move insertion, hm3 contains:" << endl
<< hm3.begin()->first
<< " => " << hm3.begin()->second
<< endl;
hm4.insert(hm4.begin(), move(is2));
cout << "After the move insertion, hm4 contains:" << endl
<< hm4.begin()->first
<< " => " << hm4.begin()->second
<< endl;
}
The original elements (Key => Value) of hm1 are:
1 => 10
2 => 20
3 => 30
4 => 40
The element 10 already exists in hm1
with a key value of ((pr.first) -> first) = 1.
After the insertions, the elements of hm1 are:
1 => 10
2 => 20
3 => 30
4 => 40
5 => 50
After the insertions, the elements of hm2 are:
2 => 20
10 => 100
3 => 30
4 => 40
After the move insertion, hm3 contains:
1 => a
After the move insertion, hm4 contains:
2 => b
hash_map::iterator
Not
Bu, API artık kullanılmıyor. Bunun alternatifi Sınıf'tırunordered_map.
bir içindeki herhangi bir öğeyi okuyabilen veya değiştirebilen çift yönlü bir yineleyici sağlayan tür hash_map.
typedef list<typename Traits::value_type, typename Traits::allocator_type>::iterator iterator;
Açıklamalar
iterator tarafından hash_map tanımlanan, ilk üyesi öğenin anahtarı olan ve ikinci üyesi öğesi tarafından tutulan eşlenmiş datum olan türündeki value_typenesneleri pair<const Key, Type>olan öğelere işaret eder.
Multimap'teki bir öğeye işaret eden adlı Iter yineleyicinin başvurularını geri almak için işlecini -> kullanın.
öğesinin anahtarının değerine erişmek için, Iter->firstile eşdeğer (*Iter).firstolan kullanın. öğesinin eşlenmiş veri kümesinin değerine erişmek için öğesine Iter->secondeşdeğer (*Iter).secondolan kullanın.
Bir öğenin değerini değiştirmek için bir tür iterator kullanılabilir.
Örnek
nasıl bildirilip kullanılacağına ilişkin bir örnek için begin örneğine iteratorbakın.
hash_map::key_comp
Not
Bu, API artık kullanılmıyor. Bunun alternatifi Sınıf'tırunordered_map.
içindeki anahtarları sıralamak için kullanılan karşılaştırma nesnesinin bir hash_mapkopyasını alır.
key_compare key_comp() const;
Dönüş Değeri
öğesinin hash_map öğelerini sıralamak için kullandığı işlev nesnesini döndürür.
Açıklamalar
Depolanan nesne üye işlevini tanımlar
bool operator( const Key& left, const Key&right );
true
left döndürür ve sıralama düzeninde bu değere right eşit değildir.
Örnek
// hash_map_key_comp.cpp
// compile with: /EHsc
#include <hash_map>
#include <iostream>
int main( )
{
using namespace std;
using namespace stdext;
hash_map <int, int, hash_compare<int, less<int> > > hm1;
hash_map <int, int, hash_compare<int, less<int> > >::key_compare
kc1 = hm1.key_comp( ) ;
// Operator stored in kc1 tests order & returns bool value
bool result1 = kc1( 2, 3 ) ;
if( result1 == true )
{
cout << "kc1( 2,3 ) returns value of true,"
<< "\n where kc1 is the function object of hm1"
<< " of type key_compare." << endl;
}
else
{
cout << "kc1( 2,3 ) returns value of false"
<< "\n where kc1 is the function object of hm1"
<< " of type key_compare." << endl;
}
hash_map <int, int, hash_compare<int, greater<int> > > hm2;
hash_map <int, int, hash_compare<int, greater<int> > >
::key_compare kc2 = hm2.key_comp( );
// Operator stored in kc2 tests order & returns bool value
bool result2 = kc2( 2, 3 ) ;
if( result2 == true )
{
cout << "kc2( 2,3 ) returns value of true,"
<< "\n where kc2 is the function object of hm2"
<< " of type key_compare." << endl;
}
else
{
cout << "kc2( 2,3 ) returns value of false,"
<< "\n where kc2 is the function object of hm2"
<< " of type key_compare." << endl;
}
}
hash_map::key_compare
Not
Bu, API artık kullanılmıyor. Bunun alternatifi Sınıf'tırunordered_map.
Eşlemdeki iki öğeye ilişkin göreli düzeni belirlemek için iki sıralama anahtarını karşılaştırabilen bir işlev nesnesi sağlayan tür.
typedef Traits key_compare;
Açıklamalar
key_compare , şablon parametresinin Traitseş anlamlısıdır.
Hakkında daha fazla bilgi Traits için Sınıfhash_map bakın.
Örnek
nasıl bildirilip kullanılacağına key_compilişkin bir örnek için key_compare örneğine bakın.
hash_map::key_type
Not
Bu, API artık kullanılmıyor. Bunun alternatifi Sınıf'tırunordered_map.
Türü, öğesinin her öğesini hash_mapoluşturan sıralama anahtarı nesnesini açıklar.
typedef Key key_type;
Açıklamalar
key_type , şablon parametresinin Keyeş anlamlısıdır.
hakkında Keydaha fazla bilgi için Sınıfhash_map bakın.
Örnek
nasıl bildirilip kullanılacağına value_typeilişkin bir örnek için key_type örneğine bakın.
hash_map::lower_bound
Not
Bu, API artık kullanılmıyor. Bunun alternatifi Sınıf'tırunordered_map.
Bir yineleyiciyi, belirtilen bir anahtara eşit veya ondan daha büyük bir anahtar değerine sahip bir içindeki ilk öğeye hash_map döndürür.
iterator lower_bound(const Key& key);
const_iterator lower_bound(const Key& key) const;
Parametreler
key
Aranmakta olan öğenin hash_map sıralama anahtarıyla karşılaştırılacak bağımsız değişken anahtarı değeri.
Dönüş Değeri
bir iterator veya const_iterator içindeki bir öğenin hash_map konumunu, bağımsız değişken anahtarına eşit veya ondan büyük bir anahtarla ya da anahtar için eşleşme bulunamazsa içindeki hash_map son öğeyi tamamlayan konumu giderir.
değerinin dönüş değeri lower_bound bir const_iteratorhash_map öğesine atanmışsa nesnesi değiştirilemez. değerinin dönüş değeri lower_bound bir iteratorhash_map öğesine atanmışsa, nesnesi değiştirilebilir.
Örnek
// hash_map_lower_bound.cpp
// compile with: /EHsc
#include <hash_map>
#include <iostream>
int main( )
{
using namespace std;
using namespace stdext;
hash_map <int, int> hm1;
hash_map <int, int> :: const_iterator hm1_AcIter, hm1_RcIter;
typedef pair <int, int> Int_Pair;
hm1.insert ( Int_Pair ( 1, 10 ) );
hm1.insert ( Int_Pair ( 2, 20 ) );
hm1.insert ( Int_Pair ( 3, 30 ) );
hm1_RcIter = hm1.lower_bound( 2 );
cout << "The first element of hash_map hm1 with a key of 2 is: "
<< hm1_RcIter -> second << "." << endl;
// If no match is found for the key, end( ) is returned
hm1_RcIter = hm1. lower_bound ( 4 );
if ( hm1_RcIter == hm1.end( ) )
cout << "The hash_map hm1 doesn't have an element "
<< "with a key of 4." << endl;
else
cout << "The element of hash_map hm1 with a key of 4 is: "
<< hm1_RcIter -> second << "." << endl;
// An element at a specific location in the hash_map can be
// found using a dereferenced iterator addressing the location
hm1_AcIter = hm1.end( );
hm1_AcIter--;
hm1_RcIter = hm1. lower_bound ( hm1_AcIter -> first );
cout << "The element of hm1 with a key matching "
<< "that of the last element is: "
<< hm1_RcIter -> second << "." << endl;
}
The first element of hash_map hm1 with a key of 2 is: 20.
The hash_map hm1 doesn't have an element with a key of 4.
The element of hm1 with a key matching that of the last element is: 30.
hash_map::mapped_type
Not
Bu, API artık kullanılmıyor. Bunun alternatifi Sınıf'tırunordered_map.
içinde depolanan veri türünü temsil eden bir hash_maptür.
typedef Type mapped_type;
Açıklamalar
türü mapped_type , şablon parametresi Typeiçin bir eş anlamlıdır.
Hakkında daha fazla bilgi Type için Sınıfhash_map bakın.
Örnek
nasıl bildirilip kullanılacağına value_typeilişkin bir örnek için key_type örneğine bakın.
hash_map::max_size
Not
Bu, API artık kullanılmıyor. Bunun alternatifi Sınıf'tırunordered_map.
değerinin uzunluk üst sınırını hash_mapdöndürür.
size_type max_size() const;
Dönüş Değeri
mümkün olan en uzun uzunluk hash_map.
Örnek
// hash_map_max_size.cpp
// compile with: /EHsc
#include <hash_map>
#include <iostream>
int main( )
{
using namespace std;
using namespace stdext;
hash_map <int, int> hm1;
hash_map <int, int> :: size_type i;
i = hm1.max_size( );
cout << "The maximum possible length "
<< "of the hash_map is " << i << "."
<< endl << "(Magnitude is machine specific.)";
}
hash_map::operator[]
Not
Bu, API artık kullanılmıyor. Bunun alternatifi Sınıf'tırunordered_map.
Belirtilen anahtar değerine sahip öğesine hash_map öğe ekler.
Type& operator[](const Key& key);
Type& operator[](Key&& key);
Parametreler
key
Eklenecek öğenin anahtar değeri.
Dönüş Değeri
Eklenen öğenin veri değerine başvuru.
Açıklamalar
Bağımsız değişken anahtarı değeri bulunamazsa, veri türünün varsayılan değeriyle birlikte eklenir.
operator[] kullanarak içine hash_map m öğe eklemek için kullanılabilir
m[ key] = DataValue;
burada DataValue, öğesinin mapped_type anahtar değeri olan değeridir key.
Öğe eklemek için kullanılırken operator[] , döndürülen başvuru eklemenin önceden var olan bir öğeyi değiştirdiğini veya yeni bir öğe oluşturduğunu göstermez. üye işlevleri find ve insert belirtilen anahtara sahip bir öğenin eklemeden önce zaten mevcut olup olmadığını belirlemek için kullanılabilir.
Örnek
// hash_map_op_ref.cpp
// compile with: /EHsc
#include <hash_map>
#include <iostream>
#include <string>
int main( )
{
using namespace std;
using namespace stdext;
typedef pair <const int, int> cInt2Int;
hash_map <int, int> hm1;
hash_map <int, int> :: iterator pIter;
// Insert a data value of 10 with a key of 1
// into a hash_map using the operator[] member function
hm1[ 1 ] = 10;
// Compare other ways to insert objects into a hash_map
hm1.insert ( hash_map <int, int> :: value_type ( 2, 20 ) );
hm1.insert ( cInt2Int ( 3, 30 ) );
cout << "The keys of the mapped elements are:";
for ( pIter = hm1.begin( ) ; pIter != hm1.end( ) ; pIter++ )
cout << " " << pIter -> first;
cout << "." << endl;
cout << "The values of the mapped elements are:";
for ( pIter = hm1.begin( ) ; pIter != hm1.end( ) ; pIter++ )
cout << " " << pIter -> second;
cout << "." << endl;
// If the key already exists, operator[]
// changes the value of the datum in the element
hm1[ 2 ] = 40;
// operator[] will also insert the value of the data
// type's default constructor if the value is unspecified
hm1[5];
cout << "The keys of the mapped elements are now:";
for ( pIter = hm1.begin( ) ; pIter != hm1.end( ) ; pIter++ )
cout << " " << pIter -> first;
cout << "." << endl;
cout << "The values of the mapped elements are now:";
for ( pIter = hm1.begin( ) ; pIter != hm1.end( ) ; pIter++ )
cout << " " << pIter -> second;
cout << "." << endl;
// operator[] will also insert by moving a key
hash_map <string, int> hm2;
string str("a");
hm2[move(str)] = 1;
cout << "The moved key is " << hm2.begin()->first
<< ", with value " << hm2.begin()->second << endl;
}
hash_map::operator=
Not
Bu, API artık kullanılmıyor. Bunun alternatifi Sınıf'tırunordered_map.
öğesinin hash_map öğelerini başka hash_mapbir kopyasıyla değiştirir.
hash_map& operator=(const hash_map& right);
hash_map& operator=(hash_map&& right);
Parametreler
right
sınıfına righthash_mapkopyalanıyor.
Açıklamalar
bir hash_mapiçindeki mevcut öğeleri sildikten sonra içindekileri operator=right kopyalar veya içine hash_maptaşır.
Örnek
// hash_map_operator_as.cpp
// compile with: /EHsc
#include <hash_map>
#include <iostream>
int main( )
{
using namespace std;
using namespace stdext;
hash_map<int, int> v1, v2, v3;
hash_map<int, int>::iterator iter;
v1.insert(pair<int, int>(1, 10));
cout << "v1 = " ;
for (iter = v1.begin(); iter != v1.end(); iter++)
cout << iter->second << " ";
cout << endl;
v2 = v1;
cout << "v2 = ";
for (iter = v2.begin(); iter != v2.end(); iter++)
cout << iter->second << " ";
cout << endl;
// move v1 into v2
v2.clear();
v2 = move(v1);
cout << "v2 = ";
for (iter = v2.begin(); iter != v2.end(); iter++)
cout << iter->second << " ";
cout << endl;
}
hash_map::pointer
Not
Bu, API artık kullanılmıyor. Bunun alternatifi Sınıf'tırunordered_map.
içindeki bir öğeye işaretçi sağlayan tür hash_map.
typedef list<typename _Traits::value_type, typename _Traits::allocator_type>::pointer pointer;
Açıklamalar
Bir öğenin değerini değiştirmek için bir tür pointer kullanılabilir.
Çoğu durumda, nesnedeki iteratorhash_map öğelere erişmek için bir kullanılmalıdır.
hash_map::rbegin
Not
Bu, API artık kullanılmıyor. Bunun alternatifi Sınıf'tırunordered_map.
ters çevrilmiş hash_mapiçindeki ilk öğeyi ele alan bir yineleyici döndürür.
const_reverse_iterator rbegin() const;
reverse_iterator rbegin();
Dönüş Değeri
Ters çevrilmiş hash_map bir içindeki ilk öğeyi veya ters çevrilmemiş hash_mapiçindeki son öğeyi ele alan ters çift yönlü yineleyici.
Açıklamalar
rbegin, ile kullanıldığı gibi hash_map ters çevrilmiş begin bir hash_mapile kullanılır.
değerinin dönüş değeri rbegin öğesine const_reverse_iteratorhash_map atanmışsa nesnesi değiştirilemez. değerinin dönüş değeri rbegin bir reverse_iteratorhash_map öğesine atanmışsa nesnesi değiştirilebilir.
rbegin geriye doğru yinelemek hash_map için kullanılabilir.
Örnek
// hash_map_rbegin.cpp
// compile with: /EHsc
#include <hash_map>
#include <iostream>
int main( )
{
using namespace std;
using namespace stdext;
hash_map <int, int> hm1;
hash_map <int, int> :: iterator hm1_Iter;
hash_map <int, int> :: reverse_iterator hm1_rIter;
hash_map <int, int> :: const_reverse_iterator hm1_crIter;
typedef pair <int, int> Int_Pair;
hm1.insert ( Int_Pair ( 1, 10 ) );
hm1.insert ( Int_Pair ( 2, 20 ) );
hm1.insert ( Int_Pair ( 3, 30 ) );
hm1_rIter = hm1.rbegin( );
cout << "The first element of the reversed hash_map hm1 is "
<< hm1_rIter -> first << "." << endl;
// begin can be used to start an iteration
// through a hash_map in a forward order
cout << "The hash_map is: ";
for ( hm1_Iter = hm1.begin( ) ; hm1_Iter != hm1.end( ); hm1_Iter++)
cout << hm1_Iter -> first << " ";
cout << "." << endl;
// rbegin can be used to start an iteration
// through a hash_map in a reverse order
cout << "The reversed hash_map is: ";
for ( hm1_rIter = hm1.rbegin( ) ; hm1_rIter != hm1.rend( ); hm1_rIter++)
cout << hm1_rIter -> first << " ";
cout << "." << endl;
// A hash_map element can be erased by dereferencing to its key
hm1_rIter = hm1.rbegin( );
hm1.erase ( hm1_rIter -> first );
hm1_rIter = hm1.rbegin( );
cout << "After the erasure, the first element "
<< "in the reversed hash_map is "
<< hm1_rIter -> first << "." << endl;
}
The first element of the reversed hash_map hm1 is 3.
The hash_map is: 1 2 3 .
The reversed hash_map is: 3 2 1 .
After the erasure, the first element in the reversed hash_map is 2.
hash_map::reference
Not
Bu, API artık kullanılmıyor. Bunun alternatifi Sınıf'tırunordered_map.
içinde depolanan bir öğeye başvuru sağlayan tür hash_map.
typedef list<typename _Traits::value_type, typename _Traits::allocator_type>::reference reference;
Örnek
// hash_map_reference.cpp
// compile with: /EHsc
#include <hash_map>
#include <iostream>
int main( )
{
using namespace std;
using namespace stdext;
hash_map <int, int> hm1;
typedef pair <int, int> Int_Pair;
hm1.insert ( Int_Pair ( 1, 10 ) );
hm1.insert ( Int_Pair ( 2, 20 ) );
// Declare and initialize a const_reference &Ref1
// to the key of the first element
const int &Ref1 = ( hm1.begin( ) -> first );
// The following line would cause an error as the
// non-const_reference cannot be used to access the key
// int &Ref1 = ( hm1.begin( ) -> first );
cout << "The key of first element in the hash_map is "
<< Ref1 << "." << endl;
// Declare and initialize a reference &Ref2
// to the data value of the first element
int &Ref2 = ( hm1.begin( ) -> second );
cout << "The data value of first element in the hash_map is "
<< Ref2 << "." << endl;
// The non-const_reference can be used to modify the
// data value of the first element
Ref2 = Ref2 + 5;
cout << "The modified data value of first element is "
<< Ref2 << "." << endl;
}
The key of first element in the hash_map is 1.
The data value of first element in the hash_map is 10.
The modified data value of first element is 15.
hash_map::rend
Not
Bu, API artık kullanılmıyor. Bunun alternatifi Sınıf'tırunordered_map.
Ters çevrilmiş hash_mapbir içindeki son öğeyi başaran konumu ele alan bir yineleyici döndürür.
const_reverse_iterator rend() const;
reverse_iterator rend();
Dönüş Değeri
Ters çevrilmiş bir öğedeki son öğeyi (ters hash_map çevrilmemiş hash_mapöğedeki ilk öğeden önce gelen konum) başarılı olan konumu ele alan ters çift yönlü yineleyici.
Açıklamalar
rend, ile kullanıldığı gibi hash_map ters çevrilmiş end bir hash_mapile kullanılır.
değerinin dönüş değeri rend öğesine const_reverse_iteratorhash_map atanmışsa nesnesi değiştirilemez. değerinin dönüş değeri rend bir reverse_iteratorhash_map öğesine atanmışsa nesnesi değiştirilebilir.
rend , ters yineleyicinin sonuna hash_mapulaşıp ulaşmadığını test etmek için kullanılabilir.
tarafından rend döndürülen değer başvurulmamalıdır.
Örnek
// hash_map_rend.cpp
// compile with: /EHsc
#include <hash_map>
#include <iostream>
int main( )
{
using namespace std;
using namespace stdext;
hash_map <int, int> hm1;
hash_map <int, int> :: iterator hm1_Iter;
hash_map <int, int> :: reverse_iterator hm1_rIter;
hash_map <int, int> :: const_reverse_iterator hm1_crIter;
typedef pair <int, int> Int_Pair;
hm1.insert ( Int_Pair ( 1, 10 ) );
hm1.insert ( Int_Pair ( 2, 20 ) );
hm1.insert ( Int_Pair ( 3, 30 ) );
hm1_rIter = hm1.rend( );
hm1_rIter--;
cout << "The last element of the reversed hash_map hm1 is "
<< hm1_rIter -> first << "." << endl;
// begin can be used to start an iteration
// through a hash_map in a forward order
cout << "The hash_map is: ";
for ( hm1_Iter = hm1.begin( ) ; hm1_Iter != hm1.end( );
hm1_Iter++)
cout << hm1_Iter -> first << " ";
cout << "." << endl;
// rbegin can be used to start an iteration
// through a hash_map in a reverse order
cout << "The reversed hash_map is: ";
for ( hm1_rIter = hm1.rbegin( ) ; hm1_rIter != hm1.rend( );
hm1_rIter++)
cout << hm1_rIter -> first << " ";
cout << "." << endl;
// A hash_map element can be erased by dereferencing to its key
hm1_rIter = --hm1.rend( );
hm1.erase ( hm1_rIter -> first );
hm1_rIter = hm1.rend( );
hm1_rIter--;
cout << "After the erasure, the last element "
<< "in the reversed hash_map is "
<< hm1_rIter -> first << "." << endl;
}
The last element of the reversed hash_map hm1 is 1.
The hash_map is: 1 2 3 .
The reversed hash_map is: 3 2 1 .
After the erasure, the last element in the reversed hash_map is 2.
hash_map::reverse_iterator
Not
Bu, API artık kullanılmıyor. Bunun alternatifi Sınıf'tırunordered_map.
Ters çevrilmiş hash_mapiçindeki bir öğeyi okuyabilen veya değiştirebilen çift yönlü bir yineleyici sağlayan tür.
typedef list<typename Traits::value_type, typename Traits::allocator_type>::reverse_iterator reverse_iterator;
Açıklamalar
Bir tür reverse_iterator bir öğenin değerini değiştiremez ve öğesini tersten yinelemek hash_map için kullanılır.
reverse_iterator tarafından hash_map tanımlanan, ilk üyesi öğenin anahtarı olan ve ikinci üyesi öğesi tarafından tutulan eşlenmiş datum olan value_type nesneleri olan türündeki pair<const Key, Type>öğelere işaret eder.
içindeki bir reverse_iteratorrIter öğeye işaret eden bir başvuruyu hash_mapgeri almak için işlecini -> kullanın.
öğesinin anahtarının değerine erişmek için, rIter->firstile eşdeğer (*rIter).firstolan kullanın. öğesinin eşlenmiş veri kümesinin değerine erişmek için öğesine rIter->secondeşdeğer (*rIter).firstolan kullanın.
Örnek
nasıl bildirilip kullanılacağına rbeginilişkin bir örnek için reverse_iterator örneğine bakın.
hash_map::size
Not
Bu, API artık kullanılmıyor. Bunun alternatifi Sınıf'tırunordered_map.
içindeki hash_mapöğe sayısını döndürür.
size_type size() const;
Dönüş Değeri
geçerli uzunluğu hash_map.
Örnek
Aşağıdaki örnekte üye işlevinin kullanımı gösterilmektedir hash_map::size .
// hash_map_size.cpp
// compile with: /EHsc
#include <hash_map>
#include <iostream>
int main( )
{
using namespace std;
using namespace stdext;
hash_map<int, int> hm1, hm2;
hash_map<int, int>::size_type i;
typedef pair<int, int> Int_Pair;
hm1.insert(Int_Pair(1, 1));
i = hm1.size();
cout << "The hash_map length is " << i << "." << endl;
hm1.insert(Int_Pair(2, 4));
i = hm1.size();
cout << "The hash_map length is now " << i << "." << endl;
}
The hash_map length is 1.
The hash_map length is now 2.
hash_map::size_type
Not
Bu, API artık kullanılmıyor. Bunun alternatifi Sınıf'tırunordered_map.
içindeki öğe sayısını temsil eden işaretsiz bir hash_maptamsayı türü.
typedef list<typename _Traits::value_type, typename _Traits::allocator_type>::size_type size_type;
Örnek
Nasıl bildirilip kullanılacağına ilişkin örnek için size bkz. örnek size_type
hash_map::swap
Not
Bu, API artık kullanılmıyor. Bunun alternatifi Sınıf'tırunordered_map.
İki hash_mapöğesinin öğelerini değiştirir.
void swap(hash_map& right);
Parametreler
right
Hedef hash_mapile değiştirilecek öğeleri sağlayan bağımsız değişkenhash_map.
Açıklamalar
Üye işlevi, öğeleri değiştirilmekte olan iki hash_mapöğedeki öğeleri belirten hiçbir başvuruyu, işaretçiyi veya yineleyiciyi geçersiz kılmaz.
Örnek
// hash_map_swap.cpp
// compile with: /EHsc
#include <hash_map>
#include <iostream>
int main( )
{
using namespace std;
using namespace stdext;
hash_map <int, int> hm1, hm2, hm3;
hash_map <int, int>::iterator hm1_Iter;
typedef pair <int, int> Int_Pair;
hm1.insert ( Int_Pair ( 1, 10 ) );
hm1.insert ( Int_Pair ( 2, 20 ) );
hm1.insert ( Int_Pair ( 3, 30 ) );
hm2.insert ( Int_Pair ( 10, 100 ) );
hm2.insert ( Int_Pair ( 20, 200 ) );
hm3.insert ( Int_Pair ( 30, 300 ) );
cout << "The original hash_map hm1 is:";
for ( hm1_Iter = hm1.begin( ); hm1_Iter != hm1.end( ); hm1_Iter++ )
cout << " " << hm1_Iter -> second;
cout << "." << endl;
// This is the member function version of swap
// hm2 is said to be the argument hash_map;
// hm1 is said to be the target hash_map
hm1.swap( hm2 );
cout << "After swapping with hm2, hash_map hm1 is:";
for ( hm1_Iter = hm1.begin( ); hm1_Iter != hm1.end( ); hm1_Iter++ )
cout << " " << hm1_Iter -> second;
cout << "." << endl;
// This is the specialized template version of swap
swap( hm1, hm3 );
cout << "After swapping with hm3, hash_map hm1 is:";
for ( hm1_Iter = hm1.begin( ); hm1_Iter != hm1.end( ); hm1_Iter++ )
cout << " " << hm1_Iter -> second;
cout << "." << endl;
}
The original hash_map hm1 is: 10 20 30.
After swapping with hm2, hash_map hm1 is: 100 200.
After swapping with hm3, hash_map hm1 is: 300.
hash_map::upper_bound
Not
Bu, API artık kullanılmıyor. Bunun alternatifi Sınıf'tırunordered_map.
Bir anahtarın belirtilen anahtardan daha büyük bir hash_map değere sahip olduğu ilk öğeye bir yineleyici döndürür.
iterator upper_bound(const Key& key);
const_iterator upper_bound(const Key& key) const;
Parametreler
key
Aranmakta olan öğenin hash_map sıralama anahtarı değeriyle karşılaştırılacak bağımsız değişken anahtarı değeri.
Dönüş Değeri
Bir iterator veya const_iterator içindeki bir öğenin hash_map konumunu, bağımsız değişken anahtarından daha büyük bir anahtarla veya anahtar için eşleşme bulunamazsa içindeki hash_map son öğeyi tamamlayan konumu giderir.
Dönüş değeri bir const_iteratorhash_map öğesine atanmışsa nesne değiştirilemez. Dönüş değeri bir iteratorhash_map öğesine atanmışsa, nesne değiştirilebilir.
Örnek
// hash_map_upper_bound.cpp
// compile with: /EHsc
#include <hash_map>
#include <iostream>
int main( )
{
using namespace std;
using namespace stdext;
hash_map <int, int> hm1;
hash_map <int, int> :: const_iterator hm1_AcIter, hm1_RcIter;
typedef pair <int, int> Int_Pair;
hm1.insert ( Int_Pair ( 1, 10 ) );
hm1.insert ( Int_Pair ( 2, 20 ) );
hm1.insert ( Int_Pair ( 3, 30 ) );
hm1_RcIter = hm1.upper_bound( 2 );
cout << "The first element of hash_map hm1 with a key "
<< "greater than 2 is: "
<< hm1_RcIter -> second << "." << endl;
// If no match is found for the key, end is returned
hm1_RcIter = hm1. upper_bound ( 4 );
if ( hm1_RcIter == hm1.end( ) )
cout << "The hash_map hm1 doesn't have an element "
<< "with a key greater than 4." << endl;
else
cout << "The element of hash_map hm1 with a key > 4 is: "
<< hm1_RcIter -> second << "." << endl;
// The element at a specific location in the hash_map can be found
// using a dereferenced iterator addressing the location
hm1_AcIter = hm1.begin( );
hm1_RcIter = hm1. upper_bound ( hm1_AcIter -> first );
cout << "The 1st element of hm1 with a key greater than that\n"
<< "of the initial element of hm1 is: "
<< hm1_RcIter -> second << "." << endl;
}
The first element of hash_map hm1 with a key greater than 2 is: 30.
The hash_map hm1 doesn't have an element with a key greater than 4.
The 1st element of hm1 with a key greater than that
of the initial element of hm1 is: 20.
hash_map::value_comp
Not
Bu, API artık kullanılmıyor. Bunun alternatifi Sınıf'tırunordered_map.
anahtar değerlerini karşılaştırarak içindeki öğelerin sırasını belirleyen bir hash_map işlev nesnesi döndürür.
value_compare value_comp() const;
Dönüş Değeri
Bir öğesinin hash_map öğelerini sıralamak için kullandığı karşılaştırma işlevi nesnesini döndürür.
Açıklamalar
bir hash_mapmiçin, iki öğe e1 (k1, d1) ve e2 (k2, d2) türünde value_typenesnelerse, burada k1 ve k2 türünde anahtarlarıdır key_type ve d1d2 bunların türüne mapped_typeait veriler ise, m.value_comp()(e1, e2) ile eşdeğerdir m.key_comp()(k1, k2). Depolanan nesne üye işlevini tanımlar
bool operator(value_type& left, value_type& right);
anahtar değeri true önceyse ve sıralama düzenindeki anahtar değerine left eşit değilse döndürürright.
Örnek
// hash_map_value_comp.cpp
// compile with: /EHsc
#include <hash_map>
#include <iostream>
int main( )
{
using namespace std;
using namespace stdext;
hash_map <int, int, hash_compare<int, less<int> > > hm1;
hash_map <int, int, hash_compare<int, less<int> > >
::value_compare vc1 = hm1.value_comp( );
pair< hash_map<int,int>::iterator, bool > pr1, pr2;
pr1= hm1.insert ( hash_map <int, int> :: value_type ( 1, 10 ) );
pr2= hm1.insert ( hash_map <int, int> :: value_type ( 2, 5 ) );
if( vc1( *pr1.first, *pr2.first ) == true )
{
cout << "The element ( 1,10 ) precedes the element ( 2,5 )."
<< endl;
}
else
{
cout << "The element ( 1,10 ) does not precede the element ( 2,5 )."
<< endl;
}
if( vc1 ( *pr2.first, *pr1.first ) == true )
{
cout << "The element ( 2,5 ) precedes the element ( 1,10 )."
<< endl;
}
else
{
cout << "The element ( 2,5 ) does not precede the element ( 1,10 )."
<< endl;
}
}
hash_map::value_type
Not
Bu, API artık kullanılmıyor. Bunun alternatifi Sınıf'tırunordered_map.
içinde depolanan nesne türünü temsil eden bir hash_maptür.
typedef pair<const Key, Type> value_type;
Açıklamalar
value_type olarak bildirilir pair<const key_type, mapped_type> ve pair<key_type, mapped_type> ilişkilendirilebilir bir kapsayıcının anahtarları, tutarsız yineleyici veya başvuru kullanılarak değiştirilemez.
Örnek
// hash_map_value_type.cpp
// compile with: /EHsc
#include <hash_map>
#include <iostream>
int main( )
{
using namespace std;
using namespace stdext;
typedef pair <const int, int> cInt2Int;
hash_map <int, int> hm1;
hash_map <int, int> :: key_type key1;
hash_map <int, int> :: mapped_type mapped1;
hash_map <int, int> :: value_type value1;
hash_map <int, int> :: iterator pIter;
// value_type can be used to pass the correct type
// explicitly to avoid implicit type conversion
hm1.insert ( hash_map <int, int> :: value_type ( 1, 10 ) );
// Compare other ways to insert objects into a hash_map
hm1.insert ( cInt2Int ( 2, 20 ) );
hm1[ 3 ] = 30;
// Initializing key1 and mapped1
key1 = ( hm1.begin( ) -> first );
mapped1 = ( hm1.begin( ) -> second );
cout << "The key of first element in the hash_map is "
<< key1 << "." << endl;
cout << "The data value of first element in the hash_map is "
<< mapped1 << "." << endl;
// The following line would cause an error because
// the value_type is not assignable
// value1 = cInt2Int ( 4, 40 );
cout << "The keys of the mapped elements are:";
for ( pIter = hm1.begin( ) ; pIter != hm1.end( ) ; pIter++ )
cout << " " << pIter -> first;
cout << "." << endl;
cout << "The values of the mapped elements are:";
for ( pIter = hm1.begin( ) ; pIter != hm1.end( ) ; pIter++ )
cout << " " << pIter -> second;
cout << "." << endl;
}
The key of first element in the hash_map is 1.
The data value of first element in the hash_map is 10.
The keys of the mapped elements are: 1 2 3.
The values of the mapped elements are: 10 20 30.
Ayrıca bkz.
C++ Standart Kitaplığında İş Parçacığı Güvenliği
C++ Standart Kitaplığı Başvurusu