Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2079558
  • 博文数量: 414
  • 博客积分: 10312
  • 博客等级: 上将
  • 技术积分: 4921
  • 用 户 组: 普通用户
  • 注册时间: 2007-10-31 01:49
文章分类

全部博文(414)

文章存档

2011年(1)

2010年(29)

2009年(82)

2008年(301)

2007年(1)

set

分类: C/C++

2008-12-29 20:59:13

Sets are a kind of associative containers that stores unique elements, and in which the elements themselves are the keys.

Associative containers are containers especially designed to be efficient accessing its elements by their key (unlike sequence containers, which are more efficient accessing elements by their relative or absolute position).

Internally, the elements in a set are always sorted from lower to higher following a specific strict weak ordering criterion set on container construction.

Sets are typically implemented as binary search trees.

Therefore, the main characteristics of set as an associative container are:

  • Unique element values: no two elements in the set can compare equal to each other. For a similar associative container allowing for multiple equivalent elements, see .
  • The element value is the key itself. For a similar associative container where elements are accessed using a key, but map to a value different than this key, see .
  • Elements follow a strict weak ordering at all times. Unordered associative arrays, like unordered_set, are available in implementations following TR1.

This container class supports bidirectional iterators.

In their implementation in the C++ Standard Template Library, set containers take three template parameters:

template < class Key, class Compare = less,
class Allocator = allocator > class set;
Where the template parameters have the following meanings:
  • Key: Key type: type of the elements contained in the container. Each elements in a set is also its key.
  • Compare: Comparison class: A class that takes two arguments of the same type as the container elements and returns a bool. The expression comp(a,b), where comp is an object of this comparison class and a and b are elements of the container, shall return true if a is to be placed at an earlier position than b in a strict weak ordering operation. This can either be a class implementing a function call operator or a pointer to a function (see for an example). This defaults to less, which returns the same as applying the less-than operator (a).
    The set object uses this expression to determine the position of the elements in the container. All elements in a set container are ordered following this rule at all times.
  • Allocator: Type of the allocator object used to define the storage allocation model. By default, the allocator class template for type Key is used, which defines the simplest memory allocation model and is value-independent.
In the reference for the set member functions, these same names (Key, Compare and Allocator) are assumed for the template parameters.

Member functions

Construct set (public member function)
Set destructor (public member function)
Copy container content (public member function)

Iterators:

Return iterator to beginning (public member function)
Return iterator to end (public member function)
Return reverse iterator to reverse beginning (public member function)
Return reverse iterator to reverse end (public member function)

Capacity:

Test whether container is empty (public member function)
Return container size (public member function)
Return maximum size (public member function)

Modifiers:

Insert element (public member function)
Erase elements (public member function)
Swap content (public member function)
Clear content (public member function)

Observers:

Return comparison object (public member function)
Return comparison object (public member function)

Operations:

Get iterator to element (public member function)
Count elements with a specific key (public member function)
Return iterator to lower bound (public member function)
Return iterator to upper bound (public member function)
Get range of equal elements (public member function)

Allocator:

Get allocator (public member function)

Member types

of template , class Allocator=allocator > class set;
member typedefinition
key_typeKey
value_typeKey
key_compareCompare
value_compareCompare
allocator_typeAllocator
referenceAllocator::reference
const_referenceAllocator::const_reference
iteratorBidirectional iterator
const_iteratorConstant bidirectional iterator
size_typeUnsigned integral type (usually same as )
difference_typeSigned integral type (usually same as )
pointerAllocator::pointer
const_pointerAllocator::const_pointer
reverse_iteratorreverse_iterator
const_reverse_iteratorreverse_iterator
阅读(1200) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~