1/*
2 * Packer_cls.hpp
3 *
4 * Created on: Jul 15, 2015
5 * Author: i-bird
6 */
7
8#ifndef MAP_VECTOR_GROW_POLICY_HPP_
9#define MAP_VECTOR_GROW_POLICY_HPP_
10
11#define PAGE_ALLOC 1
12
13namespace openfpm
14{
15
16 /*! \brief Grow policy define how the vector should grow every time we exceed the size
17 *
18 * In this case it return the requested size
19 *
20 */
21
22 class grow_policy_identity
23 {
24 public:
25
26 /*! \brief It say how much the vector must grow
27 *
28 * \param original size
29 * \param requested size
30 *
31 * \return how much to grow
32 *
33 */
34 static size_t grow(size_t original, size_t requested)
35 {
36 return requested;
37 }
38 };
39
40 /*! \brief Grow policy define how the vector should grow every time we exceed the size
41 *
42 * In this case it double up the size
43 *
44 */
45
46 class grow_policy_double
47 {
48 public:
49
50 /*! \brief It say how much the vector must grow
51 *
52 * \param original size
53 * \param requested size
54 *
55 * \return how much to grow
56 *
57 */
58 static size_t grow(size_t original, size_t requested)
59 {
60 size_t grow = (original == 0)?1:original;
61 while (grow < requested) {grow *= 2;}
62 return grow;
63 }
64 };
65
66 //! default grow policy
67 typedef grow_policy_double vector_grow_policy_default;
68
69 /*! \brief Grow policy define how the vector should grow every time we exceed the size
70 *
71 * In this case it increase of 4096 elements
72 *
73 */
74
75 class grow_policy_page
76 {
77 public:
78
79 /*! \brief It say how much the vector must grow
80 *
81 * \param original size
82 * \param requested size
83 *
84 * \return how much to grow
85 *
86 */
87 static size_t grow(size_t original, size_t requested)
88 {
89 return (requested / PAGE_ALLOC) * PAGE_ALLOC + PAGE_ALLOC;
90 }
91 };
92}
93
94#endif /* MAP_VECTOR_GROW_POLICY_HPP_ */
95