Skip to content

Commit 7328c7e

Browse files
committed
refactoring structure to make it more in userver-style
1 parent 9817ece commit 7328c7e

File tree

7 files changed

+31
-91
lines changed

7 files changed

+31
-91
lines changed

cmake/modules/Findboost.cmake

Lines changed: 0 additions & 21 deletions
This file was deleted.
Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,23 @@
11
project(userver-multi-index-lru CXX)
22

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()
3+
find_package(Boost REQUIRED)
124

135
userver_module(
146
multi-index-lru
157
SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}"
16-
UTEST_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/tests/main.cpp"
8+
UTEST_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/src/*_test.cpp"
9+
UBENCH_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/src/*_benchmark.cpp"
1710
DEPENDS core
1811
)
1912

2013
target_include_directories(userver-multi-index-lru
21-
PUBLIC ${Boost_INCLUDE_DIRS}
14+
PUBLIC
15+
${Boost_INCLUDE_DIRS}
16+
"${CMAKE_CURRENT_SOURCE_DIR}/tests/"
2217
)
2318

2419
_userver_directory_install(
2520
COMPONENT multi-index-lru
2621
FILES "${USERVER_ROOT_DIR}/cmake/modules/Findboost.cmake"
2722
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/userver/modules"
28-
)
29-
30-
# if(USERVER_FEATURE_UTEST)
31-
add_subdirectory(tests)
32-
# endif()
23+
)

libraries/multi_index_lru/include/userver/multi_index_lru/lru_boost_list_container.h

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,12 @@
66
#include <boost/multi_index/hashed_index.hpp>
77
#include <boost/multi_index/mem_fun.hpp>
88

9-
#include <list>
10-
#include <functional>
11-
#include <unordered_set>
12-
#include <iostream>
13-
149
USERVER_NAMESPACE_BEGIN
1510

16-
namespace lru_boost_list {
11+
namespace multi_index_lru {
1712
using namespace boost::multi_index;
1813

14+
namespace impl {
1915
template<typename Value>
2016
struct ValueWithHook
2117
{
@@ -62,15 +58,16 @@ struct ValueWithHook
6258
};
6359

6460
struct internal_ptr_tag {};
61+
} // namespace impl
6562

6663
template<
6764
typename Value,
6865
typename IndexSpecifierList,
69-
typename Allocator = std::allocator<ValueWithHook<Value>>
66+
typename Allocator = std::allocator<impl::ValueWithHook<Value>>
7067
>
7168
class LRUCacheContainer {
7269
private:
73-
using CacheItem = ValueWithHook<Value>;
70+
using CacheItem = impl::ValueWithHook<Value>;
7471
using List = boost::intrusive::list<
7572
CacheItem,
7673
boost::intrusive::member_hook<
@@ -83,7 +80,7 @@ class LRUCacheContainer {
8380
using ExtendedIndexSpecifierList = typename boost::mpl::push_back<
8481
IndexSpecifierList,
8582
hashed_unique<
86-
tag<internal_ptr_tag>,
83+
tag<impl::internal_ptr_tag>,
8784
const_mem_fun<CacheItem, const CacheItem*, &CacheItem::GetPointerToSelf>
8885
>
8986
>::type;
@@ -187,10 +184,10 @@ class LRUCacheContainer {
187184
if (!usage_list.empty()) {
188185
CacheItem *ptr_to_erase = &*usage_list.begin();
189186
usage_list.erase(usage_list.begin());
190-
container.template get<internal_ptr_tag>().erase(ptr_to_erase);
187+
container.template get<impl::internal_ptr_tag>().erase(ptr_to_erase);
191188
}
192189
}
193190
};
194-
}
191+
} // namespace multi_index_lru
195192

196193
USERVER_NAMESPACE_END

libraries/multi_index_lru/tests/main.cpp renamed to libraries/multi_index_lru/src/main_benchmark.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#include "tests/lru_basic_tests.h"
21
#include "benchmarks/lru_basic_benchmarks.h"
32
#include "benchmarks/lru_google_benchmarks.h"
43

@@ -8,10 +7,6 @@
87
using namespace USERVER_NAMESPACE;
98

109
int main() {
11-
test_lru_users<lru_boost_list::LRUCacheContainer>();
12-
test_lru_products<lru_boost_list::LRUCacheContainer>();
13-
std::cout << "all tests success" << std::endl;
14-
1510
benchmarks::simple_benchmark<lru_boost_list::LRUCacheContainer>("boost_list_output.txt");
1611
benchmarks::google_benchmark<lru_boost_list::LRUCacheContainer>();
1712

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#include "tests/lru_basic_tests.h"
2+
3+
// #define LRU_CONTAINER_DEBUG__
4+
#include <userver/multi_index_lru/lru_boost_list_container.h>
5+
6+
using namespace USERVER_NAMESPACE;
7+
8+
int main() {
9+
test_lru_users<lru_boost_list::LRUCacheContainer>();
10+
test_lru_products<lru_boost_list::LRUCacheContainer>();
11+
std::cout << "all tests success" << std::endl;
12+
return 0;
13+
}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +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"; }
1+
#include <userver/multi_index_lru/lru_boost_list_container.h>
2+
3+
namespace userver::multi_index_lru { const char* multi_index_lru_version = "1.0"; }

libraries/multi_index_lru/tests/CMakeLists.txt

Lines changed: 0 additions & 35 deletions
This file was deleted.

0 commit comments

Comments
 (0)