]> git.proxmox.com Git - ceph.git/blame - 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
CommitLineData
7c673cae
FG
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
20effc67
TL
21#include <boost/container/detail/config_begin.hpp>
22#include <boost/container/detail/workaround.hpp>
23
7c673cae
FG
24// container
25#include <boost/container/throw_exception.hpp>
26// container/detail
27#include <boost/container/detail/min_max.hpp>
28
11fdf7f2
TL
29#include <boost/static_assert.hpp>
30
7c673cae
FG
31namespace boost {
32namespace container {
11fdf7f2 33namespace dtl {
7c673cae 34
11fdf7f2
TL
35template<unsigned Minimum, unsigned Numerator, unsigned Denominator>
36struct grow_factor_ratio
7c673cae 37{
11fdf7f2
TL
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));
7c673cae 42
11fdf7f2
TL
43 template<class SizeType>
44 SizeType operator()(const SizeType cur_cap, const SizeType add_min_cap, const SizeType max_cap) const
7c673cae 45 {
11fdf7f2 46 const SizeType overflow_limit = ((SizeType)-1) / Numerator;
7c673cae 47
11fdf7f2 48 SizeType new_cap = 0;
7c673cae 49
11fdf7f2 50 if(cur_cap <= overflow_limit){
1e59de90 51 new_cap = SizeType(cur_cap * Numerator / Denominator);
11fdf7f2
TL
52 }
53 else if(Denominator == 1 || (SizeType(new_cap = cur_cap) / Denominator) > overflow_limit){
54 new_cap = (SizeType)-1;
55 }
56 else{
1e59de90 57 new_cap = SizeType(new_cap*Numerator);
11fdf7f2 58 }
20effc67
TL
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 );
7c673cae
FG
65 }
66};
67
11fdf7f2
TL
68} //namespace dtl {
69
70struct growth_factor_50
71 : dtl::grow_factor_ratio<0, 3, 2>
72{};
73
74struct growth_factor_60
75 : dtl::grow_factor_ratio<0, 8, 5>
76{};
77
78struct growth_factor_100
79 : dtl::grow_factor_ratio<0, 2, 1>
80{};
81
20effc67
TL
82template<class SizeType>
83BOOST_CONTAINER_FORCEINLINE void clamp_by_stored_size_type(SizeType &, SizeType)
84{}
85
86template<class SizeType, class SomeStoredSizeType>
87BOOST_CONTAINER_FORCEINLINE void clamp_by_stored_size_type(SizeType &s, SomeStoredSizeType)
88{
89 if (s >= SomeStoredSizeType(-1) )
90 s = SomeStoredSizeType(-1);
91}
92
7c673cae
FG
93} //namespace container {
94} //namespace boost {
95
20effc67
TL
96#include <boost/container/detail/config_end.hpp>
97
7c673cae 98#endif //#ifndef BOOST_CONTAINER_DETAIL_NEXT_CAPACITY_HPP