Insert sorted into the vector, and use only const iterators in CCMap
This commit is contained in:
parent
bce4fe96d0
commit
8becafcae0
1 changed files with 5 additions and 4 deletions
|
|
@ -61,8 +61,9 @@ public:
|
||||||
{
|
{
|
||||||
auto it = absl::c_find_if(container, [&](auto&& pair){ return pair.first == index; });
|
auto it = absl::c_find_if(container, [&](auto&& pair){ return pair.first == index; });
|
||||||
if (it == container.end()) {
|
if (it == container.end()) {
|
||||||
container.emplace_back(index, defaultValue);
|
auto newElement = std::make_pair(index, defaultValue);
|
||||||
return container.back().second;
|
auto inserted = container.insert(absl::c_upper_bound(container, newElement, [](auto& lhs, auto& rhs) { return lhs.first < rhs.first; }), newElement);
|
||||||
|
return inserted->second;
|
||||||
} else {
|
} else {
|
||||||
return it->second;
|
return it->second;
|
||||||
}
|
}
|
||||||
|
|
@ -86,11 +87,11 @@ public:
|
||||||
{
|
{
|
||||||
return absl::c_find_if(container, [&](auto&& pair){ return pair.first == index; }) != container.end();
|
return absl::c_find_if(container, [&](auto&& pair){ return pair.first == index; }) != container.end();
|
||||||
}
|
}
|
||||||
typename std::vector<std::pair<int, ValueType>>::iterator begin() { return container.begin(); }
|
|
||||||
typename std::vector<std::pair<int, ValueType>>::const_iterator begin() const { return container.cbegin(); }
|
typename std::vector<std::pair<int, ValueType>>::const_iterator begin() const { return container.cbegin(); }
|
||||||
typename std::vector<std::pair<int, ValueType>>::iterator end() { return container.end(); }
|
|
||||||
typename std::vector<std::pair<int, ValueType>>::const_iterator end() const { return container.cend(); }
|
typename std::vector<std::pair<int, ValueType>>::const_iterator end() const { return container.cend(); }
|
||||||
private:
|
private:
|
||||||
|
// typename std::vector<std::pair<int, ValueType>>::iterator begin() { return container.begin(); }
|
||||||
|
// typename std::vector<std::pair<int, ValueType>>::iterator end() { return container.end(); }
|
||||||
const ValueType defaultValue;
|
const ValueType defaultValue;
|
||||||
std::vector<std::pair<int, ValueType>> container;
|
std::vector<std::pair<int, ValueType>> container;
|
||||||
LEAK_DETECTOR(CCMap);
|
LEAK_DETECTOR(CCMap);
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue