Skip to content

Commit d97e04d

Browse files
committed
[MISC] CPP23 md subscript
1 parent 0cab5ec commit d97e04d

File tree

11 files changed

+126
-101
lines changed

11 files changed

+126
-101
lines changed

.github/workflows/ci_linux.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ jobs:
3232
strategy:
3333
fail-fast: false
3434
matrix:
35-
compiler: ["clang-18", "clang-17", "gcc-14", "gcc-13", "gcc-12", "gcc-11", "intel"]
35+
compiler: ["clang-18", "clang-17", "gcc-14", "gcc-13", "gcc-12", "intel"]
3636
container:
3737
image: ghcr.io/seqan/${{ matrix.compiler }}
3838
volumes:

.github/workflows/ci_macos.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ jobs:
3232
strategy:
3333
fail-fast: false
3434
matrix:
35-
compiler: ["clang-18", "clang-17", "gcc-14", "gcc-13", "gcc-12", "gcc-11"]
35+
compiler: ["clang-18", "clang-17", "gcc-14", "gcc-13", "gcc-12"]
3636
steps:
3737
- name: Checkout
3838
uses: actions/checkout@v4

.github/workflows/ci_misc.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ jobs:
4040
use_include_dependencies: "OFF"
4141
cxx_flags: "-stdlib=libc++"
4242

43-
- name: "Snippet gcc11"
44-
compiler: "gcc-11"
43+
- name: "Snippet gcc12"
44+
compiler: "gcc-12"
4545
build: snippet
4646
build_type: Release
4747
use_include_dependencies: "OFF"
@@ -53,8 +53,8 @@ jobs:
5353
use_include_dependencies: "OFF"
5454
cxx_flags: "-stdlib=libc++"
5555

56-
- name: "Performance gcc11"
57-
compiler: "gcc-11"
56+
- name: "Performance gcc12"
57+
compiler: "gcc-12"
5858
build: performance
5959
build_type: Release
6060
use_include_dependencies: "OFF"
@@ -72,8 +72,8 @@ jobs:
7272
build_type: Release
7373
use_include_dependencies: "OFF"
7474

75-
- name: "Header gcc11"
76-
compiler: "gcc-11"
75+
- name: "Header gcc12"
76+
compiler: "gcc-12"
7777
build: header
7878
build_type: Release
7979
use_include_dependencies: "OFF"
@@ -85,7 +85,7 @@ jobs:
8585
use_include_dependencies: "ON"
8686

8787
- name: "Tutorial"
88-
compiler: "gcc-11"
88+
compiler: "gcc-12"
8989
build: tutorial
9090
build_type: Debug
9191
use_include_dependencies: "OFF"

cmake/configuration.cmake

Lines changed: 12 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -79,43 +79,23 @@ include ("${HIBF_SOURCE_DIR}/test/cmake/hibf_require_ccache.cmake")
7979
hibf_require_ccache ()
8080

8181
# ----------------------------------------------------------------------------
82-
# Require C++20
82+
# C++ standard
8383
# ----------------------------------------------------------------------------
8484

85-
set (CMAKE_REQUIRED_FLAGS_SAVE ${CMAKE_REQUIRED_FLAGS})
86-
87-
set (CXXSTD_TEST_SOURCE
88-
"#if !defined (__cplusplus) || (__cplusplus < 202002)
89-
#error NOCXX20
90-
#endif
91-
int main() {}")
92-
93-
set (HIBF_FEATURE_CPP20_FLAG_BUILTIN "")
94-
set (HIBF_FEATURE_CPP20_FLAG_STD20 "-std=c++20")
95-
set (HIBF_FEATURE_CPP20_FLAG_STD2a "-std=c++2a")
96-
97-
set (HIBF_CPP20_FLAG "")
98-
99-
foreach (_FLAG BUILTIN STD20 STD2a)
100-
set (CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS_SAVE} ${HIBF_FEATURE_CPP20_FLAG_${_FLAG}}")
101-
102-
check_cxx_source_compiles ("${CXXSTD_TEST_SOURCE}" CPP20_FLAG_${_FLAG})
85+
if (NOT DEFINED CMAKE_CXX_STANDARD_REQUIRED)
86+
set (CMAKE_CXX_STANDARD_REQUIRED OFF)
87+
endif ()
10388

104-
if (CPP20_FLAG_${_FLAG})
105-
set (HIBF_CPP20_FLAG ${_FLAG})
106-
break ()
107-
endif ()
108-
endforeach ()
89+
if (NOT DEFINED CMAKE_CXX_EXTENSIONS)
90+
set (CMAKE_CXX_EXTENSIONS OFF)
91+
endif ()
10992

110-
set (CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS_SAVE})
93+
if (NOT DEFINED CMAKE_CXX_STANDARD)
94+
set (CMAKE_CXX_STANDARD 23)
95+
endif ()
11196

112-
if (HIBF_CPP20_FLAG STREQUAL "BUILTIN")
113-
hibf_config_print ("C++ Standard-20 support: builtin")
114-
elseif (HIBF_CPP20_FLAG)
115-
set (HIBF_CXX_FLAGS "${HIBF_CXX_FLAGS} ${HIBF_FEATURE_CPP20_FLAG_${HIBF_CPP20_FLAG}}")
116-
hibf_config_print ("C++ Standard-20 support: via ${HIBF_FEATURE_CPP20_FLAG_${HIBF_CPP20_FLAG}}")
117-
else ()
118-
hibf_config_error ("HIBF requires C++20, but your compiler does not support it.")
97+
if (DEFINED CMAKE_CXX_STANDARD AND CMAKE_CXX_STANDARD LESS 23)
98+
message (FATAL_ERROR "Requires C++23 or higher.")
11999
endif ()
120100

121101
# ----------------------------------------------------------------------------

include/hibf/hierarchical_interleaved_bloom_filter.hpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@
2121
#include <hibf/interleaved_bloom_filter.hpp> // for interleaved_bloom_filter
2222
#include <hibf/layout/layout.hpp> // for layout
2323
#include <hibf/misc/counting_vector.hpp> // for counting_vector
24-
#include <hibf/misc/timer.hpp> // for concurrent_timer
25-
#include <hibf/platform.hpp> // for HIBF_CONSTEXPR_VECTOR
24+
#include <hibf/misc/md_vector.hpp>
25+
#include <hibf/misc/timer.hpp> // for concurrent_timer
26+
#include <hibf/platform.hpp> // for HIBF_CONSTEXPR_VECTOR
2627

2728
namespace seqan::hibf
2829
{
@@ -202,7 +203,7 @@ class hierarchical_interleaved_bloom_filter
202203
* If `j != i` is returned, there is a lower level IBF, bin `b` is a merged bin, and `j` is the ID of the lower
203204
* level IBF in ibf_vector.
204205
*/
205-
std::vector<std::vector<int64_t>> next_ibf_id;
206+
md_vector<int64_t> next_ibf_id;
206207

207208
/*!\brief Stores for each bin in each IBF of the HIBF the user bin ID.
208209
* \details
@@ -211,7 +212,7 @@ class hierarchical_interleaved_bloom_filter
211212
* lower level IBF.
212213
* Otherwise, the returned value `j` is the corresponding user bin ID.
213214
*/
214-
std::vector<std::vector<int64_t>> ibf_bin_to_user_bin_id{};
215+
md_vector<int64_t> ibf_bin_to_user_bin_id{};
215216

216217
//!\brief Returns a membership_agent to be used for counting.
217218
membership_agent_type membership_agent() const;
@@ -280,16 +281,16 @@ class hierarchical_interleaved_bloom_filter::membership_agent_type
280281
{
281282
sum += result[bin];
282283

283-
auto const current_filename_index = hibf_ptr->ibf_bin_to_user_bin_id[ibf_idx][bin];
284+
auto const current_filename_index = hibf_ptr->ibf_bin_to_user_bin_id[ibf_idx, bin];
284285

285286
if (current_filename_index < 0) // merged bin
286287
{
287288
if (sum >= threshold)
288-
membership_for_impl(values, hibf_ptr->next_ibf_id[ibf_idx][bin], threshold);
289+
membership_for_impl(values, hibf_ptr->next_ibf_id[ibf_idx, bin], threshold);
289290
sum = 0u;
290291
}
291292
else if (bin + 1u == result.size() || // last bin
292-
current_filename_index != hibf_ptr->ibf_bin_to_user_bin_id[ibf_idx][bin + 1]) // end of split bin
293+
current_filename_index != hibf_ptr->ibf_bin_to_user_bin_id[ibf_idx, bin + 1]) // end of split bin
293294
{
294295
if (sum >= threshold)
295296
result_buffer.emplace_back(current_filename_index);
@@ -415,16 +416,16 @@ class hierarchical_interleaved_bloom_filter::counting_agent_type
415416
for (size_t bin{}; bin < result.size(); ++bin)
416417
{
417418
sum += result[bin];
418-
auto const current_filename_index = hibf_ptr->ibf_bin_to_user_bin_id[ibf_idx][bin];
419+
auto const current_filename_index = hibf_ptr->ibf_bin_to_user_bin_id[ibf_idx, bin];
419420

420421
if (current_filename_index < 0) // merged bin
421422
{
422423
if (sum >= threshold)
423-
bulk_count_impl(values, hibf_ptr->next_ibf_id[ibf_idx][bin], threshold);
424+
bulk_count_impl(values, hibf_ptr->next_ibf_id[ibf_idx, bin], threshold);
424425
sum = 0u;
425426
}
426427
else if (bin + 1u == result.size() || // last bin
427-
current_filename_index != hibf_ptr->ibf_bin_to_user_bin_id[ibf_idx][bin + 1]) // end of split bin
428+
current_filename_index != hibf_ptr->ibf_bin_to_user_bin_id[ibf_idx, bin + 1]) // end of split bin
428429
{
429430
if (sum >= threshold)
430431
result_buffer[current_filename_index] = sum;

include/hibf/layout/hierarchical_binning.hpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
#include <hibf/build/bin_size_in_bits.hpp> // for bin_size_in_bits
1414
#include <hibf/config.hpp> // for config
1515
#include <hibf/layout/data_store.hpp> // for data_store
16-
#include <hibf/platform.hpp> // for HIBF_WORKAROUND_GCC_BOGUS_MEMCPY
16+
#include <hibf/misc/md_vector.hpp>
17+
#include <hibf/platform.hpp> // for HIBF_WORKAROUND_GCC_BOGUS_MEMCPY
1718

1819
namespace seqan::hibf::layout
1920
{
@@ -140,9 +141,9 @@ class hierarchical_binning
140141
*
141142
* \image html hierarchical_dp_init.png
142143
*/
143-
void initialization(std::vector<std::vector<size_t>> & matrix,
144-
std::vector<std::vector<size_t>> & ll_matrix,
145-
std::vector<std::vector<std::pair<size_t, size_t>>> & trace);
144+
void initialization(md_vector<size_t> & matrix,
145+
md_vector<size_t> & ll_matrix,
146+
md_vector<std::pair<size_t, size_t>> & trace);
146147

147148
/*!\brief Performs the recursion.
148149
*
@@ -182,9 +183,8 @@ class hierarchical_binning
182183
* this algorithm. It would be too computational intensive to compute the splitting for every possibility.
183184
*
184185
*/
185-
void recursion(std::vector<std::vector<size_t>> & matrix,
186-
std::vector<std::vector<size_t>> & ll_matrix,
187-
std::vector<std::vector<std::pair<size_t, size_t>>> & trace);
186+
void
187+
recursion(md_vector<size_t> & matrix, md_vector<size_t> & ll_matrix, md_vector<std::pair<size_t, size_t>> & trace);
188188

189189
void backtrack_merged_bin(size_t trace_j,
190190
size_t const next_j,
@@ -198,7 +198,7 @@ class hierarchical_binning
198198
maximum_bin_tracker & max_tracker);
199199

200200
//!\brief Backtracks the trace matrix and writes the resulting binning into the output file.
201-
size_t backtracking(std::vector<std::vector<std::pair<size_t, size_t>>> const & trace);
201+
size_t backtracking(md_vector<std::pair<size_t, size_t>> const & trace);
202202

203203
data_store initialise_libf_data(size_t const trace_j) const;
204204

include/hibf/misc/md_vector.hpp

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// SPDX-FileCopyrightText: 2006-2024, Knut Reinert & Freie Universität Berlin
2+
// SPDX-FileCopyrightText: 2016-2024, Knut Reinert & MPI für molekulare Genetik
3+
// SPDX-License-Identifier: BSD-3-Clause
4+
5+
/*!\file
6+
* \brief Provides seqan::hibf::md_vector.
7+
* \author Enrico Seiler <enrico.seiler AT fu-berlin.de>
8+
*/
9+
10+
#pragma once
11+
12+
#include <vector> // for vector
13+
14+
#include <hibf/platform.hpp>
15+
16+
namespace seqan::hibf
17+
{
18+
19+
template <typename value_t>
20+
struct md_vector : public std::vector<std::vector<value_t>>
21+
{
22+
using base_t = std::vector<std::vector<value_t>>;
23+
using base_t::base_t;
24+
using base_t::operator[];
25+
#if defined(__cpp_explicit_this_parameter) && __cpp_explicit_this_parameter >= 202110L
26+
decltype(auto) operator[](this auto & self, size_t const x, size_t const y)
27+
{
28+
return self[x][y];
29+
}
30+
#else
31+
value_t & operator[](size_t const x, size_t const y)
32+
{
33+
return (*this)[x][y];
34+
}
35+
value_t const & operator[](size_t const x, size_t const y) const
36+
{
37+
return (*this)[x][y];
38+
}
39+
#endif
40+
};
41+
42+
} // namespace seqan::hibf

include/hibf/sketch/minhashes.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <cereal/access.hpp> // for access
1818
#include <cereal/cereal.hpp> // for make_nvp, CEREAL_NVP
1919

20+
#include <hibf/misc/md_vector.hpp>
2021
#include <hibf/platform.hpp>
2122

2223
namespace seqan::hibf::sketch
@@ -39,7 +40,7 @@ struct minhashes
3940
static constexpr size_t sketch_size{40};
4041

4142
//!\brief A table of sketches. For LSH we need multiple sketches, stored in a table.
42-
std::vector<std::vector<uint64_t>> table{}; // Each element (vector<uint64_t>) is a minhash.
43+
md_vector<uint64_t> table{}; // Each element (vector<uint64_t>) is a minhash.
4344

4445
/*!\name Constructors, destructor and assignment
4546
* \{

0 commit comments

Comments
 (0)