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

stl_bvector.h: 
    bit_vector redeclared Vector < BOOL , alloc> that is used as a memory allocator alloc, which is non-template class, __ BVECTOR i.e. Vector < BOOL , _Alloc> template class, when the weight bit_vector is declared __BVECTOR it may also be a template class; 
    compared to vector, which may be a bit holding element instead of a least one element of a byte; in addition the same basic functions and vector, as well as other additional interface provided; 
    BIT_VECTOR generally considered non-template class; 
    
    _Bit_reference: bits referenced class, as a bit bit_vector iterator class and class reference type; 
    data member, or both unsigned int type pointer type (hereinafter for convenience of analysis, the time being set to four bytes in size): 
        _M_p: point the bit value of the address code stored in the buffer is located; 
        _M_mask: the current bit mask value (in fact the general situation of the rest are always read-only value in binary form of a 1 0), i.e. _M_p 4-bit code bytes pointed to by the corresponding mask value for the position of 1 is the current value of the class represented by the reference bit; 
    member functions: 
        constructor initializes bit code values Address and mask value; 
        operator  bool : bool conversion overloading, the internal implemented to bit code value and mask value according to the result of ANDing the bit;
         operator =: Overloaded assignment operator copies, to achieve a value of an internal parameter to true copy, the code value adjustment bit and the current bit mask code value or values as a result of bits, or bit inverted code for the current value and the mask value seeking after its results; the 
        fact that the mask value corresponding to the position where the value of the code bit buffer modify the value 1 or 0; 
        operator == : overloaded compare equal, bits are referenced objects after comparison into BOOL;
         operator < : only when the class object is the current object is a false and true parameters is ture, or are false; 
        Flip: adjusting the value of the current bit position code value of the code mask value bitwise XOR results 
    a utility function: swap exchanging two bits referenced objects, in addition to the word length __WORD_BIT or 32 or 64, depending on the machine;     
    
    _Bit_iterator_base: template bit groups iterator class inherits random_access_iterator < BOOL , ptrdiff_t> , thus having a random access method of a conventional type and each weighing declaration; 
    data member: 
        _M_p: current buffer pointed to by the iterator data storage node (word size) address; 
        _M_offset: bit code offset, Iterator current code value of the referenced bit position index offset (typically a value in the range 0 to 31 or 0 to 63 , determined according to the machine word size), the difference value is _M_mask, _M_mask = . 1 <<_M_offset; 
    member function:     
        constructor initializes _M_p and _M_offset; 
        _M_bump_up: move the iterator (put on); if the current bit offset _M_offset code word length has reached, is adjusted to point at a word length of _M_p position and sets the offset value to 0, or bit code can be offset from plus 1; 
        _M_bump_down: iterator forward (down): If the current code bit offset is 0, the point to adjust a word _M_p long position and set an offset value of word size - 1 , otherwise the bit from the code offset minus 1 can; 
        _M_incr: rear shifters or forward iterator i bits; and calculate the adjustment _M_p _M_offset; 
        also a plurality of comparison operator overloading, wherein the operator == is when the address bits and the code offset points equal volume equal only; operator < is pointed to when an equal or less than the address pointed to by the address and bit offset code less than, 
        that any one of conditions was true, otherwise to false; 
    operator - : calculating a difference between the two bit code iterators; 
        
    _Bit_iterator: bit iterator class inherits _Bit_iterator_base; internal redeclarations by _Bit_reference reference type, pointer type Type;     
        constructor initializes the base class and _M_p _M_offset; 
        Overload operator understood by reference* Operator, returns the class object reference to the package of _Bit_reference bit (_Bit_reference (_M_p, . 1 << _M_offset)); 
        overloaded increment operator ++, operator ++ ( int ) and decremented operator-- operator - ( int ): internal or call the base class _M_bump_up _M_bump_down implemented; 
        overloaded operator + =, operator - =, operator +, operator - (return iterator object) and operator [] operator (bit reference to returns _Bit_reference Object); internal call the base class _M_incr implemented; 
    
    _Bit_const_iterator: orthotopic iterator class, other implementations with more _Bit_iterator constructor and a copy constructor allows iterator object from another bit configuration; 
    
    _Bvector_alloc_base: dispensing of the base class template BIT_VECTOR ; template parameter type dispenser are _Allocator, and a bool identification _IsStatic (standard for distinguishing whether the dispenser or dispenser SGI); 
    data members:
        _M_data_allocator: allocator object;
        _M_start: Save request first address buffer (equivalent to the first address of the container element) or so-called first iterator; 
        _M_finish: saving the contents of the container during the last address or so-called tail length iterator; 
        _M_end_of_storage: save the application buffer end address; 
    member function: 
        constructors: allocator_type type dispenser to initialize the reference _M_data_allocator; 
        get_allocator: obtaining an object dispenser _M_data_allocator; 
        _M_bit_alloc: Object _M_data_allocator dispensing through the dispenser of size (n- + __WORD_BIT - . 1 ) / __WORD_BIT) a bool type size of memory space, to ensure the word-aligned, i.e., will allocate at least the size of one word; 
        _M_deallocate: _M_start release address pointer and a size _M_end_of_storage - _M_start._M_p memory space; 
    also offers specializations _Bvector_alloc_base < _TP, _Allocator, to true > , the interior of the dispensing base class template objects no longer used dispenser, but directly using the static member functions are allocated simple_alloc management;
    
    _Bvector_base: bit_vector base class template inherits _Bvector_alloc_base, the internal redeclarations base type, the type of dispenser; 
        constructor initializes the base class dispenser; 
        memory buffer space is released _M_deallocate application destructor calls the base class; 
        
    Vector < BOOL , _Alloc>: Inheritance in _Bvector_base <_Alloc>, the template parameter _Alloc externally by a user, can use the built-in dispenser, the Vector typedef < BOOL , the alloc> when bit_vector, the dispenser of this default bit_vector the alloc; 
    moreover the weight and the type declaration referenced by the conventional bits as a reference and a pointer type, iterators and iterative consists _Bit_iterator, _Bit_const_iterator redeclarations, and reverse iterator type packaging; 
        get_allocator: override base class function, Get allocator object base class; 
        constructors: more overloaded version constructor, comprising providing distribution allocator_type parameters, an initialization element number n and a given value or initialization value used to initialize the default values, the iteration providing the data elements device range, 
        (internal call _M_initialize, fill or Call _M_initialize_dispatch distribution _M_initialize_range initialization interval, the application buffer and fill the buffer element); 
        copy constructor: internal call _M_init ialize buffer and call initialization to copy the data copy buffer, the reason may be used as fill or copy is built-bit code bool or not initialization POD type configuration; val Further, when true, the 
        filling value is ~0 , i.e., a binary full. 1; 
        _M_initialize: internal call _M_bit_alloc allocate enough to accommodate word length of n bits code buffer, _M_end_of_storage to save the application end of the buffer, _M_start save buffer and initializing the first internal address offset 0, 
        in addition to holding the tail _M_finish iterator after the valid data; 
        _M_initialize_dispatch: distribution initialization template, calling different implementations based on input iterator type, in the case _Is_integer _M_initialize, fill to the call, or the call _M_initialize_range initialization ; 
        _M_initialize_range: initialize range, for heavy-duty template function; 
            when the input parameter is input iterator or subclass iterator iterators advance end to end, end of the buffer is empty, after traversing the input iterator range sequentially inserted into the call push_back data bit elements;  
            When the input parameter to the subject when the front iterator, the internal distance call to get the input iterator length range, and thereafter call _M_initialize application buffer and call direct copy copy data to the buffer;
        other vector similar interface function similar to note that vector reference returned may take addresses safe to use, and bit_vector returned reference bits referenced objects are not directly take the address, unless it is known memory data layout; 
        to Analysis of the interface and the interface of the newly added special treatment; 
        Flip: code switch position, i.e., the interface may be the bit code buffer if it is 0 to 1, if it is changed to a 0; loop processing for internal use All word units each directly negated achieve bit inversion; 
        capacity: acquiring capacity size container may contain code bits (return a const_iterator (_M_end_of_storage, 0 ) - the begin () difference); 
        ERASE: Removes the specified position overloaded version element or element iterator range, its implementation is relatively simple, direct calls to copy and move copy to adjust the position of _M_finish; 
        _M_insert_aux: Specifies val inserted at the specified location iterator; if the buffer is not inserted and there are extra use, is called a mobile code to copy the data bit copy_backward, directly after insertion position adjustment and assignment _M_fin ish 
        can, or if the current capacity of the container to 0 is called _M_bit_alloc allocated buffer is a word length, or twice the current buffer capacity of the container space, copy after copy of the original call to the new buffer data buffer container, inserted the direct assignment position, 
        and for the rest of the container after the original insertion point of a data call copy copy again, releasing the last call _M_deallocate original container and adjusting the buffer _M_end_of_storage, _M_start, _M_finish position;
        Operation may reallocate memory: insert, push_back, copying assignment, reserve, resize; and earse, pop_back, clear, etc. are not re-allocate memory; 
        
    BIT_VECTOR Vector because similar, essentially the same functions and interfaces part, in addition to its actual distribution memory is to be continuous, but direct access to the fetching pointer or iterator or operator [] prefetch address is not directly used, because in fact returned to a  
    call bit object reference, which contains the internal values of a plurality of bits, in conjunction with the mask value if the user can also get to the correct values of the respective bits, if in addition to understand the memory layout, then you can also get to the other bit value index bits; 
    in addition bit_vector when using alloc memory pool with the default version of the dispenser is indeed often still can reduce memory fragmentation and frequent application, of course, if more than 128 bytes direct use of malloc, free memory management;
    relatively Vector, save more memory usage, because it only needs one element It can be a bit, about 8 times and save the space occupied, in addition by the introduction of a reference position leads to efficient and nearly interface portion; 
    BIT_VECTOR memory layout application format (32-bit word length, for example): 
        31 is  30  29  28 .... 2  . 1  0 | 63 is  62 is  61 is .... 34 is  33 is  32 | 95 .......      
        corresponding to the first address of its digital representation the location in memory, the word length index position at the container position address of the first element is not the container; 
        such as V BIT_VECTOR ( . 4 ); 
        V [ 0 ] =to true ; 
        V [ . 1 ] = to true ; 
        V [ 2 ] = to false ; 
        V [. 3 ] = to true ; 
        binary layout: m_Ptr: 0000000 .... 1011   corresponding to decimal 11; when taken V [ . 3 ] i.e. (* m_ptr) & during 0000 ... 1000 , taking V [ . 1 ] ie (* m_ptr) & 0000 ... 0010 ;
        

 

Guess you like

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