Class bitvector

Synopsis

#include <include/EASTL/bitvector.h>

template <typename Allocator = EASTLAllocatorType, 
		  typename Element   = BitvectorWordType, 
		  typename Container = eastl::vector<Element, Allocator> >
class bitvector

Description

bitvector

Implements an array of bits treated as boolean values. bitvector is similar to vector<bool> but uses bits instead of bytes and allows the user to use other containers such as deque instead of vector. bitvector is different from bitset in that bitset is less flexible but uses less memory and has higher performance.

To consider: Rename the Element template parameter to WordType, for consistency with bitset.

Mentioned in

Methods

bitvector overload
assignbitvector
at overload
back overload
begin overload
capacity
cbegin
cend
clear
crbegin
crend
data overloadWork in progress: template <bool value = true>> iterator find_first(); // Finds the lowest "on" bit
empty
end overload
erase overloadtemplate <typename InputIterator> Not yet implemented
front overload
get_container overloadtemplate <typename Allocator, typename Element, typename Container> template <bool value> typename bitvector<Allocator, Element, Container>::iterator bitvector<Allocator, Element, Container>::find_first() { return begin(); }
insert overload
operator=
operator[] overload
pop_back
push_back overload
rbegin overload
rend overload
reserve
reset_lose_memory
resize overload
set
set_capacity
size
swap
test
validate
validate_iterator

Source

Lines 199-333 in include/EASTL/bitvector.h.

template <typename Allocator = EASTLAllocatorType, 
          typename Element   = BitvectorWordType, 
          typename Container = eastl::vector<Element, Allocator> >
class bitvector
{
public:
    typedef bitvector<Allocator, Element>               this_type;
    typedef bool                                        value_type;
    typedef bitvector_reference<Element>                reference;
    typedef bool                                        const_reference;
    typedef bitvector_iterator<Element>                 iterator;
    typedef bitvector_const_iterator<Element>           const_iterator;
    typedef eastl::reverse_iterator<iterator>           reverse_iterator;
    typedef eastl::reverse_iterator<const_iterator>     const_reverse_iterator;
    typedef Allocator                                   allocator_type;
    typedef Element                                     element_type;
    typedef Container                                   container_type;
    typedef eastl_size_t                                size_type;
    typedef ptrdiff_t                                   difference_type;
    #if defined(_MSC_VER) && (_MSC_VER >= 1400) && (_MSC_VER <= 1600) && !EASTL_STD_CPP_ONLY  // _MSC_VER of 1400 means VS2005, 1600 means VS2010. VS2012 generates errors with usage of enum:size_type.
        enum : size_type {                      // Use Microsoft enum language extension, allowing for smaller debug symbols than using a static const. Users have been affected by this.
            npos     = container_type::npos,
            kMaxSize = container_type::kMaxSize
        };
    #else
        static const size_type npos     = container_type::npos;      /// 'npos' means non-valid position or simply non-position.
        static const size_type kMaxSize = container_type::kMaxSize;  /// -1 is reserved for 'npos'. It also happens to be slightly beneficial that kMaxSize is a value less than -1, as it helps us deal with potential integer wraparound issues.
    #endif
    enum
    {
        kBitCount = 8 * sizeof(Element)
    };
protected:
    container_type mContainer;
    size_type      mFreeBitCount;      // Unused bits in the last word of mContainer.
public:
    bitvector();
    explicit bitvector(const allocator_type& allocator);
    explicit bitvector(size_type n, const allocator_type& allocator = EASTL_BITVECTOR_DEFAULT_ALLOCATOR);
    bitvector(size_type n, value_type value, const allocator_type& allocator = EASTL_BITVECTOR_DEFAULT_ALLOCATOR);
    bitvector(const bitvector& copy);
    template <typename InputIterator>
    bitvector(InputIterator first, InputIterator last);
    bitvector& operator=(const bitvector& x);
    void swap(this_type& x);
    template <typename InputIterator>
    void assign(InputIterator first, InputIterator last);
    iterator       begin() EA_NOEXCEPT;
    const_iterator begin() const EA_NOEXCEPT;
    const_iterator cbegin() const EA_NOEXCEPT;
    iterator       end() EA_NOEXCEPT;
    const_iterator end() const EA_NOEXCEPT;
    const_iterator cend() const EA_NOEXCEPT;
    reverse_iterator       rbegin() EA_NOEXCEPT;
    const_reverse_iterator rbegin() const EA_NOEXCEPT;
    const_reverse_iterator crbegin() const EA_NOEXCEPT;
    reverse_iterator       rend() EA_NOEXCEPT;
    const_reverse_iterator rend() const EA_NOEXCEPT;
    const_reverse_iterator crend() const EA_NOEXCEPT;
    bool      empty() const EA_NOEXCEPT;
    size_type size() const EA_NOEXCEPT;
    size_type capacity() const EA_NOEXCEPT;
    void resize(size_type n, value_type value);
    void resize(size_type n);
    void reserve(size_type n);
    void set_capacity(size_type n = npos);                  // Revises the capacity to the user-specified value. Resizes the container to match the capacity if the requested capacity n is less than the current size. If n == npos then the capacity is reallocated (if necessary) such that capacity == size.
    void push_back();
    void push_back(value_type value);
    void pop_back();
    reference       front();
    const_reference front() const;
    reference       back();
    const_reference back() const;
    bool            test(size_type n, bool defaultValue) const; // Returns true if the bit index is < size() and set. Returns defaultValue if the bit is >= size().
    void            set(size_type n, bool value);               // Resizes the container to accomodate n if necessary. 
    reference       at(size_type n);                    // throws an out_of_range exception if n is invalid.
    const_reference at(size_type n) const;
    reference       operator[](size_type n);            // behavior is undefined if n is invalid.
    const_reference operator[](size_type n) const;
    /*
    Work in progress:
    template <bool value = true> iterator find_first();                                 // Finds the lowest "on" bit.
    template <bool value = true> iterator find_next(const_iterator it);                 // Finds the next lowest "on" bit after it.
    template <bool value = true> iterator find_last();                                  // Finds the index of the last "on" bit, returns size if none are set.
    template <bool value = true> iterator find_prev(const_iterator it);                 // Finds the index of the last "on" bit before last_find, returns size if none are set.
    template <bool value = true> const_iterator find_first() const;                     // Finds the lowest "on" bit.
    template <bool value = true> const_iterator find_next(const_iterator it) const;     // Finds the next lowest "on" bit after it.
    template <bool value = true> const_iterator find_last() const;                      // Finds the index of the last "on" bit, returns size if none are set.
    template <bool value = true> const_iterator find_prev(const_iterator it) const;     // Finds the index of the last "on" bit before last_find, returns size if none are set.
    */
    element_type*       data() EA_NOEXCEPT;
    const element_type* data() const EA_NOEXCEPT;

    iterator insert(const_iterator position, value_type value);
    void     insert(const_iterator position, size_type n, value_type value);
    // template <typename InputIterator> Not yet implemented. See below for disabled definition.
    // void insert(const_iterator position, InputIterator first, InputIterator last);
    iterator erase(const_iterator position);
    iterator erase(const_iterator first, const_iterator last);
    reverse_iterator erase(const_reverse_iterator position);
    reverse_iterator erase(const_reverse_iterator first, const_reverse_iterator last);
    void clear();
    void reset_lose_memory(); // This is a unilateral reset to an initially empty state. No destructors are called, no deallocation occurs.
    container_type&       get_container();
    const container_type& get_container() const;
    bool validate() const;
    int  validate_iterator(const_iterator i) const;
};





Add Discussion as Guest

Log in