добавил const для части контейнеров и explicit для конструкторов

This commit is contained in:
2023-07-03 19:10:36 +03:00
parent 9e78546b7e
commit 3a6b3a4064
10 changed files with 217 additions and 176 deletions

View File

@@ -318,7 +318,7 @@ public:
//! \~\sa \a insert(), \a value(), \a key()
inline T & operator[](const Key & key) {
bool f(false);
ssize_t i = _find(key, f);
const ssize_t i = _find(key, f);
if (f) return pim_content[pim_index[i].index];
pim_content.push_back(T());
pim_index.insert(i, MapIndex(key, pim_content.size() - 1));
@@ -334,7 +334,7 @@ public:
//! \~russian Удаляет элемент с ключом `key` из массива и возвращает его.
inline T take(const Key & key, const T & default_ = T()) {
bool f(false);
ssize_t i = _find(key, f);
const ssize_t i = _find(key, f);
if (!f) return default_;
T ret(pim_content[pim_index[i].index]);
_remove(i);
@@ -398,7 +398,7 @@ public:
//! \~russian Удаляет элемент с ключом `key` из массива.
inline PIMap<Key, T> & remove(const Key & key) {
bool f(false);
ssize_t i = _find(key, f);
const ssize_t i = _find(key, f);
if (f) _remove(i);
return *this;
}
@@ -452,7 +452,7 @@ public:
//! \~russian Если элемент с ключом `key` уже существует, то он будет перезаписан на значение `value`.
inline PIMap<Key, T> & insert(const Key & key, const T & value) {
bool f(false);
ssize_t i = _find(key, f);
const ssize_t i = _find(key, f);
if (f) {
pim_content[pim_index[i].index] = value;
} else {
@@ -464,7 +464,7 @@ public:
inline PIMap<Key, T> & insert(const Key & key, T && value) {
bool f(false);
ssize_t i = _find(key, f);
const ssize_t i = _find(key, f);
if (f) {
pim_content[pim_index[i].index] = std::move(value);
} else {
@@ -481,7 +481,7 @@ public:
//! \~russian Первый элемент пары является ключом, а второй значением.
inline PIMap<Key, T> & insert(const PIPair<Key, T> & pair) {
bool f(false);
ssize_t i = _find(pair.first, f);
const ssize_t i = _find(pair.first, f);
if (f) {
pim_content[pim_index[i].index] = pair.second;
} else {
@@ -494,7 +494,7 @@ public:
inline PIMap<Key, T> & insert(PIPair<Key, T> && pair) {
bool f(false);
Key k(std::move(pair.first));
ssize_t i = _find(k, f);
const ssize_t i = _find(k, f);
if (f) {
pim_content[pim_index[i].index] = std::move(pair.second);
} else {
@@ -510,7 +510,7 @@ public:
//! или `default_` если такого элемента нет.
inline T value(const Key & key, const T & default_ = T()) const {
bool f(false);
ssize_t i = _find(key, f);
const ssize_t i = _find(key, f);
if (!f) return default_;
return pim_content[pim_index[i].index];
}
@@ -611,7 +611,7 @@ private:
friend PIBinaryStream<P> & operator<<(PIBinaryStream<P> & s, const PIDeque<typename PIMap<Key1, T1>::MapIndex> & v);
inline ssize_t _binarySearch(ssize_t first, ssize_t last, const Key & key, bool & found) const {
ssize_t mid;
ssize_t mid = 0;
while (first <= last) {
mid = (first + last) / 2;
if (key > pim_index[mid].key)
@@ -636,7 +636,7 @@ private:
}
inline void _remove(ssize_t index) {
size_t ci = pim_index[index].index, bi = pim_index.size() - 1;
const size_t ci = pim_index[index].index, bi = pim_index.size() - 1;
pim_index.remove(index);
for (size_t i = 0; i < pim_index.size(); ++i) {
if (pim_index[i].index == bi) {