Files
pip/libs/main/containers/picontainers.cpp
peri4 caa7880cc4 get rid of piForeach
apply some code analyzer recommendations
ICU flag now check if libicu exists
prepare for more accurate growth of containers (limited PoT, then constantly increase size)
2024-11-20 20:01:47 +03:00

49 lines
1.4 KiB
C++

/*
PIP - Platform Independent Primitives
Base macros for generic containers
Ivan Pelipenko peri4ko@yandex.ru
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "picontainers.h"
#include "piliterals_bytes.h"
const size_t minAlloc = 64;
const size_t maxPoTAlloc = 4_MiB;
size_t _PIContainerConstantsBase::calcMinCountPoT(size_t szof) {
size_t ret = 0;
size_t elc = 1;
while (elc * szof < minAlloc) {
elc *= 2;
++ret;
}
// printf("calcMinCount sizeof = %d, min_count = %d, pot = %d\n", szof, elc, ret);
return ret;
}
size_t _PIContainerConstantsBase::calcMaxCountForPoT(size_t szof) {
return maxPoTAlloc / szof;
}
size_t _PIContainerConstantsBase::calcStepAfterPoT(size_t szof) {
return calcMaxCountForPoT(szof);
}