Skip to content

Commit a29e6b1

Browse files
committed
Added a samples_view() method to the SampleHeaders class
This allows the names of samples stored in a SampleHeaders instance to be efficiently iterated via a view of the keys of an internal map.
1 parent 90e38f7 commit a29e6b1

2 files changed

Lines changed: 14 additions & 4 deletions

File tree

libtiledbvcf/src/dataset/tiledbvcfdataset.cc

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
#include <cstdint>
2929
#include <future>
3030
#include <map>
31-
#include <ranges>
3231
#include <string>
3332
#include <vector>
3433

@@ -1355,11 +1354,11 @@ void TileDBVCFDataset::SampleHeaders::set_sample_header(
13551354
Indexes& indexes = sample_index_lookup[sample_name];
13561355
return indexes.header_idx == hdr_idx;
13571356
};
1358-
auto samples_view = std::views::keys(sample_index_lookup);
1357+
auto samples = samples_view();
13591358
std::vector<std::string> unique_hdr_samples;
13601359
std::copy_if(
1361-
samples_view.begin(),
1362-
samples_view.end(),
1360+
samples.begin(),
1361+
samples.end(),
13631362
std::back_inserter(unique_hdr_samples),
13641363
unique_hdr_filter);
13651364
std::string unqiue_hdr_samples_str = utils::join(unique_hdr_samples, ',');

libtiledbvcf/src/dataset/tiledbvcfdataset.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
#include <map>
3131
#include <memory>
32+
#include <ranges>
3233
#include <string>
3334
#include <thread>
3435
#include <unordered_set>
@@ -281,6 +282,16 @@ class TileDBVCFDataset {
281282
*/
282283
SafeBCFHdr get_sample_header(const std::string& sample) const;
283284

285+
/**
286+
* Returns the sample names stored as a view of the internal lookup map.
287+
*
288+
* @param sample The name of the sample to get the header for
289+
* @return The first header
290+
*/
291+
auto samples_view() {
292+
return std::views::keys(sample_index_lookup);
293+
};
294+
284295
/**
285296
* Gets sample names in the order their heaeders are returned by the
286297
* TileDB header array query.

0 commit comments

Comments
 (0)