SGI-STL abbreviated (f) - the sequence container (list)

stl_list.h: 
    List: a can, it can be done from any location fast insert and delete elements in the doubly linked list in constant time, but access to data, it is necessary to find other linear time; 
    
    _List_node_base: struct list node base class, contains only _M_next , _M_prev members, which are a pointer to the next node base class, a node on a current; 
    
    _List_node: node template class inherits _List_node_base, just adds a data member _M_data, save the actual node to node data; 
    
    _List_iterator_base: list iterator base class, those iterator type bidirectional_iterator_tag; 
        internal members _M_node current iteration is pointing to the node; 
        _List_node_base constructor parameter types _List_node_base, to initialize the value _M_node; 
        _M_incr: adjusting the current iterator for the next node referring to one of the nodes; 
        _M_decr: adjusting the current node iterator for the meaning of one of the nodes; the 
        addition overloaded operator ==, operator =! comparison operators, which in fact is a direct _M_node member comparison iterator (address) 
        
    _List_iterator: list iterator template class, inherited from _List_iterator_base; 
        the template class heavy declares more conventional type; multiple overloaded versions of the constructor to initialize the iterator;
        Further understanding of overload reference, fetch pointer operator (iterator returns the current _M_node (required to force the conversion of the subclass type _List_node) data member of _M_data, because _List_node _List_node_base type compatible 
        memory layout, it can be forced type C conversion); 
        overloaded operator ++, operator ++ ( int ), operator -, operator - ( int ): each call the corresponding base class members _M_incr, _M_decr iterators implement the front and backward iteration operation; 
        
    _List_alloc_base: a template base class distribution list, respectively, the data type parameter template T, dispenser type _Allocator, and a bool identification _IsStatic (standard for distinguishing whether the dispenser or dispenser SGI); 
    data member: 
        _M_node: the current list of the first node pointer list, which is also used as the first iterator, is determined according to the tail (Sentinel); 
    member function: 
        constructors: allocator_type type dispenser to initialize the reference _Node_allocator; 
        get_allocator: obtaining allocator object _Node_allocator;  
        _M_get_node: size distribution through the dispenser target _Node_allocator a large memory data element type Space
        _M_put_node: releases the specified data element type pointer address a memory size of the type of data element sizes Inter;
    It also offers specialized version _List_alloc_base <_TP, _Allocator, to true > , the allocation is no longer within the template base class objects using a dispenser, but directly using the static member functions are allocated simple_alloc management; 
    
    _List_base: template list base class inherits in _List_alloc_base, template parameter _IsStatic its base class is initialized by _S_instanceless _Alloc_traits extraction obtained, which is a doubly linked list node lead can be 
    more easily implemented and not much wasted space on the size of a data type node ; 
        constructors: a dispenser base class object initialization type dispenser, in addition to call _M_get_node allocated data size of a space is initialized to _M_node, the adjustment of the inner _M_node and a next node pointer point to themselves; 
        destructor function: the destruction of the entire list call clear clear buffer and call release _M_put_node list head pointer buffer; 
        clear; _M_node traverse all list node points to the rear, each node _Destroy call and calling the destructor destroys the node _M_put_node buffer, After adjustment within _M_node And a pointer to point to the next node in its own; 
    
    list: sequence list container template class list, inherits protection _List_base, the template parameters dispenser used as a default macro __STL_DEFAULT_ALLOCATOR dispenser; may be set by adjusting the macro, and therefore may be used the allocator <T>Or the alloc 
        (malloc_alloc (i.e. __malloc_alloc_template < 0 >) or __default_alloc_template <__ NODE_ALLOCATOR_THREADS, 0 > ) as the default allocator; 
        addition of a conventional type and iteratively re-declared type, and constant iterator type flip iterators; 
        get_allocator: function overriding the base class, the base class of the object acquired dispenser; 
        constructor: providing a plurality of heavy-duty version, comprising providing distribution allocator_type parameters, an initialization element number n and a given value or initialization value used to initialize the default value, providing input iterator range (call insert in the end of the container 
        is inserted into the input iterator range data or inserted data n elements); 
        _M_create_node: Create and initialize a buffer node node to a specific value, the internal element type first call request size _M_get_node buffer, after which the current node is configured to call _Construct initialization value; 
        the begin: first acquiring element node iterator packaging container (return _M_node -> _M_next packaging iterator object); 
        End: after obtaining the end node packaging container element iterator (return packet _M_node Installed iterator object); 
        rbegin, rend: initialization means configured to begin and end and returns inverting iterator object;
        empty: determining whether the container is empty (return _M_node  -> _ == M_next_M_node i.e., first determines whether the current list pointer points to the next node is itself); 
        size: obtaining a container element capacity (internal call number calculated distance traversed container element, due to the need to traverse, so efficiency is relatively low, constant time to complete, so for general priority to empty rather than size to determine whether the container is empty, 
        but also depends achieve different compilers, some compilers store a variable size sized recording the current container data the number of elements, or empty at this time are the same size and is very efficient when the acquired number of elements); 
        MAX_SIZE: obtaining the maximum capacity of the list, returns size_t (with the deque - . 1 ), different compilers different implementations, some of return size_t (- . 1 ) / the sizeof (T); 
        Front, Back: obtaining a container head element and the tail element ( * the begin (), * (End () - . 1 ), if the container is empty occurs abnormal operation); 
        the swap: swap two container contents, in fact, simply exchange _M_node value (i.e., a pointer and a next node on which the corresponding value); 
        INSERT: providing a variety of heavy-duty version, the package Inserting a value before the specified position, and a value of n is inserted into the input iterator value range before the specified position before the specified position; 
            insert a value before the specified position versions:
                Call _M_create_node create and initialize the new node value, adjusting the mutual relationship between the specified point and the insertion node and the previous node which new nodes to form a doubly linked list, specific operation is: 
                    1 . The next new node to the first node of the insertion point node;
                     2 would be a node pointing to a node insertion point node of the new node;
                     3 . the next one node of the insertion node pointed to by a node pointing to the new node;
                     4 . the insertion node one node to the new node; 
                in fact, the above steps are just one implementation, there are other possible implementations sequence; 
            Inserts n val value before the specified position version: 
                internal call _M_fill_insert filling insert (in fact _M_fill_insert call insert inside the loop is achieved before the specified insertion position iterator); 
            inserted into the input iterator before the specified position value range version: 
                internal call function dispatch _M_insert_dispatch template inserted; when it is a data element type is called _M_fill_insert _Is_integer filling insert otherwise traverse input iterator and calls insert is inserted at a prescribed position; 
        push_fron t, push_back: each container is inserted into header and trailer data elements (called internally are inserted before the first insert portion and the tail portion at iterator) in;
        erase: overloaded version, removes the specified location iterator data elements and input data elements range iterator; the former needs only to fall in the relationship to be removed before the iterator node and the node position, and thereafter call _Destroy destruction corresponding node element iterator, 
        and calls _M_put_node destroy the node buffer; the latter version only need to call the former version can erase in the loop iterator range, adjust the relationship is removed as follows: 
            1 to obtain the removal iterations. node of a node and the next node (there are two temporary save the two pointer variables node position);
             2 . point to the next node of the acquired node a next node is obtained;
             3 . the points to the next node of the obtained node is a node obtained; 
            in fact no temporary pointer 1, i.e. can be adjusted directly in accordance with the following steps; 
            a direct adjustment removed iterator node on a node points to a node in the next node removes iterator node;
             2 . on removal adjustment iterator node to the next node in a Removing a node point iterator node; 
        Clear: Empty container elements (call the base class Clear);     
        a resize: providing two versions overloaded, reset the size of space of the container, to obtain the size of the internal reset for loop between the container and the minimum size of the original, if the value of the same size is called the reset erase subsequently removing the remaining elements of the container; otherwise call insert 
        the remaining value is less than the reset iterator tail insert size (we use for loop to get the value can be obtained because the need for direct call when earse iterator with the current position, if With the size of the acquired size have again moved so that the position of the iterator is too time-consuming as a whole); 
        pop_front, pop_back: a container header removing elements, tail Section element, which are internal to the first call earse removal value iterator aft position; 
        ASSIGN: distribution function, overloaded version, respectively, providing a distribution of n values of the initialization container and dispensing val input iterator range initialization container; the former call _M_fill_assign filling distribution; the latter is called _M_assign_dispatch template functions assigned; 
        _M_fill_assign: If the policy for which data is assigned in the original container for loop copy data, the data call insert inserted in the back fill the remaining number if the container is less than the specified size, or the call earse remove redundant data elements of the original container; 
        _M_assign_dispatch: template functions assigned assignment, call the appropriate version of the data element type, in the case _Is_integer _M_fill_assign type is called to fill otherwise handled as if the original data through a container for copy data assignment cycle, 
        is called to fill the remaining data elements inserted into the insert iterator range behind if the container is less than the specified size, or the call earse remove redundant data element of the original container iterator range, processing strategies similar _M_fill_assign ; 
        splice: splicing function, removal source And an element inserted into the target vessel before the iterator position specified; provide three overloaded versions; 
            providing the target container insert iterator position and the source container version: internal call to transfer the source container element spliced to specify a template container before insertion position; and Also provided are two versions of a source inserted iterator or iterator range, are converted to the call transfer 
            implementation, the two versions of the second parameter is a container reference, but did not use the invalid parameter; 
        transfer: transfer vessel element, during operation of: disconnect the source container iterator range pointer to the data portion, and then inserted into a broken data iterator before the specified insertion position, and finally improve the data points, as follows: 
            1The next node in a node of a source container last iterator point specified insert iterator node;
             2 would point to the next node in a node of a source container first iterator is a last iteration node;
             3 . Inserting previous node iterator node is a node pointing to first iterator node;
             4 . obtaining a node of the insertion node tmp;
             . 5 . insertion node a node pointing to a node last node;
             . 6 . last node on a node pointing to a node of the first node;
             7 on the first node is a node pointing tmp;. 
        remove: removing the first container with the same value of the specified data element (internal while loop iterator the found under the same call to erase the specified value and the element removed);         
        UNIQUE: removing the adjacent element leaving only near identical copy of the data element, providing two overloaded version; one for the operator = comparison, another provided by an external the comparison function to achieve, no matter which version, while inside are adjacent to loop through the same element is called erase 
        remove found subsequent elements; 
        Merge: merge together Removing the container element and the source container and merge the current sort order (provided that the container element has two ordered) (default is ascending), (by means of Transfer), externally provided furthermore provides an overloaded version of the comparison function; 
        Reverse: reversing the order of list element data, an internal call to implement the actual flip operation __List_base_reverse (node traversal, exchange Point to a node of each node and the next node, after the exchange, the next current node be present on a node, 
        sequentially traversing up back to the original node);
        sort: sorting container element, the default is ascending, but also provides a custom external comparison function implements sorting; Thought policy implemented similar way merge sort, as follows: 
            __carry: as a temporary buffer list, the main role: 1 . the splice was removed from the container a current data; 2 with __counter merging several times were combined and the exchange;. 
            __counter: each buffer list stored in the sorted array combined, which is the number of array 64, each array subscript index values represents the number of elements which can accommodate up to ordering (e.g. __counter [ 3 ] represents the number of data elements can accommodate the 3 power 2, when in fact 63 is 
            shown to be a large list, the process is generally not so large sort of work, in addition to the current PC, 64-bit memory can not hold so much data, there may also lead to __counter bounds exception); 
            moreover adjacent __counter index will merge sort together and form a larger order data thereafter stored at the next index __counter; according to this principle, for each index __counter does not constitute the combined data over Each index in turn calls merge merge 
            until incorporated into a final index value of the Fill - 
            List specializes sort algorithm operating without the sort, because the algorithm is a type of iterator RandomAccessIter, and the list is bidirectional_iterator; __counter list array 1, after the call list and swap exchange container of the present ultimate sorting data;
            End by the whole time complexity of sorting and sorting O (nlogn), different in that it does not take up additional space; 
        furthermore overloading various comparison operators, of which the most important is the operator == comparison of two successively traverse a container element, operator < call lexicographical_compare comparison, traversing the container element; 
    
    if the memory pool list with default version of the dispenser, if the direct use of more than 128 bytes of malloc, free memory management, memory space requirements in general relatively large the dispenser is substantially little significance when employed in the case of direct malloc, free management, internal buffer container 
    structure is different from the vector, deque, which is a pointer to the next node and each node with a point, it is relatively Vector, each element two will be more space size of a pointer, if the node is stored char, int, or a pointer or the like instead of the pointer exceeds the actual storage space occupied by 
    the value of memory usage, so that the container for the list element data classification typically large and occupies under operating conditions need to quickly delete or insert, orderly consolidation, stitching, this Outside it does not support random access;
    

 

Guess you like

Origin www.cnblogs.com/haomiao/p/11647232.html