doc PIMap PIStack PIQueue done
This commit is contained in:
@@ -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)
|
||||
|
||||
|
||||
@@ -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<T> 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<Key> keys() const {
|
||||
PIVector<Key> ret;
|
||||
ret.reserve(pim_index.size());
|
||||
@@ -529,6 +541,10 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
//! \~english Сreates a new map PIMap<Key2, T2> populated with the results
|
||||
//! of calling a provided function `PIPair<Key2, T2> f(const Key & key, const T & value)` on every element in the calling array.
|
||||
//! \~russian Создаёт новый словарь PIMap<Key2, T2> с результатом вызова указанной функции
|
||||
//! `PIPair<Key2, T2> f(const Key & key, const T & value)` для каждого элемента массива.
|
||||
template <typename Key2, typename T2>
|
||||
inline PIMap<Key2, T2> map(std::function<PIPair<Key2, T2>(const Key & key, const T & value)> f) const {
|
||||
PIMap<Key2, T2> ret; ret.reserve(size());
|
||||
@@ -538,6 +554,10 @@ public:
|
||||
return ret;
|
||||
}
|
||||
|
||||
//! \~english Сreates a new array PIVector<ST> 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> с результатом вызова указанной функции
|
||||
//! `ST f(const Key & key, const T & value)` для каждого элемента массива.
|
||||
template <typename ST>
|
||||
inline PIVector<ST> map(std::function<ST(const Key & key, const T & value)> f) const {
|
||||
PIVector<ST> 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<T> filter(std::function<bool(const Key & key, const T & value)> test) const {
|
||||
inline PIMap<Key, T> filter(std::function<bool(const Key & key, const T & value)> test) const {
|
||||
PIMap<Key, T> ret;
|
||||
for (int i = 0; i < pim_index.size_s(); ++i) {
|
||||
if (test(pim_index[i].key, pim_content[pim_index[i].index])) {
|
||||
|
||||
@@ -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<typename T>
|
||||
class PIQueue: public PIDeque<T> {
|
||||
public:
|
||||
|
||||
//! \~english Constructs an empty array.
|
||||
//! \~russian Создает пустой массив.
|
||||
PIQueue() {}
|
||||
|
||||
//! \~english Puts an element on the queue.
|
||||
//! \~russian Кладёт элемент в очередь.
|
||||
PIDeque<T> & enqueue(const T & v) {PIDeque<T>::push_front(v); return *this;}
|
||||
|
||||
//! \~english Move an element on the queue.
|
||||
//! \~russian Перемещает элемент в очередь.
|
||||
PIDeque<T> & enqueue(T && v) {PIDeque<T>::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<T>::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<T>::back();}
|
||||
const T & head() const {return PIDeque<T>::back();}
|
||||
PIVector<T> toVector() {return PIVector<T>(PIDeque<T>::data(), PIDeque<T>::size());}
|
||||
PIDeque<T> toDeque() {return PIDeque<T>(*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<T>::front();}
|
||||
const T & tail() const {return PIDeque<T>::front();}
|
||||
|
||||
//! \~english Converts \a PIQueue to \a PIVector.
|
||||
//! \~russian Преобразует \a PIQueue в \a PIVector.
|
||||
PIVector<T> toVector() const {return PIVector<T>(PIDeque<T>::data(), PIDeque<T>::size());}
|
||||
|
||||
//! \~english Converts \a PIQueue to \a PIDeque.
|
||||
//! \~russian Преобразует \a PIQueue в \a PIDeque.
|
||||
PIDeque<T> toDeque() const {return PIDeque<T>(*this);}
|
||||
};
|
||||
|
||||
#endif // PIQUEUE_H
|
||||
|
||||
@@ -66,23 +66,24 @@ public:
|
||||
//! \~russian Перемещает элемент в стек.
|
||||
PIVector<T> & push(T && v) {PIVector<T>::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<T>::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<T>::back();}
|
||||
@@ -90,11 +91,11 @@ public:
|
||||
|
||||
//! \~english Converts \a PIStack to \a PIVector.
|
||||
//! \~russian Преобразует \a PIStack в \a PIVector.
|
||||
PIVector<T> toVector() {return PIVector<T>(*this);}
|
||||
PIVector<T> toVector() const {return PIVector<T>(*this);}
|
||||
|
||||
//! \~english Converts \a PIStack to \a PIDeque.
|
||||
//! \~russian Преобразует \a PIStack в \a PIDeque.
|
||||
PIDeque<T> toDeque() {return PIDeque<T>(PIVector<T>::data(), PIVector<T>::size());}
|
||||
PIDeque<T> toDeque() const {return PIDeque<T>(PIVector<T>::data(), PIVector<T>::size());}
|
||||
};
|
||||
|
||||
#endif // PISTACK_H
|
||||
|
||||
Reference in New Issue
Block a user