STL 容器

STL 容器

    by Yazy, 2005-6-15
    STL容器的概念、特性、接口。
General Concepts
Concept

Container

stores other objects(its elements),
has an associated iterator type that can be used to iterate through the Container's elements

Forward
Container

elements are arranged in a definite order,
it's iterators satisfy the forward iterator requirements

Reversible
Container

allows backwords iteration through the container,
with the Bidirectional Iterators

Random Access
Container

provides amortized constant time access to arbitrary elements,
with the Random Access Iterator
Associated
Types
X::value_type
X::iterator
X::const_iterator
X::reference
X::const_reference
X::pointer
X::difference_type
X::size_type
[+Container]
[+Container]
X::reverse_iterator
X::const_reverse_iterator
[+Container]
Valid
Expressions
a.begin()
a.end()
a.size()
a.max_size()
a.empty()
a.swap(b)
[+Container]
a == b
a != b
a < b
a > b
a <= b
a >= b
[+Forward Container]
a.rbegin()
a.rend()
[+Reversible Containe]
a[n]
STL
Models
vector
vector
deque
list
set
map
multiset
multimap
slist(SGI)
hash_set(SGI)
hash_map(SGI)
hash_multiset(SGI)
hash_multimap(SGI)
vector
deque
list
vector
deque



Sequences
Concept

Sequence

variable-sized Container,
elements are arranged in a strict linear order,
supports insertion and removal of elements

Front Insertion
Sequence

insertion at the beginning,
accession at the first element,
in amortized constant time

Back Insertion
Sequence

appending an element to the end,
accession the last element,
in amortized constant time
Associated
Types
[+Forward Container]
[+Sequence]
[+Sequence]
Valid
Expressions
[+Forward Container]
a.front()
a.insert(p, t)
a.insert(p, n, t)
a.erase(p)
a.erase(p,q)
a.clear()
a.resize(n, t)
a.resize(n)
[+Sequence]
a.front()
a.push_front(t)
a.pop_front()
[+Sequence]
a.back()
a.push_back(t)
a.pop_back()
STL
Models
vector
deque
list
slist(SGI)
deque
list
vector
deque
list



Associative Container(1)
Concept

Associative Container

variable-sized Container,
efficient retrieval of elements(values) based on keys,
insertion and removal of elements (but not at a specific position)

Simple
Associative Container

is an Associative Container where elements are their own keys

Pair
Associative Container

associates a key with some other object,
the value type is pair<const key_type, data_type>

Sorted
Associative Container

uses an ordering relation on their keys,
the complexity for most operations is never worse than logarithmic,
elements are always sorted in ascending order by key
Associated
Types
[+Forward Container]
X::key_type
[+Associative Container]
(X::key_type is X::value_type)
[+Associative Container]
X::data_type
[+Reversible Container]
[+Associative Container]
X::key_compare
X::value_compare
Valid
Expressions
[+Forward Container]
a.erase(k):size_type
a.erase(p):void
a.erase(p, q):void
a.clear():void
a.find(k):iterator|const_iterator
a.count(k):size_type
a.equal_range(k):size_type
[+Associative Container]
[+Associative Container]
[+Reversible Container]
[+Associative Container]
a.key_comp():X::key_compare
a.value_compare():X::value_compare
a.lower_bound(k):iterator|const_iterator
a.upper_bound(k):iterator|const_iterator
a.equal_range(k):iterator|const_iterator
STL
Models
set
map
multiset
multimap
hash_set(SGI)
hash_map(SGI)
hash_multiset(SGI)
hash_multimap(SGI)
set
multiset
hash_set(SGI)
hash_multiset(SGI)
map
multimap
hash_map(SGI)
hash_multimap(SGI)
set
map
multiset
multimap



Associative Container(2)
Concept

Unique
Associative Container

each key in the container is unique

Multiple
Associative Container

there may be more than one element with the same key

Unique Sorted
Associative Container

with the property that no two elements in it have the same key
elements are arranged in an order

Multiple Sorted
Associative Container

any number of elements in it may have equivalent keys.
it's also a Sorted Associative Container
Associated
Types
[+Associative Container]
[+Associative Container]
[+Sorted Associative Container]
[+Unique Associative Container]
[+Sorted Associative Container]
[+Multiple Associative Container]
Valid
Expressions
[+Associative Container]
a.insert(t):pair<X::iterator, bool>
a.insert(t, j):void
a.count(k):size_type
[+Associative Container]
a.insert(t):X::iterator
a.insert(i, j):void
[+Sorted Associative Container]
[+Unique Associative Container]
a.insert(p, t):iterator
a.insert(i, j):void
[+Sorted Associative Container]
[+Multiple Associative Container]
a.insert(p, t):iterator
a.insert(i, j):void
STL
Models
set
map
hash_set(SGI)
hash_map(SGI)
multiset
multimap
hash_multiset(SGI)
hash_multimap(SGI)
set
map
multiset
multimap



Associative Container(3)
Concept

Hashed
Associative Container

Unique Hashed
Associative Container

Multiple Hashed
Associative Container

HashFunction

(it's not Container.)
Associated
Types
[+Associative Container]
X::hasher
X::key_equal
[+Hashed Associative Container]
[+Unique Associative Container]
[+Hashed Associative Container]
[+Multiple Associative Container]
[+Unary Function]
(the Result Type must be size_t)
Valid
Expressions




STL
Models
hash_set
hash_map
hash_multiset
hash_multimap
hash_set(SGI)
hash_map(SGI)
hash_multiset(SGI)
hash_multimap(SGI)




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值