Standard Template Library Programmer's Guide

Здесь есть возможность читать онлайн «Standard Template Library Programmer's Guide» весь текст электронной книги совершенно бесплатно (целиком полную версию без сокращений). В некоторых случаях можно слушать аудио, скачать через торрент в формате fb2 и присутствует краткое содержание. Жанр: Программирование, Справочники, на английском языке. Описание произведения, (предисловие) а так же отзывы посетителей доступны на портале библиотеки ЛибКат.

Standard Template Library Programmer's Guide: краткое содержание, описание и аннотация

Предлагаем к чтению аннотацию, описание, краткое содержание или предисловие (зависит от того, что написал сам автор книги «Standard Template Library Programmer's Guide»). Если вы не нашли необходимую информацию о книге — напишите в комментариях, мы постараемся отыскать её.

This document contains reference on SGI STL implementation

Standard Template Library Programmer's Guide — читать онлайн бесплатно полную книгу (весь текст) целиком

Ниже представлен текст книги, разбитый по страницам. Система сохранения места последней прочитанной страницы, позволяет с удобством читать онлайн бесплатно книгу «Standard Template Library Programmer's Guide», без необходимости каждый раз заново искать на чём Вы остановились. Поставьте закладку, и сможете в любой момент перейти на страницу, на которой закончили чтение.

Тёмная тема
Сбросить

Интервал:

Закладка:

Сделать
Notes

[1] This member function relies on member template functions, which at present (early 1998) are not supported by all compilers. If your compiler supports member templates, you can call this function with any type of input iterator. If your compiler does not yet support member templates, though, then the arguments must either be of type const value_type* or of type hash_set::const_iterator .

See also

Associative Container, Hashed Associative Container, Simple Associative Container, Unique Hashed Associative Container, set , map , multiset , multimap , hash_map , hash_multiset , hash_multimap

hash_map

Category: containers

Component type: type

Description

Hash_map is a Hashed Associative Container that associates objects of type Key with objects of type Data . Hash_map is a Pair Associative Container, meaning that its value type is pair . It is also a Unique Associative Container, meaning that no two elements have keys that compare equal using EqualKey .

Looking up an element in a hash_map by its key is efficient, so hash_map is useful for "dictionaries" where the order of elements is irrelevant. If it is important for the elements to be in a particular order, however, then map is more appropriate.

Example

struct eqstr {

bool operator()(const char* s1, const char* s2) const {

return strcmp(s1, s2) == 0;

}

};

int main() {

hash_map, eqstr> months;

months["january"] = 31;

months["february"] = 28;

months["march"] = 31;

months["april"] = 30;

months["may"] = 31;

months["june"] = 30;

months["july"] = 31;

months["august"] = 31;

months["september"] = 30;

months["october"] = 31;

months["november"] = 30;

months["december"] = 31;

cout << "september –> " << months["september"] << endl;

cout << "april –> " << months["april"] << endl;

cout << "june –> " << months["june"] << endl;

cout << "november –> " << months["november"] << endl;

}

Definition

Defined in the header hash_map, and in the backward-compatibility header hash_map.h. This class is an SGI extension; it is not part of the C++ standard.

Template parameters
Parameter Description Default
Key The hash_map's key type. This is also defined as hash_map::key_type .
Data The hash_map's data type. This is also defined as hash_map::data_type .
HashFcn The hash function used by the hash_map. This is also defined as hash_map::hasher . hash
EqualKey The hash_map key equality function: a binary predicate that determines whether two keys are equal. This is also defined as hash_map::key_equal . equal_to
Alloc The hash_map 's allocator, used for all internal memory management. alloc
Model of

Unique Hashed Associative Container, Pair Associative Container

Type requirements

• Key is Assignable.

• EqualKey is a Binary Predicate whose argument type is Key .

• EqualKey is an equivalence relation.

• Alloc is an Allocator.

Public base classes

None.

Members
Member Where defined Description
key_type Associative Container The hash_map 's key type, Key .
data_type Pair Associative Container The type of object associated with the keys.
value_type Pair Associative Container The type of object, pair , stored in the hash_map.
hasher Hashed Associative Container The hash_map 's hash function.
key_equal Hashed Associative Container Function object that compares keys for equality.
pointer Container Pointer to T .
reference Container Reference to T
const_reference Container Const reference to T
size_type Container An unsigned integral type.
difference_type Container A signed integral type.
iterator Container Iterator used to iterate through a hash_map . [1]
const_iterator Container Const iterator used to iterate through a hash_map .
iterator begin() Container Returns an iterator pointing to the beginning of the hash_map .
iterator end() Container Returns an iterator pointing to the end of the hash_map .
const_iterator begin() const Container Returns an const_iterator pointing to the beginning of the hash_map .
const_iterator end() const Container Returns an const_iterator pointing to the end of the hash_map .
size_type size() const Container Returns the size of the hash_map .
size_type max_size() const Container Returns the largest possible size of the hash_map .
bool empty() const Container true if the hash_map 's size is 0 .
size_type bucket_count() const Hashed Associative Container Returns the number of buckets used by the hash_map .
void resize(size_type n) Hashed Associative Container Increases the bucket count to at least n .
hasher hash_funct() const Hashed Associative Container Returns the hasher object used by the hash_map .
key_equal key_eq() const Hashed Associative Container Returns the key_equal object used by the hash_map .
hash_map() Container Creates an empty hash_map .
hash_map(size_type n) Hashed Associative Container Creates an empty hash_map with at least n buckets.
hash_map(size_type n, const hasher& h) Hashed Associative Container Creates an empty hash_map with at least n buckets, using h as the hash function.
hash_map(size_type n, const hasher& h, const key_equal& k) Hashed Associative Container Creates an empty hash_map with at least n buckets, using h as the hash function and k as the key equal function.
template hash_map(InputIterator f, InputIterator l)[2] Unique Hashed Associative Container Creates a hash_map with a copy of a range.
template hash_map(InputIterator f, InputIterator l, size_type n)[2] Unique Hashed Associative Container Creates a hash_map with a copy of a range and a bucket count of at least n .
template hash_map(InputIterator f, InputIterator l, size_type n, const hasher& h)[2] Unique Hashed Associative Container Creates a hash_map with a copy of a range and a bucket count of at least n , using h as the hash function.
template hash_map(InputIterator f, InputIterator l, size_type n, const hasher& h, const key_equal& k)[2] Unique Hashed Associative Container Creates a hash_map with a copy of a range and a bucket count of at least n , using h as the hash function and k as the key equal function.
hash_map(const hash_map&) Container The copy constructor.
hash_map& operator=(const hash_map&) Container The assignment operator
void swap(hash_map&) Container Swaps the contents of two hash_maps.
pair insert(const value_type& x) Unique Associative Container Inserts x into the hash_map .
template void insert(InputIterator f, InputIterator l)[2] Unique Associative Container Inserts a range into the hash_map .
void erase(iterator pos) Associative Container Erases the element pointed to by pos .
size_type erase(const key_type& k) Associative Container Erases the element whose key is k .
void erase(iterator first, iterator last) Associative Container Erases all elements in a range.
void clear() Associative Container Erases all of the elements.
const_iterator find(const key_type& k) const Associative Container Finds an element whose key is k .
iterator find(const key_type& k) Associative Container Finds an element whose key is k .
size_type count(const key_type& k) const Unique Associative Container Counts the number of elements whose key is k .
pair equal_range(const key_type& k) const Associative Container Finds a range containing all elements whose key is k .
pair equal_range(const key_type& k) Associative Container Finds a range containing all elements whose key is k .
data_type& operator[](const key_type& k)[3] hash_map See below.
bool operator==(const hash_map&, const hash_map&) Hashed Associative Container Tests two hash_maps for equality. This is a global function, not a member function.
New members

These members are not defined in the Unique Hashed Associative Container and Pair Associative Container requirements, but are specific to hash_map .

Читать дальше
Тёмная тема
Сбросить

Интервал:

Закладка:

Сделать

Похожие книги на «Standard Template Library Programmer's Guide»

Представляем Вашему вниманию похожие книги на «Standard Template Library Programmer's Guide» списком для выбора. Мы отобрали схожую по названию и смыслу литературу в надежде предоставить читателям больше вариантов отыскать новые, интересные, ещё непрочитанные произведения.


Отзывы о книге «Standard Template Library Programmer's Guide»

Обсуждение, отзывы о книге «Standard Template Library Programmer's Guide» и просто собственные мнения читателей. Оставьте ваши комментарии, напишите, что Вы думаете о произведении, его смысле или главных героях. Укажите что конкретно понравилось, а что нет, и почему Вы так считаете.

x