STL Container Concepts

zhaozj2021-02-16  59

Container:

Description: Store various elements, each Container must have the corresponding Iterator, and the order of storage of the elements is uncertain.

Perhaps every time Iterator traversed Container, each access order may be different, and Container

It cannot be guaranteed that there is more than one Iterator that is valid at the same moment. Container has the elements you have included (if you mean

Needle Container, then just the ownership of the pointer, not the object pointing to the pointer). Container

Depending on whether you can dynamically divide the container size is divided into Fixed Sized Container and Variable Sized Con

TAINER.

Definition: The size of the Container refers to the number of elements that contains, is not negative.

Container's Area refers to the number of bytes occupied by the Container. Is equal to all the space posted by all elements

Container attached spatial consumption.

Expression semantics:

1, x, y represents the element in the Container.

The expression includes assignment x = y, and it is determined that the X == Y, X! = Y, the relatively large small x y, x> = y.

2, A, b represent the Container object. Expressions include constructor, quaternative functions, copy constructor, assignment

Octa, begin (), end (), size (), max_size (), EMPTY (), SWAP ().

B = a, copy the container A to B, therefore, the size of A and B is consistent.

A.BEGIN (), returning an Iterator with the first element of the container

a.End (), returns an item of Iterator to the last element of the container

A.SIZE (), return to the number of elements of container A

A.MAX_SIZE (), return the maximum number of elements that may be achieved in container A, in Fixed Size Contain

ER Size () == max_size ()

A.empty (), determined if the container A is empty

Forward Container:

Description: Forward Container first is Container, and the Container difference is that his element storage order is

Be sure, his Iterator must be Forward Iterator because he is a Forward Container, i

The order of each time when Teerator is traversed.

Expression semantics: a, b represents the Container object. First he contains the expression of Container, and also: a <

B, a == b.

a

A == B: A, B is the same size, and the elements corresponding to each position are equal

Reversible Container:

Description: Reversible Container first is a ForwardContainer, but its item is two-way

Bidirectional Iterators. Therefore, it also supports the reverse direction cycle. The Iterator he is also required

It is enhanced, it must be Bidirectional Iterators, not just forward itrators.

Expression semantics: a, b represents the Container object. In addition to the operation of ForwardContainer, there is RBEG

in (), rend ().

Rbegin: Returns a reverse direction, he points to the last element of the Container.

Rend: Returns an anti-direction cycle, he points to the first element of the Container.

Random Access Container Description: First, Random Access Container is a Reversible Container, which provides access to any one

Method of elements. The Iterator he asked is also strengthened, and it must be Random Access Iterator.

Just require the Bidirectional Iterators.

Expression semantics: a, b represents the Container object. In addition to the operation of Reversible Container, there is A

[N]: Where 0

SEQUENCE:

Description: Sequence first is a forward container that can dynamically change the size, and also support insertion and deletion.

Element operation.

Expression semantics: x sequence type container

A, B container X object

Type of elements contained in T container X

T data type T object

P, Q container A, B Iterator object

Number of elements of N containers a, b

In addition to the Forward Container operation, X (N, T), X A (N, T), X (N), X A (N, T), X (I, J),

X A (i, j), a.front (), A. Isert (p, t) a.insert (p, n, t), a.insert (p, i, j), a.rase

(p), a.rase (p, q), a.clear (), A.Resize (n, t), a.resize (n)

X (n, t): Create a sequence, size () == n, and each element is a copy of T

X a (n, t): Create a sequence object a, a.size () == n, and each element is a copy of T

X (n): Create a sequence, size () == n, and each element is T (), the default constructor

X a (n, t): Create a sequence object a, a.size () == n, and each element is T ()

X (i, j): Create a sequence object, a.size () == size (i-j), and the element is the element of the element between I, J

Shell, I, J is the range of a T type element

X a (i, j): Create a sequence object a, a.size () == size (i-j), and the element is element between I, J

copy

A.Nsert (p, t): Insert an element T at p, a.size () plus 1, and the position of the elements does not change

A. INSERT (p, n, t): Insert N elements T at P, a.size () plus N, and the position of the elements is unchanged

A.Nsert (p, i, j): Insert an element in P, a.size () plus (J-I), and the position of the elements does not change

a.rase (p): Delete the element pointing to the P pointing, returns an item, pointing to the back element of the element pointed to the P pointing

A.rase (p, q): Delete the elements between P, Q, return an item, pointing to the back element of the element to point to the elements

a.clear (): It is equivalent to a.rase (a.begin, a.end)

A.Resize (n, t): Make Size () = n of Sequence A, if the original size ()> N is equivalent to deleting extra elements

If the original size ()

A.Resize (N): equivalent to A.Resize (n, t ())

Front Insertion Sequence

Description: First he is definitely a sequence, and he also supports inserted before the first element of Sequence,

Or get the first element, or remove the first element expression: In addition to the expression of Sequence, he also includes: front (), push_front (), pop_f

Ront ().

A.front (): Get the first element of A, equivalent to * (A.BEGIN ())

A.PUSH_FRONT (T): T, equivalent to A.Nsert (A.Begin (), T) before the first element of A.

A.POP_FRONT (): Delete the first element, equivalent to a.rase (A.BEGIN ())

Back Insertion Sequence

Description: First of all, he is definitely a sequence, and he also supports insertion after the last element of Sequence.

Or get the first element, or delete the last element

Expression: In addition to Sequence's expression, he also includes: back (), push_back (), pop_bac

k ().

A.BACK (): Gets the last element of A, equivalent to * (a.end ())

A.Push_Back (T): Before the last element of A, T, equivalent to A.Nsert (a.end (), t)

A.POP_BACK (): Delete the last element, equivalent to a.rase (a.end ())

Associative Container

Description: He first is a Variable Sized Container, supports insertion of elements based on Key

Delete operation (different from Sequence, he could not specify where the inserted and deleted position). In Associative Cont

In Ainer, each element has a corresponding key: in Simple Associative, Key is the element

Has itself, and in other Associative Container, Key is a special part of the element itself. due to

The element is stored according to their key, so it is required to be permanent. In Simple A

SSOCIATIVE is that the elements are not variable; in Pair Associative Containers, element books

The body is variable, but the key as part of the element is not variable. The polarity of the key corresponding to the element means AS

The element of the Sociative Container is not assignable (Assignable.). And not assigning a value

Important consequences: Associative Containers has no variable cycles (Mutable Iterator) because Mutab

The Le Iterator requires assignment. That is: If i is a Mutable Iterator, T is the container pointing to it.

One element, then * i = T is legally effective. In Simple Associative Containers, the element is never

Change, while other Associative Containers, the value of the element can be changed via Iterator. For example, P

Air Associative Containers, the cyclic sub-i is the MAP type, and the value of the element can be changed by (* i). Second = 3. Unique Associative Containers, all elements

The Key value is unique, and in the Unique Associative Containers, multiple elements are allowed to have the same Key value.

.

Expression semantics:

a.rase (k): Delete elements of all KEY values ​​to K. Returns only the number of elements that are deleted, the size of the element that reduces the element of the Key value is a.count (k)

a.rase (p): Delete the elements referred to by cyclic sub-P, size reduction 1

a.rase (p, q): Delete elements between cycles p, q, size reduces the number of elements of P, Q rooms]

a.clear (): Empty container, equivalent to a.rase (A.Begin (), a.end ())

A.Find (k): Find the element of the KEY value K, if there is a result, return a loop pointing to the element, otherwise returns a.

End ()

A.Count (k): Number of elements that return the key value of K

a.equal_range (k): Returns a pair of cycles, the first cycle point to the first element of the Key value K, the second

The element pointing to the last element of the Key value

Simple Associative Container

Description: His key is the element itself, each element itself is because it is Key, so the elements are unstrenomed.

Pair Associative Container

Description: His element is pair , pay attention: the first PAIR here

The parameter is const, because Key is not variable, so the element cannot be pair .

Sorted Associative Container

Description: His key value can be sorted, if the two keys cannot be larger, then they think is equal

. If the key value is not related, then "Abcde" and "abcde" two keys are considered equal

expression:

A.Lower_Bound (k): Returns the last element of the Key value of not less than K, if there are multiple and K the same key, then return

Back to the first element, if there is no element that satisfies the required elements, then return end ()

A.upper_bound (k): Returns the first element greater than k, if there are multiple and K the same key, then return and

The last element of the last element of the same key element, if there is no element that satisfies the required elements, return end ()

a.Equal_range (k): Returns a pair of cycles, the first is A.Lower_Bound (k), the second is a.upper_bou

Nd (k)

Hashed Associative Container

Description: Hashed Associative Container is a Container with Hash Table. His elements of the elements

The way is not necessarily meaningful, even, his elements are disorderless. Hashed Associative Container

The complexity of the operation is that the size of the container is widely proportional.

Hash function definition: One yuan parameter function, input to a key value, returns to the key corresponding to the location of the key in the HASH.

Each element is incorporated into the Hash function to determine the storage location of the element. Hash function

The return value can only be determined by the parameters brought by the function. The number of elements that the Hash table may be stored in addition to the length of the HASH table

The result is the load factor. Hash function is coming for Hashed Associative Container

It is important to say that if the hash function is not found, there will be conflicts (here the conflict refers to two different elements being mapped to

The same location). The worst is that all elements are mapped to the same location, and the complexity of the entire function will increase, becoming the Size of the container into linear proportional relationship.

Expression semantics:

X a type what is a model of haShed Associative Container

A Object of Type X

T Object of Type x :: value_type

K Object of Type x :: key_type

P, Q Object of Type x :: itemarator

N Object of Type x :: size_type

H Object of Type x :: Hasher

C Object of Type x :: Key_equal

X (), x A: Default constructor, the size of the container is 0, the length of the container has an unrecorded value, the container is used

Hasher () is his hash function, and key_equal () is a key value comparison function of its element.

X (n) x a (n): Size = 0 of the container, but the length of the container is n, using Hasher () as his hash function,

KEY_EQUAL () compares the key value of its element.

X (n, h) x a (n, h): SIZE = 0 of the container, but the length of the container is N, using H () for his hash function,

KEY_EQUAL () compares the key value of its element.

X (n, h, k) x a (n, h, k): the size = 0 of the container, but the length of the container is N, using H () for his hash

The function, while k () is a comparison function of the Key value of its element.

A.hash_funct (): Returns the hash function of the container

a.rase (k): Delete elements in the container to KEY value, reduced A.Count (k), return to delete

Number of elements

A.Find (k): Find the element of the Key value of K, if there is a result, return to the cycle of the element, otherwise returns A

()

A.Equal_Range (k): Returns a range, from the element of the first key to K to the element of the last Key, such as

If you don't find it, return to an empty range

A.Bucket_count (): Returns the length of the container

A.Resize (N): Increase the length of the container, at least n, if the original length is greater than n, then don't move. Note: Change

The size of the container does not make the cycle of the container fail, but may affect the success between the various cycles.

sequence. Originally after the previous cycle is changed after the length of the container changes.

UNIQUE Associative Container

Description: The respective Key values ​​of all elements are different, so the return value of A. Count (k) is 0 or 1

A.Nsert (t) also has certain specificities here: if T is already in Unique Associative Container

Existed, then it is not inserted. If there is no existence, it is inserted. The return value is pair <>, the first element is a pointing T

The cycler, the second is a Boolean value that is inserted.

Multiple Associative Container

Description: Cancel the container for UNIQUE Associative Container

Unique Sorted Associative Container

Description: Need to meet Sorted Associative Container and UNIQUE Associative Container

container

Multiple Sorted Associative Container Description: Need to meet Sorted Associative Container and Multiple Associative Container

container

Unique Hashed Associative Container

Description: Need to meet the Hashed Associative Container, Unique Associative Container

Be aware of

Multiple Hashed Associative Container

Description: Need to meet Hashed Associative Container, Multiple Associative Container

container

转载请注明原文地址:https://www.9cbs.com/read-24325.html

New Post(0)