add sectorcollection

This commit is contained in:
Ivan Morozov
2022-06-10 15:28:59 +03:00
parent 87c3d6cf9d
commit e049cff2ed
9 changed files with 67 additions and 37 deletions

View File

@ -7,7 +7,7 @@ SectorCollection::SectorCollection()
}
void SectorCollection::Add(Sector item)
void SectorCollection::Add(const Sector &item)
{
if (DoCheckSizeLimitReached() == false)
return;
@ -15,6 +15,12 @@ void SectorCollection::Add(Sector item)
add(item);
}
void SectorCollection::Clear()
{
largeArraySlices.clear();
count = 0;
}
bool SectorCollection::DoCheckSizeLimitReached()
{
if (!sizeLimitReached && (count - 1 > MAX_SECTOR_V4_COUNT_LOCK_RANGE))
@ -25,22 +31,22 @@ bool SectorCollection::DoCheckSizeLimitReached()
return true;
}
int SectorCollection::add(Sector item)
int SectorCollection::add(const Sector &item)
{
int itemIndex = count / SLICE_SIZE;
unsigned itemIndex = count / SLICE_SIZE;
if (itemIndex < largeArraySlices.Count)
{
largeArraySlices[itemIndex].Add(item);
count++;
}
else
{
ArrayList ar = new ArrayList(SLICE_SIZE);
ar.Add(item);
largeArraySlices.Add(ar);
count++;
}
if (itemIndex < largeArraySlices.size())
{
largeArraySlices[itemIndex]->push_back(item);
count++;
}
else
{
std::unique_ptr<std::vector<Sector>> ar(new std::vector<Sector>(SLICE_SIZE));
ar->emplace_back(item);
largeArraySlices.push_back(ar);
count++;
}
return count - 1;
return count - 1;
}