30#include <unordered_map>
33#include "iceberg/iceberg_export.h"
35#include "iceberg/util/string_util.h"
43 using value_type = std::shared_ptr<DataFile>;
44 using iterator =
typename std::vector<value_type>::iterator;
45 using const_iterator =
typename std::vector<value_type>::const_iterator;
46 using difference_type =
typename std::vector<value_type>::difference_type;
54 std::pair<iterator, bool>
insert(
const value_type& file) {
return InsertImpl(file); }
57 std::pair<iterator, bool>
insert(value_type&& file) {
58 return InsertImpl(std::move(file));
62 size_t size()
const {
return elements_.size(); }
65 bool empty()
const {
return elements_.empty(); }
70 index_by_path_.clear();
74 iterator
begin() {
return elements_.begin(); }
75 const_iterator begin()
const {
return elements_.begin(); }
76 const_iterator cbegin()
const {
return elements_.cbegin(); }
79 iterator
end() {
return elements_.end(); }
80 const_iterator end()
const {
return elements_.end(); }
81 const_iterator cend()
const {
return elements_.cend(); }
84 std::span<const value_type>
as_span()
const {
return elements_; }
87 std::pair<iterator, bool> InsertImpl(value_type file) {
89 return {elements_.end(),
false};
92 auto [index_iter, inserted] =
93 index_by_path_.try_emplace(file->file_path, elements_.size());
95 auto pos =
static_cast<difference_type
>(index_iter->second);
96 return {elements_.begin() + pos,
false};
99 elements_.push_back(std::move(file));
100 return {std::prev(elements_.end()),
true};
104 std::vector<value_type> elements_;
105 std::unordered_map<std::string_view, size_t, StringHash, StringEqual> index_by_path_;
A set of DataFile pointers with insertion order preserved and deduplicated by file path.
Definition data_file_set.h:41
iterator end()
Get iterator to the end.
Definition data_file_set.h:79
void clear()
Clear all elements from the set.
Definition data_file_set.h:68
std::span< const value_type > as_span() const
Get a non-owning view of the data files in insertion order.
Definition data_file_set.h:84
size_t size() const
Get the number of elements in the set.
Definition data_file_set.h:62
std::pair< iterator, bool > insert(const value_type &file)
Insert a data file into the set.
Definition data_file_set.h:54
iterator begin()
Get iterator to the beginning.
Definition data_file_set.h:74
bool empty() const
Check if the set is empty.
Definition data_file_set.h:65
std::pair< iterator, bool > insert(value_type &&file)
Insert a data file into the set (move version).
Definition data_file_set.h:57