Добавлено несколько методов в hashStrMap.
Added several methods to hashStrMap.
This commit is contained in:
Aleksandr Orefkov 2026-07-24 16:24:40 +03:00
parent a779aa7320
commit 86deccbac3
13 changed files with 159 additions and 24 deletions

View File

@ -5,7 +5,7 @@ include(FetchContent)
project( project(
simstr simstr
VERSION 1.8.1 VERSION 1.8.2
DESCRIPTION "Yet another modern C++ string library" DESCRIPTION "Yet another modern C++ string library"
HOMEPAGE_URL "https://github.com/orefkov/simstr" HOMEPAGE_URL "https://github.com/orefkov/simstr"
LANGUAGES CXX LANGUAGES CXX

View File

@ -1,5 +1,5 @@
/* /*
* ver. 1.8.1 * ver. 1.8.2
* (c) Проект "SimStr", Александр Орефков orefkov@gmail.com * (c) Проект "SimStr", Александр Орефков orefkov@gmail.com
* Бенчмарки * Бенчмарки
* (c) Project "SimStr", Aleksandr Orefkov orefkov@gmail.com * (c) Project "SimStr", Aleksandr Orefkov orefkov@gmail.com

View File

@ -48,7 +48,7 @@ PROJECT_NAME = "simstr"
# could be handy for archiving the generated documentation or if some version # could be handy for archiving the generated documentation or if some version
# control system is used. # 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 # 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 # 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 # 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 # 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. # this, this feature is disabled by default.
# The default value is: NO. # The default value is: NO.
# This tag requires that the tag HAVE_DOT is set to YES. # This tag requires that the tag HAVE_DOT is set to YES.

View File

@ -48,7 +48,7 @@ PROJECT_NAME = "simstr"
# could be handy for archiving the generated documentation or if some version # could be handy for archiving the generated documentation or if some version
# control system is used. # 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 # 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 # 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 # 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 # 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. # this, this feature is disabled by default.
# The default value is: NO. # The default value is: NO.
# This tag requires that the tag HAVE_DOT is set to YES. # This tag requires that the tag HAVE_DOT is set to YES.

View File

@ -1,6 +1,6 @@
/* /*
* (c) Проект "SimStr", Александр Орефков orefkov@gmail.com * (c) Проект "SimStr", Александр Орефков orefkov@gmail.com
* ver. 1.8.1 * ver. 1.8.2
*/ */
#pragma once #pragma once

View File

@ -1,5 +1,5 @@
/* /*
* ver. 1.8.1 * ver. 1.8.2
* (c) Проект "SimStr", Александр Орефков orefkov@gmail.com * (c) Проект "SimStr", Александр Орефков orefkov@gmail.com
* Классы для работы со строками * Классы для работы со строками
* (c) Project "SimStr", Aleksandr Orefkov orefkov@gmail.com * (c) Project "SimStr", Aleksandr Orefkov orefkov@gmail.com
@ -4365,8 +4365,7 @@ public:
} }
auto erase(const InStore& key) { auto erase(const InStore& key) {
auto it = hash_t::find(key); if (auto it = hash_t::find(key); it != hash_t::end()) {
if (it != hash_t::end()) {
((sstring<K>*)it->first.node)->~sstring(); ((sstring<K>*)it->first.node)->~sstring();
hash_t::erase(it); hash_t::erase(it);
return 1; return 1;
@ -4378,15 +4377,151 @@ public:
return erase(toStoreType(key)); return erase(toStoreType(key));
} }
bool lookup(simple_str<K> txt, T& val) const { /*!
auto it = find(txt); * @ru @brief Поиск и извлечение значения.
if (it != hash_t::end()) { * @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<typename Dst> requires std::is_assignable_v<T, Dst>
bool lookup(simple_str<K> key, Dst& val) const {
if (auto it = find(key); it != hash_t::end()) {
val = it->second; val = it->second;
return true; return true;
} }
return false; 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<typename Dst> requires std::is_assignable_v<T, Dst>
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<typename Dst = T> requires std::is_constructible_v<Dst, T>
std::optional<Dst> get(simple_str<K> 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<typename Dst = T> requires std::is_constructible_v<Dst, T>
std::optional<Dst> 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<K> 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<K> 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() { void clear() {
for (auto& k: *this) for (auto& k: *this)
((sstring<K>*)k.first.node)->~sstring(); ((sstring<K>*)k.first.node)->~sstring();

View File

@ -1,5 +1,5 @@
/* /*
* ver. 1.8.1 * ver. 1.8.2
* (c) Проект "SimStr", Александр Орефков orefkov@gmail.com * (c) Проект "SimStr", Александр Орефков orefkov@gmail.com
* База для строковых конкатенаций через выражения времени компиляции * База для строковых конкатенаций через выражения времени компиляции
* (c) Project "SimStr", Aleksandr Orefkov orefkov@gmail.com * (c) Project "SimStr", Aleksandr Orefkov orefkov@gmail.com

View File

@ -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) [![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.
<h2>Speed up your work with strings by 2-10 times!</h2> <h2>Speed up your work with strings by 2-10 times!</h2>
@ -325,8 +325,8 @@ function(add_simstr)
simstr simstr
GIT_REPOSITORY https://github.com/orefkov/simstr.git GIT_REPOSITORY https://github.com/orefkov/simstr.git
GIT_SHALLOW TRUE GIT_SHALLOW TRUE
GIT_TAG tags/rel1.8.1 # Specify the desired release GIT_TAG tags/rel1.8.2 # Specify the desired release
FIND_PACKAGE_ARGS NAMES simstr 1.8.1 FIND_PACKAGE_ARGS NAMES simstr 1.8.2
) )
FetchContent_MakeAvailable(simstr) FetchContent_MakeAvailable(simstr)
endfunction() endfunction()

View File

@ -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) [![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.
<h2>Ускорь работу со строками в 2-10 раз!</h2> <h2>Ускорь работу со строками в 2-10 раз!</h2>
@ -326,8 +326,8 @@ function(add_simstr)
simstr simstr
GIT_REPOSITORY https://github.com/orefkov/simstr.git GIT_REPOSITORY https://github.com/orefkov/simstr.git
GIT_SHALLOW TRUE GIT_SHALLOW TRUE
GIT_TAG tags/rel1.8.1 # Укажите нужный релиз GIT_TAG tags/rel1.8.2 # Укажите нужный релиз
FIND_PACKAGE_ARGS NAMES simstr 1.8.1 FIND_PACKAGE_ARGS NAMES simstr 1.8.2
) )
FetchContent_MakeAvailable(simstr) FetchContent_MakeAvailable(simstr)
endfunction() endfunction()

View File

@ -1,5 +1,5 @@
/* /*
* ver. 1.8.1 * ver. 1.8.2
* (c) Проект "SimStr", Александр Орефков orefkov@gmail.com * (c) Проект "SimStr", Александр Орефков orefkov@gmail.com
* Реализация строковых функций * Реализация строковых функций
* (c) Project "SimStr", Aleksandr Orefkov orefkov@gmail.com * (c) Project "SimStr", Aleksandr Orefkov orefkov@gmail.com

View File

@ -1,5 +1,5 @@
/* /*
* ver. 1.8.1 * ver. 1.8.2
* (c) Проект "SimStr", Александр Орефков orefkov@gmail.com * (c) Проект "SimStr", Александр Орефков orefkov@gmail.com
* Тесты simstr * Тесты simstr
* (c) Project "SimStr", Aleksandr Orefkov orefkov@gmail.com * (c) Project "SimStr", Aleksandr Orefkov orefkov@gmail.com

View File

@ -1,5 +1,5 @@
/* /*
* ver. 1.8.1 * ver. 1.8.2
* (c) Проект "SimStr", Александр Орефков orefkov@gmail.com * (c) Проект "SimStr", Александр Орефков orefkov@gmail.com
* Тесты simstr * Тесты simstr
* (c) Project "SimStr", Aleksandr Orefkov orefkov@gmail.com * (c) Project "SimStr", Aleksandr Orefkov orefkov@gmail.com

View File

@ -1,5 +1,5 @@
/* /*
* ver. 1.8.1 * ver. 1.8.2
* (c) Проект "SimStr", Александр Орефков orefkov@gmail.com * (c) Проект "SimStr", Александр Орефков orefkov@gmail.com
* Тесты simstr * Тесты simstr
* (c) Project "SimStr", Aleksandr Orefkov orefkov@gmail.com * (c) Project "SimStr", Aleksandr Orefkov orefkov@gmail.com