diff --git a/CMakeLists.txt b/CMakeLists.txt index 61d0fad4..9259e814 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,8 +3,8 @@ cmake_policy(SET CMP0017 NEW) # need include() with .cmake project(PIP) set(PIP_MAJOR 3) set(PIP_MINOR 1) -set(PIP_REVISION 0) -set(PIP_SUFFIX dev) +set(PIP_REVISION 1) +set(PIP_SUFFIX ) set(PIP_COMPANY SHS) set(PIP_DOMAIN org.SHS) diff --git a/libs/main/containers/pimap.h b/libs/main/containers/pimap.h index e8dba4c9..13b60b08 100644 --- a/libs/main/containers/pimap.h +++ b/libs/main/containers/pimap.h @@ -494,6 +494,10 @@ public: return *this; } + //! \~english Returns the value of the element by the key `key` + //! or `default_` if there is no such element. + //! \~russian Возвращает значение элемента по ключу `key` + //! или `default_` если такого элемента нет. inline T value(const Key & key, const T & default_ = T()) const { bool f(false); ssize_t i = _find(key, f); @@ -501,17 +505,25 @@ public: return pim_content[pim_index[i].index]; } + //! \~english Returns an array of values of all elements + //! \~russian Возвращает массив значений всех эелметнов inline PIVector values() const {return pim_content;} - inline Key key(const T & value_, const Key & default_ = Key()) const { + //! \~english Returns the key of the first element + //! whose value matches `value` or `default_` if there is no such element. + //! \~russian Возвращает ключ первого элемента, значение которого + //! совпадает с `value` или `default_` если такого элемента нет. + inline Key key(const T & value, const Key & default_ = Key()) const { for (int i = 0; i < pim_index.size_s(); ++i) { - if (pim_content[pim_index[i].index] == value_) { + if (pim_content[pim_index[i].index] == value) { return pim_index[i].key; } } return default_; } + //! \~english Returns an array of keys of all elements + //! \~russian Возвращает массив ключей всех элементов inline PIVector keys() const { PIVector ret; ret.reserve(pim_index.size()); @@ -529,6 +541,10 @@ public: } } + //! \~english Сreates a new map PIMap populated with the results + //! of calling a provided function `PIPair f(const Key & key, const T & value)` on every element in the calling array. + //! \~russian Создаёт новый словарь PIMap с результатом вызова указанной функции + //! `PIPair f(const Key & key, const T & value)` для каждого элемента массива. template inline PIMap map(std::function(const Key & key, const T & value)> f) const { PIMap ret; ret.reserve(size()); @@ -538,6 +554,10 @@ public: return ret; } + //! \~english Сreates a new array PIVector populated with the results + //! of calling a provided function `ST f(const Key & key, const T & value)` on every element in the calling array. + //! \~russian Создаёт новый массив PIVector с результатом вызова указанной функции + //! `ST f(const Key & key, const T & value)` для каждого элемента массива. template inline PIVector map(std::function f) const { PIVector ret; ret.reserve(size()); @@ -551,7 +571,7 @@ public: //! 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 { + inline PIMap 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])) { diff --git a/libs/main/containers/piqueue.h b/libs/main/containers/piqueue.h index 5fd1620c..a5e266c6 100644 --- a/libs/main/containers/piqueue.h +++ b/libs/main/containers/piqueue.h @@ -37,18 +37,77 @@ #include "pideque.h" #include "pivector.h" - +//! \addtogroup Containers +//! \{ +//! \class PIQueue +//! \brief +//! \~english A container class inherited from the \a PIDeque with queue functionality. +//! \~russian Класс контейнера наследованый от \a PIDeque с функциональностью очереди. +//! \~\} +//! \details +//! \~english The container is a array of elements organized according to the FIFO principle (first in, first out). +//! Adds \a enqueue() and \dequeue() functions to \a PIDeque. +//! \~russian Контейнер представляющий массив элементов, организованных по принципу FIFO (первым пришёл — первым вышел). +//! Добавляет к \a PIDeque функции \a enqueue() и \a dequeue(). +//! \~\sa \a PIDeque template class PIQueue: public PIDeque { public: + + //! \~english Constructs an empty array. + //! \~russian Создает пустой массив. PIQueue() {} + + //! \~english Puts an element on the queue. + //! \~russian Кладёт элемент в очередь. PIDeque & enqueue(const T & v) {PIDeque::push_front(v); return *this;} + + //! \~english Move an element on the queue. + //! \~russian Перемещает элемент в очередь. PIDeque & enqueue(T && v) {PIDeque::push_front(std::move(v)); return *this;} + + //! \~english Retrieves and returns an element from the queue. + //! \~russian Забирает и возвращает элемент из очереди. + //! \~\details + //! \note + //! \~english This function assumes that the array isn't empty. + //! Otherwise will be undefined behavior. + //! \~russian Эта функция предполагает, что массив не пустой. + //! Иначе это приведёт к неопределённому поведению программы и ошибкам памяти. T dequeue() {return PIDeque::take_back();} + + //! \~english Head element of the queue. + //! \~russian Головной (верхний) элемент очереди. + //! \~\details + //! \note + //! \~english Returns a reference to the head element of the queue. + //! This function assumes that the array isn't empty. + //! Otherwise will be undefined behavior. + //! \~russian Возвращает ссылку на головной (верхний) элемент очереди. + //! Эта функция предполагает, что массив не пустой. + //! Иначе это приведёт к неопределённому поведению программы и ошибкам памяти. T & head() {return PIDeque::back();} const T & head() const {return PIDeque::back();} - PIVector toVector() {return PIVector(PIDeque::data(), PIDeque::size());} - PIDeque toDeque() {return PIDeque(*this);} + + //! \~english Tail element of the queue. + //! \~russian Хвостовой (нижний) элемент очереди. + //! \~\details + //! \~english Returns a reference to the tail element of the queue. + //! This function assumes that the array isn't empty. + //! Otherwise will be undefined behavior. + //! \~russian Возвращает ссылку на хвостовой (нижний) элемент очереди. + //! Эта функция предполагает, что массив не пустой. + //! Иначе это приведёт к неопределённому поведению программы и ошибкам памяти. + T & tail() {return PIDeque::front();} + const T & tail() const {return PIDeque::front();} + + //! \~english Converts \a PIQueue to \a PIVector. + //! \~russian Преобразует \a PIQueue в \a PIVector. + PIVector toVector() const {return PIVector(PIDeque::data(), PIDeque::size());} + + //! \~english Converts \a PIQueue to \a PIDeque. + //! \~russian Преобразует \a PIQueue в \a PIDeque. + PIDeque toDeque() const {return PIDeque(*this);} }; #endif // PIQUEUE_H diff --git a/libs/main/containers/pistack.h b/libs/main/containers/pistack.h index 1d9c1f55..91f39b9d 100644 --- a/libs/main/containers/pistack.h +++ b/libs/main/containers/pistack.h @@ -66,23 +66,24 @@ public: //! \~russian Перемещает элемент в стек. PIVector & push(T && v) {PIVector::push_back(std::move(v)); return *this;} - //! \~english Retrieves and returns an element from the stack. //! \~russian Забирает и возвращает элемент из стека. - //! \details - //! \~\note - //! \~english If the stack is empty, it returns the element created by the default constructor. - //! \~russian Если стек пустой то возвращает элемент созданный конструткором по умолчанию. + //! \~\details + //! \note + //! \~english This function assumes that the array isn't empty. + //! Otherwise will be undefined behavior. + //! \~russian Эта функция предполагает, что массив не пустой. + //! Иначе это приведёт к неопределённому поведению программы и ошибкам памяти. T pop() {return PIVector::take_back();} - - //! \~english Last element. - //! \~russian Последний элемент массива. + //! \~english Top element of the stack + //! \~russian Верхний элемент стека. //! \~\details - //! \~english Returns a reference to the last item in the array. + //! \note + //! \~english Returns a reference to the top element of the stack. //! This function assumes that the array isn't empty. //! Otherwise will be undefined behavior. - //! \~russian Возвращает ссылку на последний элемент в массиве. + //! \~russian Возвращает ссылку на верхний элемент стека. //! Эта функция предполагает, что массив не пустой. //! Иначе это приведёт к неопределённому поведению программы и ошибкам памяти. T & top() {return PIVector::back();} @@ -90,11 +91,11 @@ public: //! \~english Converts \a PIStack to \a PIVector. //! \~russian Преобразует \a PIStack в \a PIVector. - PIVector toVector() {return PIVector(*this);} + PIVector toVector() const {return PIVector(*this);} //! \~english Converts \a PIStack to \a PIDeque. //! \~russian Преобразует \a PIStack в \a PIDeque. - PIDeque toDeque() {return PIDeque(PIVector::data(), PIVector::size());} + PIDeque toDeque() const {return PIDeque(PIVector::data(), PIVector::size());} }; #endif // PISTACK_H