containers doc
This commit is contained in:
@@ -108,7 +108,7 @@ public:
|
||||
//! \~\details
|
||||
//! \~\code
|
||||
//! PIMap <int, PIString> m{{1, "a"}, {2, "b"}};
|
||||
//! piCout << m; // {1, 2, 3}
|
||||
//! piCout << m; // {1: a, 2: b}
|
||||
//! \endcode
|
||||
inline PIMap(std::initializer_list<std::pair<Key, T>> init_list) {
|
||||
for (auto i: init_list) {
|
||||
@@ -289,6 +289,11 @@ public:
|
||||
//! \~russian Если элемента с таким ключом `key` не существует,
|
||||
//! то он будет создан конструктором по умолчанию и добавлен в массив
|
||||
//! по ключу `key`, а затем возвращена ссылка на этот новый элемент.
|
||||
//! \~\code
|
||||
//! PIMap <PIString, PIString> m;
|
||||
//! m[] =
|
||||
//! piCout << m; //
|
||||
//! \endcode
|
||||
//! \~\sa \a insert(), \a value(), \a key()
|
||||
inline T & operator [](const Key & key) {
|
||||
bool f(false);
|
||||
@@ -357,16 +362,22 @@ public:
|
||||
return f;
|
||||
}
|
||||
|
||||
//! \~english Tests if element with value `value` exists in the array.
|
||||
//! \~russian Проверяет наличие элемента со значением `value` в массиве.
|
||||
inline bool containsValue(const T & value) const {
|
||||
return pim_content.contains(value);
|
||||
}
|
||||
|
||||
//! \~english Attempts to allocate memory for at least `new_size` elements.
|
||||
//! \~russian Резервируется память под как минимум `new_size` элементов.
|
||||
inline PIMap<Key, T> & reserve(size_t new_size) {
|
||||
pim_content.reserve(new_size);
|
||||
pim_index.reserve(new_size);
|
||||
return *this;
|
||||
}
|
||||
|
||||
//! \~english Remove element with key `key` from the array.
|
||||
//! \~russian Удаляет элемент с ключом `key` из массива.
|
||||
inline PIMap<Key, T> & remove(const Key & key) {
|
||||
bool f(false);
|
||||
ssize_t i = _find(key, f);
|
||||
@@ -375,23 +386,44 @@ public:
|
||||
}
|
||||
|
||||
|
||||
//! \~english Remove all elements in the array
|
||||
//! passes the test implemented by the provided function `test`.
|
||||
//! \~russian Удаляет все элементы, удовлетворяющие условию,
|
||||
//! заданному в передаваемой функции `test`.
|
||||
inline PIMap<Key, T> & removeWhere(std::function<bool(const Key & key, const T & value)> test) {
|
||||
for (int i = 0; i < pim_index.size_s(); ++i) {
|
||||
if (pim_index[i].key, pim_content[pim_index[i].index]) {
|
||||
if (test(pim_index[i].key, pim_content[pim_index[i].index])) {
|
||||
_remove(i);
|
||||
--i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
inline PIMap<Key, T> & erase(const Key & key) {return remove(key);}
|
||||
//! \~english Same as \a remove().
|
||||
//! \~russian Синоним функции \a remove().
|
||||
inline PIMap<Key, T> & erase(const Key & key) {
|
||||
return remove(key);
|
||||
}
|
||||
|
||||
|
||||
//! \~english Clear array, remove all elements.
|
||||
//! \~russian Очищает массив, удаляет все элементы.
|
||||
//! \~\details
|
||||
//! \~\note
|
||||
//! \~english Reserved memory will not be released.
|
||||
//! \~russian Зарезервированная память не освободится.
|
||||
//! \~\sa \a resize()
|
||||
inline PIMap<Key, T> & clear() {
|
||||
pim_content.clear();
|
||||
pim_index.clear();
|
||||
return *this;
|
||||
}
|
||||
|
||||
//! \~english Swaps array `v` other with this array.
|
||||
//! \~russian Меняет местами массив `v` с этим массивом.
|
||||
//! \~\details
|
||||
//! \~english This operation is very fast and never fails.
|
||||
//! \~russian Эта операция выполняется мгновенно без копирования памяти и никогда не дает сбоев.
|
||||
inline void swap(PIMap<Key, T> & other) {
|
||||
pim_content.swap(other.pim_content);
|
||||
pim_index.swap(other.pim_index);
|
||||
|
||||
Reference in New Issue
Block a user