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», без необходимости каждый раз заново искать на чём Вы остановились. Поставьте закладку, и сможете в любой момент перейти на страницу, на которой закончили чтение.

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

Интервал:

Закладка:

Сделать
Name Expression Return type
Default constructor X() X a;
Constructor with compare X(c) X a(c);
Key comparison a.key_comp() X::key_compare
Value comparison a::value_compare() X::value_compare
Lower bound a.lower_bound(k) iterator if a is mutable, otherwise const_iterator .
Upper bound a.upper_bound(k) iterator if a is mutable, otherwise const_iterator .
Equal range a.equal_range(k) pair if a is mutable, otherwise pair .
Expression semantics
Name Expression Semantics Postcondition
Default constructor X() X a; Creates an empty container, using key_compare() as the comparison object. The size of the container is 0 .
Constructor with compare X(c) X a(c); Creates an empty container, using c as the comparison object. The size of the container is 0 . key_comp() returns a function object that is equivalent to c .
Key comparison a.key_comp() Returns the key comparison object used by a .
Value comparison a::value_compare() Returns the value comparison object used by a . If t1 and t2 are objects of type value_type , and k1 and k2 are the keys associated with them, then a.value_comp()(t1, t2) is equivalent to a.key_comp()(k1, k2) .
Lower bound a.lower_bound(k) Returns an iterator pointing to the first element whose key is not less than k . Returns a.end() if no such element exists. If a contains any elements that have the same key as k , then the return value of lower_bound points to the first such element.
Upper bound a.upper_bound(k) Returns an iterator pointing to the first element whose key is greater than k . Returns a.end() if no such element exists. If a contains any elements that have the same key as k , then the return value of upper_bound points to one past the last such element.
Equal range a.equal_range(k) Returns a pair whose first element is a.lower_bound(k) and whose second element is a.upper_bound(k) .
Complexity guarantees

key_comp() and value_comp() are constant time.

Erase element is constant time.

Erase key is O(log(size()) + count(k)) . [1]

Erase range is O(log(size()) + N) , where N is the length of the range. [1]

Find is logarithmic. [1]

Count is O(log(size()) + count(k)) . [1]

Lower bound, upper bound, and equal range are logarithmic. [1]

Invariants
Definition of value_comp If t1 and t2 are objects of type X::value_type and k1 and k2 are the keys associated with those objects, then a.value_comp() returns a function object such that a.value_comp()(t1, t2) is equivalent to a.key_comp()(k1, k2) .
Ascending order The elements in a Sorted Associative Container are always arranged in ascending order by key. That is, if a is a Sorted Associative Container, then is_sorted(a.begin(), a.end(), a.value_comp()) is always true .
Models

• set

• multiset

• map

• multimap

Notes

[1] This is a much stronger guarantee than the one provided by Associative Container. The guarantees in Associative Container only apply to average complexity; worst case complexity is allowed to be greater. Sorted Associative Container, however, provides an upper limit on worst case complexity.

[2] This definition is consistent with the semantics described in Associative Container. It is a stronger condition, though: if a contains no elements with the key k , then a.equal_range(k) returns an empty range that indicates the position where those elements would be if they did exist. The Associative Container requirements, however, merely state that the return value is an arbitrary empty range.

See also

Associative Container, Hashed Associative Container

Hashed Associative Container

Category: containers

Component type: concept

Description

A Hashed Associative Container is an Associative Container whose implementation is a hash table. [1] The elements of a Hashed Associative Container are not guaranteed to be in any meaningful order; in particular, they are not sorted. The worst case complexity of most operations on Hashed Associative Containers is linear in the size of the container, but the average case complexity is constant time; this means that for applications where values are simply stored and retrieved, and where ordering is unimportant, Hashed Associative Containers are usually much faster than Sorted Associative Containers.

Refinement of

Associative Container

Associated types

The following new types are introduced, in addition to the types defined in the Associative Container requirements.

Hash function X::hasher A type that is a model of Hash Function. X::hasher 's argument type must be X::key_type .
Key equal X::key_equal A Binary Predicate whose argument type is X::key_type . An object of type key_equal returns true if its arguments are the same key, and false otherwise. X::key_equal must be an equivalence relation.
Notation

XA type that is a model of Hashed Associative Container

aObject of type X

tObject of type X::value_type

kObject of type X::key_type

p, qObject of type X::iterator

nObject of type X::size_type

hObject of type X::hasher

cObject of type X::key_equal

Definitions

A hash function for a Hashed Associative Container X is a Unary Function whose argument type is X::key_type and whose return type is size_t . A hash function must be deterministic (that is, it must always return the same value whenever it is called with the same argument), but return values of the hash function should be as uniform as possible: ideally, no two keys will hash to the same value. [2]

Elements in a Hashed Associative Container are organized into buckets . A Hashed Associative Container uses the value of the hash function to determine which bucket an element is assigned to.

The number of elements in a Hashed Associative Container divided by the number of buckets is called the load factor . A Hashed Associative Container with a small load factor is faster than one with a large load factor.

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

Интервал:

Закладка:

Сделать

Похожие книги на «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