Skip to content

Commit aa2b5f9

Browse files
committed
itegrated multi-index lru to userver
1 parent 084b91e commit aa2b5f9

File tree

19 files changed

+204
-92
lines changed

19 files changed

+204
-92
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
include_guard(GLOBAL)
2+
3+
if(userver_multiindex_lru_FOUND)
4+
return()
5+
endif()
6+
7+
find_package(userver REQUIRED COMPONENTS core)
8+
9+
find_package(Boost REQUIRED)
10+
11+
set(userver_multiindex_lru_FOUND TRUE)

cmake/modules/Findboost.cmake

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
_userver_module_begin(
2+
NAME
3+
Boost
4+
DEBIAN_NAMES
5+
libboost-dev
6+
FORMULA_NAMES
7+
boost
8+
PACMAN_NAMES
9+
boost
10+
PKG_CONFIG_NAMES
11+
boost
12+
)
13+
14+
_userver_module_find_include(NAMES boost/version.hpp)
15+
16+
_userver_module_end()
17+
18+
if(NOT TARGET Boost::boost AND Boost_FOUND)
19+
add_library(Boost::boost INTERFACE)
20+
target_include_directories(Boost::boost INTERFACE ${Boost_INCLUDE_DIRS})
21+
endif()

libraries/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,16 @@ option(USERVER_FEATURE_EASY "Build easy HTTP server library" "${USERVER_LIB_ENAB
22
option(USERVER_FEATURE_S3API "Build S3 api client library" "${USERVER_LIB_ENABLED_DEFAULT}")
33
option(USERVER_FEATURE_GRPC_REFLECTION "Build grpc reflection library" "${USERVER_LIB_ENABLED_DEFAULT}")
44
option(USERVER_FEATURE_GRPC_PROTOVALIDATE "Build grpc protovalidate library" "OFF")
5+
option(USERVER_FEATURE_MULTI_INDEX_LRU "Build multi index lru library" "ON")
56

67
if(USERVER_FEATURE_S3API)
78
add_subdirectory(s3api)
89
endif()
910

11+
if (USERVER_FEATURE_MULTI_INDEX_LRU)
12+
add_subdirectory(multi_index_lru)
13+
endif()
14+
1015
if(USERVER_FEATURE_EASY)
1116
if(NOT USERVER_FEATURE_POSTGRESQL)
1217
message(FATAL_ERROR "'USERVER_FEATURE_EASY' requires 'USERVER_FEATURE_POSTGRESQL=ON'")
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
project(userver-multi-index-lru CXX)
2+
3+
find_package(Boost REQUIRED)
4+
5+
6+
if(NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/multi_index_lru.cpp")
7+
file(WRITE "${CMAKE_CURRENT_SOURCE_DIR}/src/multi_index_lru.cpp"
8+
"// MultiIndex LRU header-only lib\n"
9+
"// This file exists only to satisfy CMake target requirements\n"
10+
"namespace userver::lru_boost_list { const char* multi_index_lru_version = \"1.0\"; }\n")
11+
endif()
12+
13+
userver_module(
14+
multi-index-lru
15+
SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}"
16+
UTEST_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/tests/main.cpp"
17+
DEPENDS core
18+
)
19+
20+
target_include_directories(userver-multi-index-lru
21+
PUBLIC ${Boost_INCLUDE_DIRS}
22+
)
23+
24+
_userver_directory_install(
25+
COMPONENT multi-index-lru
26+
FILES "${USERVER_ROOT_DIR}/cmake/modules/Findboost.cmake"
27+
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/userver/modules"
28+
)
29+
30+
# if(USERVER_FEATURE_UTEST)
31+
add_subdirectory(tests)
32+
# endif()

lru_container/src/implements/examples/lru_list_container.h renamed to libraries/multi_index_lru/include/userver/multi_index_lru/implements/examples/lru_list_container.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
#include <functional>
88
#include <unordered_set>
99

10+
USERVER_NAMESPACE_BEGIN
11+
1012
namespace lru_list {
1113
using namespace boost::multi_index;
1214

@@ -177,4 +179,6 @@ class LRUCacheContainer_List {
177179
template<typename T>
178180
size_t ValueWithIdentificator<T>::id = 0;
179181

180-
}
182+
}
183+
184+
USERVER_NAMESPACE_END

lru_container/src/implements/examples/lru_time_index_container.h renamed to libraries/multi_index_lru/include/userver/multi_index_lru/implements/examples/lru_time_index_container.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
#include <chrono>
44

5+
USERVER_NAMESPACE_BEGIN
6+
57
namespace lru_time_index {
68
using namespace boost::multi_index;
79

@@ -138,4 +140,6 @@ class LRUCacheContainer_TimeIndex {
138140
}
139141
}
140142
};
141-
}
143+
}
144+
145+
USERVER_NAMESPACE_END

lru_container/src/implements/actual/lru_boost_list_container.h renamed to libraries/multi_index_lru/include/userver/multi_index_lru/lru_boost_list_container.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
#include <unordered_set>
1111
#include <iostream>
1212

13+
USERVER_NAMESPACE_BEGIN
14+
1315
namespace lru_boost_list {
1416
using namespace boost::multi_index;
1517

@@ -69,7 +71,7 @@ template<
6971
typename IndexSpecifierList,
7072
typename Allocator = std::allocator<ValueWithHook<Value>>
7173
>
72-
class LRUCacheContainer_BoostList {
74+
class LRUCacheContainer {
7375
private:
7476
using CacheItem = ValueWithHook<Value>;
7577
using List = boost::intrusive::list<
@@ -104,7 +106,7 @@ class LRUCacheContainer_BoostList {
104106
using value_type = Value;
105107
using cache_item_type = CacheItem;
106108

107-
LRUCacheContainer_BoostList(size_t max_size) : max_size(max_size) {}
109+
LRUCacheContainer(size_t max_size) : max_size(max_size) {}
108110

109111
template<typename... Args>
110112
bool emplace(Args&&... args) {
@@ -192,4 +194,6 @@ class LRUCacheContainer_BoostList {
192194
}
193195
}
194196
};
195-
}
197+
}
198+
199+
USERVER_NAMESPACE_END
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
project-name: userver-lib-multi-index-lru
2+
3+
description: multi index lru cache
4+
5+
maintainers:
6+
- Common components
7+
8+
libraries:
9+
- userver-core
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// MultiIndex LRU header-only lib
2+
// This file exists only to satisfy CMake target requirements
3+
namespace userver::lru_boost_list { const char* multi_index_lru_version = "1.0"; }
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
project(multi-index-lru-tests)
2+
3+
find_package(Boost REQUIRED)
4+
find_package(benchmark REQUIRED)
5+
6+
file(GLOB_RECURSE MULTIINDEX_LRU_LIB_TESTS_SOURCES
7+
${CMAKE_CURRENT_SOURCE_DIR}/*.cpp
8+
${CMAKE_CURRENT_SOURCE_DIR}/*.h
9+
)
10+
11+
add_library(${PROJECT_NAME} STATIC ${MULTIINDEX_LRU_LIB_TESTS_SOURCES})
12+
target_link_libraries(${PROJECT_NAME}
13+
PUBLIC
14+
userver::multi-index-lru
15+
benchmark::benchmark
16+
)
17+
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_20)
18+
add_executable(multi-index-lru-test-runner
19+
${CMAKE_CURRENT_SOURCE_DIR}/main.cpp
20+
)
21+
22+
target_link_libraries(multi-index-lru-test-runner
23+
PRIVATE
24+
${PROJECT_NAME}
25+
)
26+
27+
_userver_directory_install(
28+
COMPONENT multi-index-lru
29+
DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/include/"
30+
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
31+
)
32+
33+
_userver_install_targets(COMPONENT multi-index-lru TARGETS ${PROJECT_NAME})

0 commit comments

Comments
 (0)