Skip to content

Commit 7baa1f3

Browse files
committed
Template some methods to avoid boilerplate to_atom_key calls
1 parent d5724da commit 7baa1f3

3 files changed

Lines changed: 28 additions & 24 deletions

File tree

cpp/arcticdb/version/test/version_backwards_compat.hpp

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,12 @@ inline std::optional<RefKey> get_symbol_ref_key(const std::shared_ptr<StreamSour
2828
std::deque<AtomKey> backwards_compat_delete_all_versions(
2929
const std::shared_ptr<Store>& store, std::shared_ptr<VersionMap>& version_map, const StreamId& stream_id
3030
) {
31-
31+
std::deque<AtomKey> output;
3232
auto entry = version_map->check_reload(
3333
store, stream_id, LoadStrategy{LoadType::ALL, LoadObjective::INCLUDE_DELETED}, __FUNCTION__
3434
);
35-
auto indexes = entry->get_indexes(false);
36-
std::deque<AtomKey> output(indexes.size());
37-
std::ranges::transform(indexes, output.begin(), [&stream_id](const auto& atom_key_packed) {
38-
return atom_key_packed.to_atom_key(stream_id);
39-
});
35+
auto indexes = entry->template get_indexes<AtomKey>(false);
36+
output.assign(std::begin(indexes), std::end(indexes));
4037

4138
if (auto ref_key = get_symbol_ref_key(store, stream_id); ref_key) {
4239
store->remove_key(*ref_key).wait();
@@ -51,7 +48,6 @@ std::vector<AtomKey> backwards_compat_write_and_prune_previous(
5148
) {
5249
const auto& sym = key.id();
5350
log::version().debug("Version map pruning previous versions for stream {}", key.id());
54-
5551
auto entry = version_map->check_reload(
5652
store, sym, LoadStrategy{LoadType::ALL, LoadObjective::INCLUDE_DELETED}, __FUNCTION__
5753
);
@@ -61,11 +57,7 @@ std::vector<AtomKey> backwards_compat_write_and_prune_previous(
6157
version_map->do_write(store, key, entry);
6258
write_symbol_ref(store, key, std::nullopt, entry->head_.value());
6359
version_map->remove_entry_version_keys(store, old_entry, sym);
64-
auto output_packed = old_entry.get_indexes(false);
65-
std::vector<AtomKey> output(output_packed.size());
66-
std::ranges::transform(output_packed, output.begin(), [&sym](const auto& atom_key_packed) {
67-
return atom_key_packed.to_atom_key(sym);
68-
});
60+
auto output = old_entry.template get_indexes<AtomKey>(false);
6961

7062
if (version_map->log_changes())
7163
log_write(store, sym, key.version_id());

cpp/arcticdb/version/version_functions.hpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,14 @@ inline version_store::UpdateInfo get_latest_undeleted_version_and_next_version_i
5050
return {latest_undeleted_version, next_version_id};
5151
}
5252

53-
inline std::vector<AtomKeyPacked> get_all_versions(
53+
template<AtomKeyType T = AtomKeyPacked>
54+
std::vector<T> get_all_versions(
5455
const std::shared_ptr<Store>& store, const std::shared_ptr<VersionMap>& version_map, const StreamId& stream_id
5556
) {
5657
ARCTICDB_SAMPLE(GetAllVersions, 0)
5758
LoadStrategy load_strategy{LoadType::ALL, LoadObjective::UNDELETED_ONLY};
5859
auto entry = version_map->check_reload(store, stream_id, load_strategy, __FUNCTION__);
59-
return entry->get_indexes(false);
60+
return entry->template get_indexes<T>(false);
6061
}
6162

6263
inline std::optional<AtomKey> get_specific_version(
@@ -131,8 +132,8 @@ inline std::unordered_map<VersionId, bool> get_all_tombstoned_versions(
131132
LoadStrategy load_strategy{LoadType::ALL, LoadObjective::INCLUDE_DELETED};
132133
auto entry = version_map->check_reload(store, stream_id, load_strategy, __FUNCTION__);
133134
std::unordered_map<VersionId, bool> result;
134-
for (auto key : entry->get_tombstoned_indexes())
135-
result[key.version_id()] = store->key_exists(key.to_atom_key(stream_id)).get();
135+
for (const auto& key : entry->template get_tombstoned_indexes<AtomKey>())
136+
result[key.version_id()] = store->key_exists(key).get();
136137

137138
return result;
138139
}

cpp/arcticdb/version/version_map_entry.hpp

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -324,20 +324,31 @@ struct VersionMapEntry {
324324
keys_.push_front(key);
325325
}
326326

327-
std::vector<AtomKeyPacked> get_indexes(bool include_deleted) const {
328-
std::vector<AtomKeyPacked> output;
327+
template<AtomKeyType T = AtomKeyPacked>
328+
std::vector<T> get_indexes(bool include_deleted) const {
329+
std::vector<T> output;
329330
for (const auto& key : keys_) {
330-
if (is_index_key_type(key.type()) && (include_deleted || !is_tombstoned(key)))
331-
output.emplace_back(key);
331+
if (is_index_key_type(key.type()) && (include_deleted || !is_tombstoned(key))) {
332+
if constexpr (std::is_same_v<T, AtomKey>) {
333+
output.emplace_back(key.to_atom_key(stream_id_));
334+
} else {
335+
output.emplace_back(key);
336+
}
337+
}
332338
}
333339
return output;
334340
}
335341

336-
std::vector<AtomKeyPacked> get_tombstoned_indexes() const {
337-
std::vector<AtomKeyPacked> output;
342+
template<AtomKeyType T = AtomKeyPacked>
343+
std::vector<T> get_tombstoned_indexes() const {
344+
std::vector<T> output;
338345
for (const auto& key : keys_) {
339-
if (is_index_key_type(key.type()) && is_tombstoned(key))
340-
output.emplace_back(key);
346+
if (is_index_key_type(key.type()) && is_tombstoned(key)) {
347+
if constexpr (std::is_same_v<T, AtomKey>) {
348+
output.emplace_back(key.to_atom_key(stream_id_));
349+
} else {
350+
output.emplace_back(key);
351+
} }
341352
}
342353
return output;
343354
}

0 commit comments

Comments
 (0)