Set (C++): Difference between revisions
→Overview of functions: add all functions; cleanup definitions; link to an external reference |
Added observers |
||
Line 43: | Line 43: | ||
**<code>set::[http://en.cppreference.com/enwiki/w/cpp/container/set/lower_bound lower_bound]</code> - Returns an iterator to the first element not less than the given value |
**<code>set::[http://en.cppreference.com/enwiki/w/cpp/container/set/lower_bound lower_bound]</code> - Returns an iterator to the first element not less than the given value |
||
**<code>set::[http://en.cppreference.com/enwiki/w/cpp/container/set/upper_bound upper_bound]</code> - Returns an iterator to the first element greater than a certain value |
**<code>set::[http://en.cppreference.com/enwiki/w/cpp/container/set/upper_bound upper_bound]</code> - Returns an iterator to the first element greater than a certain value |
||
*Observers |
|||
**<code>set::[http://en.cppreference.com/enwiki/w/cpp/container/set/key_comp key_comp]</code> - Constant time function which returns Key comparison function. |
|||
**<code>set::[http://en.cppreference.com/enwiki/w/cpp/container/set/value_comp value_comp]</code> - Constant time function which compares keys and returns Key comparison function. |
|||
<!-- ==Iterators== |
<!-- ==Iterators== |
Revision as of 08:56, 3 October 2011
C++ Standard Library |
---|
Containers |
C standard library |
A set is an associative container data structure that is available as part of the C++ Standard Library (STL), and contains a sorted set of unique objects.[1]
Although the abstract concept of a set does not necessarily imply an ordered collection, the standard library set data structure is always ordered. Its functionality in the STL is provided as a template class, such that any valid C++ object can be used with it. Sets are guaranteed to perform operations of insertion, deletion, and testing whether an element is in it, in logarithmic time - O(log n). As such, they are typically implemented using self-balancing binary search trees and support's bidirectional iterator
Types
There are 2 types of sets available in the C++ STL: std::set
and std::multiset
.
Set
In a set, every element is unique, and insertions of values that are already present in the container are ignored.
Multiset
In a multiset, multiple occurrences of the same value are allowed.
Characteristics
- Unique element value: In a set, no two values are same.
- Element value is itself a key.[clarification needed]
- Elements follow strict weak ordering at all times.
Overview of functions
- Iterators
- Capacity
- Modifiers
- Lookup
set::count
- Returns the number of elements matching specific keyset::find
- Finds an element with specific keyset::equal_range
- Returns a range of elements matching specific keyset::lower_bound
- Returns an iterator to the first element not less than the given valueset::upper_bound
- Returns an iterator to the first element greater than a certain value
- Observers
set::key_comp
- Constant time function which returns Key comparison function.set::value_comp
- Constant time function which compares keys and returns Key comparison function.
References
- ^ ISO/IEC 14882:2011 draft specification, p. 806, § 23.4.6