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);
|
||||
|
||||
@@ -44,9 +44,6 @@
|
||||
//! \~english Class template that provides a way to store two heterogeneous objects as a single unit.
|
||||
//! \~russian Класс, который позволяет хранить два разнородных объекта как единое целое.
|
||||
//! \~\}
|
||||
//! \details
|
||||
//! \~english
|
||||
//! \~russian
|
||||
//! \~\sa \a PIMap
|
||||
template<typename Type0, typename Type1>
|
||||
class PIPair {
|
||||
|
||||
@@ -1,8 +1,17 @@
|
||||
/*! \file piqueue.h
|
||||
* \brief Queue container
|
||||
*
|
||||
* This file declare PIQueue
|
||||
*/
|
||||
//! \addtogroup Containers
|
||||
//! \{
|
||||
//! \file piqueue.h
|
||||
//! \brief
|
||||
//! \~english Declares \a PIQueue
|
||||
//! \~russian Объявление \a PIQueue
|
||||
//! \~\authors
|
||||
//! \~english
|
||||
//! Ivan Pelipenko peri4ko@yandex.ru;
|
||||
//! Andrey Bychkov work.a.b@yandex.ru;
|
||||
//! \~russian
|
||||
//! Иван Пелипенко peri4ko@yandex.ru;
|
||||
//! Андрей Бычков work.a.b@yandex.ru;
|
||||
//! \~\}
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
Queue container
|
||||
|
||||
@@ -1,8 +1,17 @@
|
||||
/*! \file pistack.h
|
||||
* \brief Stack container
|
||||
*
|
||||
* This file declare PIStack
|
||||
*/
|
||||
//! \addtogroup Containers
|
||||
//! \{
|
||||
//! \file pistack.h
|
||||
//! \brief
|
||||
//! \~english Declares \a PIStack
|
||||
//! \~russian Объявление \a PIStack
|
||||
//! \~\authors
|
||||
//! \~english
|
||||
//! Ivan Pelipenko peri4ko@yandex.ru;
|
||||
//! Andrey Bychkov work.a.b@yandex.ru;
|
||||
//! \~russian
|
||||
//! Иван Пелипенко peri4ko@yandex.ru;
|
||||
//! Андрей Бычков work.a.b@yandex.ru;
|
||||
//! \~\}
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
Stack container
|
||||
@@ -28,16 +37,63 @@
|
||||
#include "pivector.h"
|
||||
#include "pideque.h"
|
||||
|
||||
//! \addtogroup Containers
|
||||
//! \{
|
||||
//! \class PIStack
|
||||
//! \brief
|
||||
//! \~english A container class inherited from the \a PIVector with stack functionality.
|
||||
//! \~russian Класс контейнера наследованый от \a PIVector с функциональностью стека.
|
||||
//! \~\}
|
||||
//! \details
|
||||
//! \~english The container is a array of elements organized according to the LIFO principle (last in, first out).
|
||||
//! Adds \a push() and \pop() functions to \a PIVector.
|
||||
//! \~russian Контейнер представляющий массив элементов, организованных по принципу LIFO (последним пришёл — первым вышел).
|
||||
//! Добавляет к \a PIVector функции \a push() и \a pop().
|
||||
//! \~\sa \a PIVector
|
||||
template<typename T>
|
||||
class PIStack: public PIVector<T> {
|
||||
public:
|
||||
|
||||
//! \~english Constructs an empty array.
|
||||
//! \~russian Создает пустой массив.
|
||||
PIStack() {}
|
||||
|
||||
//! \~english Puts an element on the stack.
|
||||
//! \~russian Кладёт элемент в стек.
|
||||
PIVector<T> & push(const T & v) {PIVector<T>::push_back(v); return *this;}
|
||||
|
||||
//! \~english Move an element on the stack.
|
||||
//! \~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 Если стек пустой то возвращает элемент созданный конструткором по умолчанию.
|
||||
T pop() {return PIVector<T>::take_back();}
|
||||
|
||||
|
||||
//! \~english Last element.
|
||||
//! \~russian Последний элемент массива.
|
||||
//! \~\details
|
||||
//! \~english Returns a reference to the last item in the array.
|
||||
//! This function assumes that the array isn't empty.
|
||||
//! Otherwise will be undefined behavior.
|
||||
//! \~russian Возвращает ссылку на последний элемент в массиве.
|
||||
//! Эта функция предполагает, что массив не пустой.
|
||||
//! Иначе это приведёт к неопределённому поведению программы и ошибкам памяти.
|
||||
T & top() {return PIVector<T>::back();}
|
||||
const T & top() const {return PIVector<T>::back();}
|
||||
|
||||
//! \~english Converts \a PIStack to \a PIVector.
|
||||
//! \~russian Преобразует \a PIStack в \a PIVector.
|
||||
PIVector<T> toVector() {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());}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user