mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-22 04:20:17 +00:00
add growth factor
This commit is contained in:
parent
542d83ba1c
commit
2929addbd8
@ -7,7 +7,7 @@
|
||||
|
||||
namespace pkpy {
|
||||
|
||||
using List = pod_vector<PyObject*>;
|
||||
using List = pod_vector<PyObject*, 4>;
|
||||
|
||||
struct Tuple {
|
||||
PyObject** _args;
|
||||
|
@ -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++;
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user