⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 storage_sparse.hpp

📁 Boost provides free peer-reviewed portable C++ source libraries. We emphasize libraries that work
💻 HPP
📖 第 1 页 / 共 2 页
字号:
            BOOST_UBLAS_CHECK (size_ <= capacity_, internal_logic ());        }    public:        // Reserving        BOOST_UBLAS_INLINE        void reserve (size_type capacity) {            BOOST_UBLAS_CHECK (size_ <= capacity_, internal_logic ());            // Reduce capacity_ if size_ allows            BOOST_UBLAS_CHECK (capacity >= size_, bad_size ());            pointer data;            if (capacity) {                data = alloc_.allocate (capacity);                std::uninitialized_copy (data_, data_ + size_, data);                std::uninitialized_fill (data + size_, data + capacity, value_type ());            }            else                data = 0;                            if (capacity_) {                std::for_each (data_, data_ + capacity_, static_destroy);                alloc_.deallocate (data_, capacity_);            }            capacity_ = capacity;            data_ = data;            BOOST_UBLAS_CHECK (size_ <= capacity_, internal_logic ());        }        // Random Access Container        BOOST_UBLAS_INLINE        size_type size () const {            return size_;        }        BOOST_UBLAS_INLINE        size_type capacity () const {            return capacity_;        }        BOOST_UBLAS_INLINE        size_type max_size () const {            return 0; //TODO        }               BOOST_UBLAS_INLINE        bool empty () const {            return size_ == 0;        }                    // Element access        BOOST_UBLAS_INLINE        data_reference operator [] (key_type i) {#ifndef BOOST_UBLAS_STRICT_MAP_ARRAY            pointer it = find (i);            if (it == end ())                it = insert (end (), value_type (i, mapped_type (0)));            BOOST_UBLAS_CHECK (it != end (), internal_logic ());            return it->second;#else            return data_reference (*this, i);#endif        }        // Assignment        BOOST_UBLAS_INLINE        map_array &operator = (const map_array &a) {            if (this != &a) {                resize (a.size_);                std::copy (a.data_, a.data_ + a.size_, data_);            }            return *this;        }        BOOST_UBLAS_INLINE        map_array &assign_temporary (map_array &a) {            swap (a);            return *this;        }        // Swapping        BOOST_UBLAS_INLINE        void swap (map_array &a) {            if (this != &a) {                std::swap (capacity_, a.capacity_);                std::swap (data_, a.data_);                std::swap (size_, a.size_);            }        }        BOOST_UBLAS_INLINE        friend void swap (map_array &a1, map_array &a2) {            a1.swap (a2);        }        // Element insertion and deletion                // From Back Insertion Sequence concept        // BOOST_UBLAS_INLINE This function seems to be big. So we do not let the compiler inline it.            iterator push_back (iterator it, const value_type &p) {            if (size () == 0 || (it = end () - 1)->first < p.first) {                resize (size () + 1);                *(it = end () - 1) = p;                return it;            }            external_logic ().raise ();            return it;        }        // Form Unique Associative Container concept        // BOOST_UBLAS_INLINE This function seems to be big. So we do not let the compiler inline it.            std::pair<iterator,bool> insert (const value_type &p) {            iterator it = detail::lower_bound (begin (), end (), p, detail::less_pair<value_type> ());            if (it != end () && it->first == p.first)                return std::make_pair (it, false);            difference_type n = it - begin ();            BOOST_UBLAS_CHECK (size () == 0 || size () == size_type (n), external_logic ());            resize (size () + 1);            it = begin () + n;    // allow for invalidation            std::copy_backward (it, end () - 1, end ());            *it = p;            return std::make_pair (it, true);        }        // Form Sorted Associative Container concept        // BOOST_UBLAS_INLINE This function seems to be big. So we do not let the compiler inline it.            iterator insert (iterator hint, const value_type &p) {            return insert (p).first;        }        // BOOST_UBLAS_INLINE This function seems to be big. So we do not let the compiler inline it.            void erase (iterator it) {            BOOST_UBLAS_CHECK (begin () <= it && it < end (), bad_index ());            std::copy (it + 1, end (), it);            resize (size () - 1);        }        // BOOST_UBLAS_INLINE This function seems to be big. So we do not let the compiler inline it.            void erase (iterator it1, iterator it2) {            BOOST_UBLAS_CHECK (begin () <= it1 && it1 < it2 && it2 <= end (), bad_index ());            std::copy (it2, end (), it1);            resize (size () - (it2 - it1));        }        // BOOST_UBLAS_INLINE This function seems to be big. So we do not let the compiler inline it.            void clear () {            resize (0);        }        // Element lookup        // BOOST_UBLAS_INLINE This function seems to be big. So we do not let the compiler inline it.            const_iterator find (key_type i) const {            const_iterator it (detail::lower_bound (begin (), end (), value_type (i, mapped_type (0)), detail::less_pair<value_type> ()));            if (it == end () || it->first != i)                it = end ();            return it;        }        // BOOST_UBLAS_INLINE This function seems to be big. So we do not let the compiler inline it.            iterator find (key_type i) {            iterator it (detail::lower_bound (begin (), end (), value_type (i, mapped_type (0)), detail::less_pair<value_type> ()));            if (it == end () || it->first != i)                it = end ();            return it;        }        // BOOST_UBLAS_INLINE This function seems to be big. So we do not let the compiler inline it.            const_iterator lower_bound (key_type i) const {            return detail::lower_bound (begin (), end (), value_type (i, mapped_type (0)), detail::less_pair<value_type> ());        }        // BOOST_UBLAS_INLINE This function seems to be big. So we do not let the compiler inline it.            iterator lower_bound (key_type i) {            return detail::lower_bound (begin (), end (), value_type (i, mapped_type (0)), detail::less_pair<value_type> ());        }        BOOST_UBLAS_INLINE        const_iterator begin () const {            return data_;        }        BOOST_UBLAS_INLINE        const_iterator end () const {            return data_ + size_;        }        BOOST_UBLAS_INLINE        iterator begin () {            return data_;        }        BOOST_UBLAS_INLINE        iterator end () {            return data_ + size_;        }        // Reverse iterators        typedef std::reverse_iterator<const_iterator> const_reverse_iterator;        typedef std::reverse_iterator<iterator> reverse_iterator;        BOOST_UBLAS_INLINE        const_reverse_iterator rbegin () const {            return const_reverse_iterator (end ());        }        BOOST_UBLAS_INLINE        const_reverse_iterator rend () const {            return const_reverse_iterator (begin ());        }        BOOST_UBLAS_INLINE        reverse_iterator rbegin () {            return reverse_iterator (end ());        }        BOOST_UBLAS_INLINE        reverse_iterator rend () {            return reverse_iterator (begin ());        }        // Allocator        allocator_type get_allocator () {            return alloc_;        }         // Serialization        template<class Archive>        void serialize(Archive & ar, const unsigned int /* file_version */){            serialization::collection_size_type s (size_);            ar & serialization::make_nvp("size",s);            if (Archive::is_loading::value) {                resize(s);            }            ar & serialization::make_array(data_, s);        }    private:        // Provide destroy as a non member function        BOOST_UBLAS_INLINE        static void static_destroy (reference p) {            (&p) -> ~value_type ();        }        ALLOC alloc_;        size_type capacity_;        pointer data_;        size_type size_;    };    namespace detail {        template<class A, class T>        struct map_traits {            typedef typename A::mapped_type &reference;        };        template<class I, class T, class ALLOC>        struct map_traits<map_array<I, T, ALLOC>, T > {            typedef typename map_array<I, T, ALLOC>::data_reference reference;        };        // reserve helpers for map_array and generic maps        // ISSUE should be in map_traits but want to use on all compilers        template<class M>        BOOST_UBLAS_INLINE        void map_reserve (M &/* m */, typename M::size_type /* capacity */) {        }        template<class I, class T, class ALLOC>        BOOST_UBLAS_INLINE        void map_reserve (map_array<I, T, ALLOC> &m, typename map_array<I, T, ALLOC>::size_type capacity) {            m.reserve (capacity);        }        template<class M>        struct map_capacity_traits {            typedef typename M::size_type type ;            type operator() ( M const& m ) const {               return m.size ();            }        } ;        template<class I, class T, class ALLOC>        struct map_capacity_traits< map_array<I, T, ALLOC> > {            typedef typename map_array<I, T, ALLOC>::size_type type ;            type operator() ( map_array<I, T, ALLOC> const& m ) const {               return m.capacity ();            }        } ;        template<class M>        BOOST_UBLAS_INLINE        typename map_capacity_traits<M>::type map_capacity (M const& m) {            return map_capacity_traits<M>() ( m );        }    }}}}#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -