From db3de9904a9e558d9c7cfc7a7e973ebafefca3d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=91=D1=8B=D1=87=D0=BA=D0=BE=D0=B2=20=D0=90=D0=BD=D0=B4?= =?UTF-8?q?=D1=80=D0=B5=D0=B9?= Date: Tue, 30 Aug 2022 18:15:13 +0300 Subject: [PATCH] pimap some doc --- libs/main/containers/pideque.h | 4 ++-- libs/main/containers/pimap.h | 28 +++++++++++++++++++++++++++- libs/main/containers/pivector.h | 4 ++-- 3 files changed, 31 insertions(+), 5 deletions(-) diff --git a/libs/main/containers/pideque.h b/libs/main/containers/pideque.h index 183c8932..dfe0b618 100644 --- a/libs/main/containers/pideque.h +++ b/libs/main/containers/pideque.h @@ -2082,9 +2082,9 @@ public: } //! \~english Returns a new array with all elements - //! that pass the test implemented by the provided function `test`. + //! that pass the test implemented by the provided function `bool test(const T & e)`. //! \~russian Возвращает новый массив со всеми элементами, - //! прошедшими проверку, задаваемую в передаваемой функции `test`. + //! прошедшими проверку, задаваемую в передаваемой функции `bool test(const T & e)`. //! \~\details //! \~\code //! PIDeque v{3, 2, 5, 2, 7}; diff --git a/libs/main/containers/pimap.h b/libs/main/containers/pimap.h index ad3844be..e8dba4c9 100644 --- a/libs/main/containers/pimap.h +++ b/libs/main/containers/pimap.h @@ -1,6 +1,6 @@ //! \addtogroup Containers //! \{ -//! \file pideque.h +//! \file pimap.h //! \brief //! \~english Declares \a PIMap //! \~russian Объявление \a PIMap @@ -435,6 +435,11 @@ public: pim_index.swap(other.pim_index); } + //! \~english Inserts value `value` with key `key` in the array. + //! \~russian Вставляет значение `value` с ключом `key` в массив. + //! \~\details + //! \~english If an element with the key `key` already exists, it will be overwritten with the value `value`. + //! \~russian Если элемент с ключом `key` уже существует, то он будет перезаписан на значение `value`. inline PIMap & insert(const Key & key, const T & value) { bool f(false); ssize_t i = _find(key, f); @@ -459,6 +464,11 @@ public: return *this; } + //! \~english Inserts value `pair` in the array. + //! \~russian Вставляет пару `pair` в массив. + //! \~\details + //! \~english The first element of the pair is the key, and the second is the value. + //! \~russian Первый элемент пары является ключом, а второй значением. inline PIMap & insert(const PIPair & pair) { bool f(false); ssize_t i = _find(pair.first, f); @@ -511,6 +521,8 @@ public: return ret; } + //! \~english Execute function `void f(const Key & key, const T & value)` for every element in array. + //! \~russian Выполняет функцию `void f(const Key & key, const T & value)` для каждого элемента массива. inline void forEach(std::function f) const { for (int i = 0; i < pim_index.size_s(); ++i) { f(pim_index[i].key, pim_content[pim_index[i].index]); @@ -535,6 +547,20 @@ public: return ret; } + //! \~english Returns a new array with all elements + //! that pass the test implemented by the provided function `bool test(const Key & key, const T & value)`. + //! \~russian Возвращает новый массив со всеми элементами, + //! прошедшими проверку, задаваемую в передаваемой функции `bool test(const Key & key, const T & value)`. + inline PIDeque filter(std::function test) const { + PIMap ret; + for (int i = 0; i < pim_index.size_s(); ++i) { + if (test(pim_index[i].key, pim_content[pim_index[i].index])) { + ret.insert(pim_index[i].key, pim_content[pim_index[i].index]); + } + } + return ret; + } + private: struct MapIndex { MapIndex(const Key & k = Key(), size_t i = 0): key(k), index(i) {} diff --git a/libs/main/containers/pivector.h b/libs/main/containers/pivector.h index 9845c18b..adba236d 100644 --- a/libs/main/containers/pivector.h +++ b/libs/main/containers/pivector.h @@ -2000,9 +2000,9 @@ public: } //! \~english Returns a new array with all elements - //! that pass the test implemented by the provided function `test`. + //! that pass the test implemented by the provided function `bool test(const T & e)`. //! \~russian Возвращает новый массив со всеми элементами, - //! прошедшими проверку, задаваемую в передаваемой функции `test`. + //! прошедшими проверку, задаваемую в передаваемой функции `bool test(const T & e)`. //! \~\details //! \~\code //! PIVector v{3, 2, 5, 2, 7};