]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/container/detail/next_capacity.hpp
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / boost / boost / container / detail / next_capacity.hpp
1 //////////////////////////////////////////////////////////////////////////////
2 //
3 // (C) Copyright Ion Gaztanaga 2014-2015. Distributed under the Boost
4 // Software License, Version 1.0. (See accompanying file
5 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 //
7 // See http://www.boost.org/libs/container for documentation.
8 //
9 //////////////////////////////////////////////////////////////////////////////
10 #ifndef BOOST_CONTAINER_DETAIL_NEXT_CAPACITY_HPP
11 #define BOOST_CONTAINER_DETAIL_NEXT_CAPACITY_HPP
12
13 #ifndef BOOST_CONFIG_HPP
14 # include <boost/config.hpp>
15 #endif
16
17 #if defined(BOOST_HAS_PRAGMA_ONCE)
18 # pragma once
19 #endif
20
21 #include <boost/container/detail/config_begin.hpp>
22 #include <boost/container/detail/workaround.hpp>
23
24 // container
25 #include <boost/container/throw_exception.hpp>
26 // container/detail
27 #include <boost/container/detail/min_max.hpp>
28
29 #include <boost/static_assert.hpp>
30
31 namespace boost {
32 namespace container {
33 namespace dtl {
34
35 template<unsigned Minimum, unsigned Numerator, unsigned Denominator>
36 struct grow_factor_ratio
37 {
38 BOOST_STATIC_ASSERT(Numerator > Denominator);
39 BOOST_STATIC_ASSERT(Numerator < 100);
40 BOOST_STATIC_ASSERT(Denominator < 100);
41 BOOST_STATIC_ASSERT(Denominator == 1 || (0 != Numerator % Denominator));
42
43 template<class SizeType>
44 SizeType operator()(const SizeType cur_cap, const SizeType add_min_cap, const SizeType max_cap) const
45 {
46 const SizeType overflow_limit = ((SizeType)-1) / Numerator;
47
48 SizeType new_cap = 0;
49
50 if(cur_cap <= overflow_limit){
51 new_cap = SizeType(cur_cap * Numerator / Denominator);
52 }
53 else if(Denominator == 1 || (SizeType(new_cap = cur_cap) / Denominator) > overflow_limit){
54 new_cap = (SizeType)-1;
55 }
56 else{
57 new_cap = SizeType(new_cap*Numerator);
58 }
59 return max_value<SizeType>
60 ( SizeType(Minimum)
61 , max_value<SizeType>
62 ( SizeType(cur_cap+add_min_cap)
63 , min_value<SizeType>(max_cap, new_cap))
64 );
65 }
66 };
67
68 } //namespace dtl {
69
70 struct growth_factor_50
71 : dtl::grow_factor_ratio<0, 3, 2>
72 {};
73
74 struct growth_factor_60
75 : dtl::grow_factor_ratio<0, 8, 5>
76 {};
77
78 struct growth_factor_100
79 : dtl::grow_factor_ratio<0, 2, 1>
80 {};
81
82 template<class SizeType>
83 BOOST_CONTAINER_FORCEINLINE void clamp_by_stored_size_type(SizeType &, SizeType)
84 {}
85
86 template<class SizeType, class SomeStoredSizeType>
87 BOOST_CONTAINER_FORCEINLINE void clamp_by_stored_size_type(SizeType &s, SomeStoredSizeType)
88 {
89 if (s >= SomeStoredSizeType(-1) )
90 s = SomeStoredSizeType(-1);
91 }
92
93 } //namespace container {
94 } //namespace boost {
95
96 #include <boost/container/detail/config_end.hpp>
97
98 #endif //#ifndef BOOST_CONTAINER_DETAIL_NEXT_CAPACITY_HPP