add growth factor

This commit is contained in:
blueloveTH 2024-04-28 21:14:27 +08:00
parent 542d83ba1c
commit 2929addbd8
3 changed files with 6 additions and 6 deletions

View File

@ -7,7 +7,7 @@
namespace pkpy {
using List = pod_vector<PyObject*>;
using List = pod_vector<PyObject*, 4>;
struct Tuple {
PyObject** _args;

View File

@ -5,7 +5,7 @@
namespace pkpy{
template<typename T>
template<typename T, int Growth=2>
struct pod_vector{
static constexpr int SizeT = sizeof(T);
static constexpr int N = 64 / SizeT;
@ -60,13 +60,13 @@ struct pod_vector{
template<typename __ValueT>
void push_back(__ValueT&& t) {
if (_size == _capacity) reserve(_capacity*2);
if (_size == _capacity) reserve(_capacity*Growth);
_data[_size++] = std::forward<__ValueT>(t);
}
template<typename... Args>
void emplace_back(Args&&... args) {
if (_size == _capacity) reserve(_capacity*2);
if (_size == _capacity) reserve(_capacity*Growth);
new (&_data[_size++]) T(std::forward<Args>(args)...);
}
@ -110,7 +110,7 @@ struct pod_vector{
template<typename __ValueT>
void insert(int i, __ValueT&& val){
if (_size == _capacity) reserve(_capacity*2);
if (_size == _capacity) reserve(_capacity*Growth);
for(int j=_size; j>i; j--) _data[j] = _data[j-1];
_data[i] = std::forward<__ValueT>(val);
_size++;

View File

@ -66,7 +66,7 @@ namespace pkpy{
ItemNode* old_nodes = _nodes;
int old_head_idx = _head_idx;
_capacity *= 2;
_capacity *= 4;
_mask = _capacity - 1;
_size = 0;
_critical_size = _capacity*__LoadFactor+0.5f;