annotate DEPENDENCIES/generic/include/boost/container/detail/next_capacity.hpp @ 133:4acb5d8d80b6 tip

Don't fail environmental check if README.md exists (but .txt and no-suffix don't)
author Chris Cannam
date Tue, 30 Jul 2019 12:25:44 +0100
parents f46d142149f5
children
rev   line source
Chris@102 1 //////////////////////////////////////////////////////////////////////////////
Chris@102 2 //
Chris@102 3 // (C) Copyright Ion Gaztanaga 2014-2015. Distributed under the Boost
Chris@102 4 // Software License, Version 1.0. (See accompanying file
Chris@102 5 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
Chris@102 6 //
Chris@102 7 // See http://www.boost.org/libs/container for documentation.
Chris@102 8 //
Chris@102 9 //////////////////////////////////////////////////////////////////////////////
Chris@102 10 #ifndef BOOST_CONTAINER_DETAIL_NEXT_CAPACITY_HPP
Chris@102 11 #define BOOST_CONTAINER_DETAIL_NEXT_CAPACITY_HPP
Chris@102 12
Chris@102 13 #ifndef BOOST_CONFIG_HPP
Chris@102 14 # include <boost/config.hpp>
Chris@102 15 #endif
Chris@102 16
Chris@102 17 #if defined(BOOST_HAS_PRAGMA_ONCE)
Chris@102 18 # pragma once
Chris@102 19 #endif
Chris@102 20
Chris@102 21 // container
Chris@102 22 #include <boost/container/throw_exception.hpp>
Chris@102 23 // container/detail
Chris@102 24 #include <boost/container/detail/min_max.hpp>
Chris@102 25
Chris@102 26 namespace boost {
Chris@102 27 namespace container {
Chris@102 28 namespace container_detail {
Chris@102 29
Chris@102 30 enum NextCapacityOption { NextCapacityDouble, NextCapacity60Percent };
Chris@102 31
Chris@102 32 template<class SizeType, NextCapacityOption Option>
Chris@102 33 struct next_capacity_calculator;
Chris@102 34
Chris@102 35 template<class SizeType>
Chris@102 36 struct next_capacity_calculator<SizeType, NextCapacityDouble>
Chris@102 37 {
Chris@102 38 static SizeType get(const SizeType max_size
Chris@102 39 ,const SizeType capacity
Chris@102 40 ,const SizeType n)
Chris@102 41 {
Chris@102 42 const SizeType remaining = max_size - capacity;
Chris@102 43 if ( remaining < n )
Chris@102 44 boost::container::throw_length_error("get_next_capacity, allocator's max_size reached");
Chris@102 45 const SizeType additional = max_value(n, capacity);
Chris@102 46 return ( remaining < additional ) ? max_size : ( capacity + additional );
Chris@102 47 }
Chris@102 48 };
Chris@102 49
Chris@102 50 template<class SizeType>
Chris@102 51 struct next_capacity_calculator<SizeType, NextCapacity60Percent>
Chris@102 52 {
Chris@102 53 static SizeType get(const SizeType max_size
Chris@102 54 ,const SizeType capacity
Chris@102 55 ,const SizeType n)
Chris@102 56 {
Chris@102 57 const SizeType remaining = max_size - capacity;
Chris@102 58 if ( remaining < n )
Chris@102 59 boost::container::throw_length_error("get_next_capacity, allocator's max_size reached");
Chris@102 60 const SizeType m3 = max_size/3;
Chris@102 61
Chris@102 62 if (capacity < m3)
Chris@102 63 return capacity + max_value(3*(capacity+1)/5, n);
Chris@102 64
Chris@102 65 if (capacity < m3*2)
Chris@102 66 return capacity + max_value((capacity+1)/2, n);
Chris@102 67 return max_size;
Chris@102 68 }
Chris@102 69 };
Chris@102 70
Chris@102 71 } //namespace container_detail {
Chris@102 72 } //namespace container {
Chris@102 73 } //namespace boost {
Chris@102 74
Chris@102 75 #endif //#ifndef BOOST_CONTAINER_DETAIL_NEXT_CAPACITY_HPP