]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/container/detail/next_capacity.hpp
update sources to ceph Nautilus 14.2.1
[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 // container
22 #include <boost/container/throw_exception.hpp>
23 // container/detail
24 #include <boost/container/detail/min_max.hpp>
25
26 #include <boost/static_assert.hpp>
27
28 namespace boost {
29 namespace container {
30 namespace dtl {
31
32 template<unsigned Minimum, unsigned Numerator, unsigned Denominator>
33 struct grow_factor_ratio
34 {
35 BOOST_STATIC_ASSERT(Numerator > Denominator);
36 BOOST_STATIC_ASSERT(Numerator < 100);
37 BOOST_STATIC_ASSERT(Denominator < 100);
38 BOOST_STATIC_ASSERT(Denominator == 1 || (0 != Numerator % Denominator));
39
40 template<class SizeType>
41 SizeType operator()(const SizeType cur_cap, const SizeType add_min_cap, const SizeType max_cap) const
42 {
43 const SizeType overflow_limit = ((SizeType)-1) / Numerator;
44
45 SizeType new_cap = 0;
46
47 if(cur_cap <= overflow_limit){
48 new_cap = cur_cap * Numerator / Denominator;
49 }
50 else if(Denominator == 1 || (SizeType(new_cap = cur_cap) / Denominator) > overflow_limit){
51 new_cap = (SizeType)-1;
52 }
53 else{
54 new_cap *= Numerator;
55 }
56 return max_value(SizeType(Minimum), max_value(cur_cap+add_min_cap, min_value(max_cap, new_cap)));
57 }
58 };
59
60 } //namespace dtl {
61
62 struct growth_factor_50
63 : dtl::grow_factor_ratio<0, 3, 2>
64 {};
65
66 struct growth_factor_60
67 : dtl::grow_factor_ratio<0, 8, 5>
68 {};
69
70 struct growth_factor_100
71 : dtl::grow_factor_ratio<0, 2, 1>
72 {};
73
74 } //namespace container {
75 } //namespace boost {
76
77 #endif //#ifndef BOOST_CONTAINER_DETAIL_NEXT_CAPACITY_HPP