diff --git a/CMakeLists.txt b/CMakeLists.txt index d7b3162..267d251 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,7 +5,7 @@ include(FetchContent) project( simstr - VERSION 1.8.1 + VERSION 1.8.2 DESCRIPTION "Yet another modern C++ string library" HOMEPAGE_URL "https://github.com/orefkov/simstr" LANGUAGES CXX diff --git a/bench/bench_str.cpp b/bench/bench_str.cpp index bde990e..8aac7f5 100644 --- a/bench/bench_str.cpp +++ b/bench/bench_str.cpp @@ -1,5 +1,5 @@ /* - * ver. 1.8.1 + * ver. 1.8.2 * (c) Проект "SimStr", Александр Орефков orefkov@gmail.com * Бенчмарки * (c) Project "SimStr", Aleksandr Orefkov orefkov@gmail.com diff --git a/docs/Doxyfile b/docs/Doxyfile index cf84753..fa30426 100644 --- a/docs/Doxyfile +++ b/docs/Doxyfile @@ -48,7 +48,7 @@ PROJECT_NAME = "simstr" # could be handy for archiving the generated documentation or if some version # control system is used. -PROJECT_NUMBER = 1.8.1 +PROJECT_NUMBER = 1.8.2 # Using the PROJECT_BRIEF tag one can provide an optional one line description # for a project that appears at the top of each page and should give viewers a @@ -2928,7 +2928,7 @@ MAX_DOT_GRAPH_DEPTH = 0 # Set the DOT_MULTI_TARGETS tag to YES to allow dot to generate multiple output # files in one run (i.e. multiple -o and -T options on the command line). This -# makes dot run faster, but since only newer versions of dot (>1.8.10) support +# makes dot run faster, but since only newer versions of dot (>1.8.20) support # this, this feature is disabled by default. # The default value is: NO. # This tag requires that the tag HAVE_DOT is set to YES. diff --git a/docs/Doxyfile_ru b/docs/Doxyfile_ru index dcc58c9..96ec69b 100644 --- a/docs/Doxyfile_ru +++ b/docs/Doxyfile_ru @@ -48,7 +48,7 @@ PROJECT_NAME = "simstr" # could be handy for archiving the generated documentation or if some version # control system is used. -PROJECT_NUMBER = 1.8.1 +PROJECT_NUMBER = 1.8.2 # Using the PROJECT_BRIEF tag one can provide an optional one line description # for a project that appears at the top of each page and should give viewers a @@ -2928,7 +2928,7 @@ MAX_DOT_GRAPH_DEPTH = 0 # Set the DOT_MULTI_TARGETS tag to YES to allow dot to generate multiple output # files in one run (i.e. multiple -o and -T options on the command line). This -# makes dot run faster, but since only newer versions of dot (>1.8.10) support +# makes dot run faster, but since only newer versions of dot (>1.8.20) support # this, this feature is disabled by default. # The default value is: NO. # This tag requires that the tag HAVE_DOT is set to YES. diff --git a/include/simstr/simple_unicode.h b/include/simstr/simple_unicode.h index 842f2fc..1606df7 100644 --- a/include/simstr/simple_unicode.h +++ b/include/simstr/simple_unicode.h @@ -1,6 +1,6 @@ /* * (c) Проект "SimStr", Александр Орефков orefkov@gmail.com - * ver. 1.8.1 + * ver. 1.8.2 */ #pragma once diff --git a/include/simstr/sstring.h b/include/simstr/sstring.h index 2cc107d..bcce62a 100644 --- a/include/simstr/sstring.h +++ b/include/simstr/sstring.h @@ -1,5 +1,5 @@ /* -* ver. 1.8.1 +* ver. 1.8.2 * (c) Проект "SimStr", Александр Орефков orefkov@gmail.com * Классы для работы со строками * (c) Project "SimStr", Aleksandr Orefkov orefkov@gmail.com @@ -4365,8 +4365,7 @@ public: } auto erase(const InStore& key) { - auto it = hash_t::find(key); - if (it != hash_t::end()) { + if (auto it = hash_t::find(key); it != hash_t::end()) { ((sstring*)it->first.node)->~sstring(); hash_t::erase(it); return 1; @@ -4378,15 +4377,151 @@ public: return erase(toStoreType(key)); } - bool lookup(simple_str txt, T& val) const { - auto it = find(txt); - if (it != hash_t::end()) { + /*! + * @ru @brief Поиск и извлечение значения. + * @param key - искомый ключ. + * @param val - ссылка на приёмник значения. + * @details Если ключ существует, присваивает переданной ссылке хранимое значение и возвращает true. + * Иначе возвращает false. + * @en @brief Finding and retrieving the value. + * @param key - the key you are looking for. + * @param val - reference to the value receiver. + * @details If the key exists, assigns the stored value to the passed reference and returns true. + * Otherwise returns false. + */ + template requires std::is_assignable_v + bool lookup(simple_str key, Dst& val) const { + if (auto it = find(key); it != hash_t::end()) { val = it->second; return true; } return false; } + /*! + * @ru @brief Поиск и извлечение значения. + * @param key - искомый ключ. + * @details Если ключ существует, присваивает переданной ссылке хранимое значение и возвращает true. + * Иначе возвращает false. + * @en @brief Finding and retrieving the value. + * @param key - the key you are looking for. + * @param val - reference to the value receiver. + * @details If the key exists, assigns the stored value to the passed reference and returns true. + * Otherwise returns false. + */ + template requires std::is_assignable_v + bool lookup(const InStore& key, Dst& val) const { + if (auto it = find(key); it != hash_t::end()) { + val = it->second; + return true; + } + return false; + } + + /*! + * @ru @brief Поиск и извлечение значения. + * @param key - искомый ключ. + * @details Если ключ существует, возвращает std::optional указанного типа с копией значения. + * Иначе возвращает std::nullopt. + * @en @brief Finding and retrieving the value. + * @param key - the key you are looking for. + * @details If the key exists, return a std::optional of the specified type with a copy of the value. + * Otherwise returns std::nullopt. + */ + template requires std::is_constructible_v + std::optional get(simple_str key) const { + if (auto it = find(key); it != hash_t::end()) { + return it->second; + } + return {}; + } + + /*! + * @ru @brief Поиск и извлечение значения. + * @param key - искомый ключ. + * @details Если ключ существует, возвращает std::optional указанного типа с копией значения. + * Иначе возвращает std::nullopt. + * @en @brief Finding and retrieving the value. + * @param s - the key you are looking for. + * @details If the key exists, return a std::optional of the specified type with a copy of the value. + * Otherwise returns std::nullopt. + */ + template requires std::is_constructible_v + std::optional get(const InStore& key) const { + if (auto it = find(key); it != hash_t::end()) { + return it->second; + } + return {}; + } + + /*! + * @ru @brief Поиск существующего значения. + * @param key - искомый ключ. + * @details Если ключ существует, возвращает указатель на хранимое значение. + * Иначе возвращает nullptr. + * @en @brief Finding an existing value. + * @param s - the key you are looking for. + * @details If the key exists, returns a pointer to the stored value. + * Otherwise returns nullptr. + */ + T* existed(simple_str key) { + if (auto it = find(key); it != hash_t::end()) { + return std::addressof(it->second); + } + return nullptr; + } + + /*! + * @ru @brief Поиск существующего значения. + * @param key - искомый ключ. + * @details Если ключ существует, возвращает указатель на хранимое значение. + * Иначе возвращает nullptr. + * @en @brief Finding an existing value. + * @param s - the key you are looking for. + * @details If the key exists, returns a pointer to the stored value. + * Otherwise returns nullptr. + */ + T* existed(const InStore& key) { + if (auto it = find(key); it != hash_t::end()) { + return std::addressof(it->second); + } + return nullptr; + } + + /*! + * @ru @brief Поиск существующего значения. + * @param key - искомый ключ. + * @details Если ключ существует, возвращает константный указатель на хранимое значение. + * Иначе возвращает nullptr. + * @en @brief Finding an existing value. + * @param s - the key you are looking for. + * @details If the key exists, returns a constant pointer to the stored value. + * Otherwise returns nullptr. + */ + const T* existed(simple_str key) const { + if (auto it = find(key); it != hash_t::end()) { + return std::addressof(it->second); + } + return nullptr; + } + + /*! + * @ru @brief Поиск существующего значения. + * @param key - искомый ключ. + * @details Если ключ существует, возвращает константный указатель на хранимое значение. + * Иначе возвращает nullptr. + * @en @brief Finding an existing value. + * @param s - the key you are looking for. + * @details If the key exists, returns a constant pointer to the stored value. + * Otherwise returns nullptr. + */ + const T* existed(const InStore& key) const { + if (auto it = find(key); it != hash_t::end()) { + return std::addressof(it->second); + } + return nullptr; + } + void clear() { for (auto& k: *this) ((sstring*)k.first.node)->~sstring(); diff --git a/include/simstr/strexpr.h b/include/simstr/strexpr.h index bd266c0..0ea6ea9 100644 --- a/include/simstr/strexpr.h +++ b/include/simstr/strexpr.h @@ -1,5 +1,5 @@ /* - * ver. 1.8.1 + * ver. 1.8.2 * (c) Проект "SimStr", Александр Орефков orefkov@gmail.com * База для строковых конкатенаций через выражения времени компиляции * (c) Project "SimStr", Aleksandr Orefkov orefkov@gmail.com diff --git a/readme.md b/readme.md index 280f4db..0375c11 100644 --- a/readme.md +++ b/readme.md @@ -3,7 +3,7 @@ [![CMake on multiple platforms](https://github.com/orefkov/simstr/actions/workflows/cmake-multi-platform.yml/badge.svg)](https://github.com/orefkov/simstr/actions/workflows/cmake-multi-platform.yml) -Version 1.8.1. +Version 1.8.2.

Speed up your work with strings by 2-10 times!

@@ -325,8 +325,8 @@ function(add_simstr) simstr GIT_REPOSITORY https://github.com/orefkov/simstr.git GIT_SHALLOW TRUE - GIT_TAG tags/rel1.8.1 # Specify the desired release - FIND_PACKAGE_ARGS NAMES simstr 1.8.1 + GIT_TAG tags/rel1.8.2 # Specify the desired release + FIND_PACKAGE_ARGS NAMES simstr 1.8.2 ) FetchContent_MakeAvailable(simstr) endfunction() diff --git a/readme_ru.md b/readme_ru.md index dee0b9d..82d0c55 100644 --- a/readme_ru.md +++ b/readme_ru.md @@ -3,7 +3,7 @@ [![CMake on multiple platforms](https://github.com/orefkov/simstr/actions/workflows/cmake-multi-platform.yml/badge.svg)](https://github.com/orefkov/simstr/actions/workflows/cmake-multi-platform.yml) -Версия 1.8.1. +Версия 1.8.2.

Ускорь работу со строками в 2-10 раз!

@@ -326,8 +326,8 @@ function(add_simstr) simstr GIT_REPOSITORY https://github.com/orefkov/simstr.git GIT_SHALLOW TRUE - GIT_TAG tags/rel1.8.1 # Укажите нужный релиз - FIND_PACKAGE_ARGS NAMES simstr 1.8.1 + GIT_TAG tags/rel1.8.2 # Укажите нужный релиз + FIND_PACKAGE_ARGS NAMES simstr 1.8.2 ) FetchContent_MakeAvailable(simstr) endfunction() diff --git a/src/sstring.cpp b/src/sstring.cpp index 60f137f..ce34efa 100644 --- a/src/sstring.cpp +++ b/src/sstring.cpp @@ -1,5 +1,5 @@ /* - * ver. 1.8.1 + * ver. 1.8.2 * (c) Проект "SimStr", Александр Орефков orefkov@gmail.com * Реализация строковых функций * (c) Project "SimStr", Aleksandr Orefkov orefkov@gmail.com diff --git a/tests/test_expr_only.cpp b/tests/test_expr_only.cpp index 3a035f4..129a975 100644 --- a/tests/test_expr_only.cpp +++ b/tests/test_expr_only.cpp @@ -1,5 +1,5 @@ /* - * ver. 1.8.1 + * ver. 1.8.2 * (c) Проект "SimStr", Александр Орефков orefkov@gmail.com * Тесты simstr * (c) Project "SimStr", Aleksandr Orefkov orefkov@gmail.com diff --git a/tests/test_str.cpp b/tests/test_str.cpp index a149180..eb989ff 100644 --- a/tests/test_str.cpp +++ b/tests/test_str.cpp @@ -1,5 +1,5 @@ /* - * ver. 1.8.1 + * ver. 1.8.2 * (c) Проект "SimStr", Александр Орефков orefkov@gmail.com * Тесты simstr * (c) Project "SimStr", Aleksandr Orefkov orefkov@gmail.com diff --git a/tests/test_tostrexpr.cpp b/tests/test_tostrexpr.cpp index 2188adf..441cfa1 100644 --- a/tests/test_tostrexpr.cpp +++ b/tests/test_tostrexpr.cpp @@ -1,5 +1,5 @@ /* - * ver. 1.8.1 + * ver. 1.8.2 * (c) Проект "SimStr", Александр Орефков orefkov@gmail.com * Тесты simstr * (c) Project "SimStr", Aleksandr Orefkov orefkov@gmail.com