Skip to content

Commit 986c697

Browse files
committed
Update qtils
1 parent 15cf229 commit 986c697

File tree

9 files changed

+50
-78
lines changed

9 files changed

+50
-78
lines changed

include/morum/archive_backend.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
#pragma once
88

9-
#include <qtils/macro.hpp>
9+
#include <qtils/macro/common.hpp>
1010

1111
#include <morum/common.hpp>
1212
#include <morum/db.hpp>

include/morum/common.hpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,20 @@
1010
#include <cassert>
1111
#include <chrono>
1212
#include <expected>
13-
#include <iostream>
14-
#include <print>
1513
#include <source_location>
1614
#include <vector>
1715

16+
#include <fmt/format.h>
17+
1818
#include <qtils/bytes.hpp>
1919

2020
#ifdef MORUM_ENABLE_TRACE
2121

2222
#define MORUM_TRACE(msg, ...) \
23-
std::println("{}:{}: {}", \
23+
fmt::println("{}:{}: {}", \
2424
std::source_location::current().file_name(), \
2525
std::source_location::current().line(), \
26-
std::format(msg __VA_OPT__(, ) __VA_ARGS__));
26+
fmt::format(msg __VA_OPT__(, ) __VA_ARGS__));
2727

2828
namespace morum {
2929
template <char... Name>
@@ -91,7 +91,7 @@ namespace morum {
9191
} // namespace morum
9292

9393
template <>
94-
struct std::formatter<morum::StorageError, char> {
94+
struct fmt::formatter<morum::StorageError, char> {
9595
template <class ParseContext>
9696
constexpr ParseContext::iterator parse(ParseContext &ctx) {
9797
auto it = ctx.begin();
@@ -102,7 +102,7 @@ struct std::formatter<morum::StorageError, char> {
102102
FmtContext::iterator format(const morum::StorageError &e,
103103
FmtContext &ctx) const {
104104
auto out = ctx.out();
105-
std::format_to(out,
105+
fmt::format_to(out,
106106
"From {}:{} - {}\n",
107107
e.origin.file_name(),
108108
e.origin.line(),

include/morum/merkle_tree.hpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@
1818
#include <variant>
1919

2020
#include <qtils/assert.hpp>
21-
#include <qtils/bytes.hpp>
2221
#include <qtils/bitspan.hpp>
22+
#include <qtils/bytes.hpp>
23+
#include <qtils/fixed_byte_vector.hpp>
2324
#include <qtils/optional_ref.hpp>
2425

2526
#include <morum/common.hpp>

src/merkle_tree/archive_backend.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#include <morum/archive_backend.hpp>
22

3+
#include <qtils/macro/unwrap.hpp>
4+
35
namespace morum {
46

57
std::expected<std::optional<TreeNode>, StorageError> ArchiveNodeLoader::load(

src/merkle_tree/db.cpp

+16-15
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
#include <rocksdb/status.h>
1313
#include <rocksdb/write_batch.h>
1414
#include <qtils/assert.hpp>
15-
#include <qtils/macro.hpp>
15+
#include <qtils/byte_utils.hpp>
16+
#include <qtils/macro/unwrap.hpp>
1617

1718
namespace morum {
1819

@@ -90,7 +91,8 @@ namespace morum {
9091

9192
family_idx = 0;
9293
for ([[maybe_unused]] auto &handle : handles) {
93-
[[maybe_unused]] auto name = to_string(static_cast<ColumnFamilyId>(family_idx++));
94+
[[maybe_unused]] auto name =
95+
to_string(static_cast<ColumnFamilyId>(family_idx++));
9496
QTILS_ASSERT(name.has_value());
9597
QTILS_ASSERT_EQ(handle->GetName(), *name);
9698
}
@@ -111,27 +113,26 @@ namespace morum {
111113

112114
std::expected<void, StorageError> write(
113115
qtils::ByteSpan key, qtils::ByteSpan value) override {
114-
return wrap_status(batch.Put(default_cf,
115-
qtils::to_string_view(key),
116-
qtils::to_string_view(value)));
116+
return wrap_status(
117+
batch.Put(default_cf, qtils::byte2str(key), qtils::byte2str(value)));
117118
}
118119

119120
std::expected<void, StorageError> remove(qtils::ByteSpan key) override {
120-
return wrap_status(batch.Delete(default_cf, qtils::to_string_view(key)));
121+
return wrap_status(batch.Delete(default_cf, qtils::byte2str(key)));
121122
}
122123

123124
std::expected<void, StorageError> write(ColumnFamilyId cf,
124125
qtils::ByteSpan key,
125126
qtils::ByteSpan value) override {
126127
return wrap_status(batch.Put(db->handles[static_cast<size_t>(cf)],
127-
qtils::to_string_view(key),
128-
qtils::to_string_view(value)));
128+
qtils::byte2str(key),
129+
qtils::byte2str(value)));
129130
}
130131

131132
std::expected<void, StorageError> remove(
132133
ColumnFamilyId cf, qtils::ByteSpan key) override {
133134
return wrap_status(batch.Delete(
134-
db->handles[static_cast<size_t>(cf)], qtils::to_string_view(key)));
135+
db->handles[static_cast<size_t>(cf)], qtils::byte2str(key)));
135136
}
136137

137138
std::shared_ptr<RocksDb> db;
@@ -181,8 +182,8 @@ namespace morum {
181182
qtils::ByteSpan key, qtils::ByteSpan value) {
182183
rocksdb::WriteBatch updates;
183184
QTILS_UNWRAP_void(wrap_status(updates.Put(handle,
184-
rocksdb::Slice{qtils::to_string_view(key)},
185-
rocksdb::Slice{qtils::to_string_view(value)})));
185+
rocksdb::Slice{qtils::byte2str(key)},
186+
rocksdb::Slice{qtils::byte2str(value)})));
186187
QTILS_UNWRAP_void(
187188
wrap_status(db->db->Write(rocksdb::WriteOptions{}, &updates)));
188189
return {};
@@ -193,7 +194,7 @@ namespace morum {
193194
std::string value;
194195
auto status = db->db->Get(rocksdb::ReadOptions{},
195196
handle,
196-
rocksdb::Slice{qtils::to_string_view(key)},
197+
rocksdb::Slice{qtils::byte2str(key)},
197198
&value);
198199
if (status.IsNotFound()) {
199200
return std::nullopt;
@@ -208,7 +209,7 @@ namespace morum {
208209
std::string res;
209210
auto status = db->db->Get(rocksdb::ReadOptions{},
210211
handle,
211-
rocksdb::Slice{qtils::to_string_view(key)},
212+
rocksdb::Slice{qtils::byte2str(key)},
212213
&res);
213214
if (status.IsNotFound()) {
214215
return std::nullopt;
@@ -220,8 +221,8 @@ namespace morum {
220221

221222
std::expected<void, StorageError> RocksDbColumnFamily::remove(
222223
qtils::ByteSpan key) const {
223-
QTILS_UNWRAP_void(wrap_status(db->db->Delete(
224-
rocksdb::WriteOptions{}, handle, qtils::to_string_view(key))));
224+
QTILS_UNWRAP_void(wrap_status(
225+
db->db->Delete(rocksdb::WriteOptions{}, handle, qtils::byte2str(key))));
225226
return {};
226227
}
227228

src/merkle_tree/merkle_tree.cpp

+6-4
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
#include <algorithm>
1212
#include <filesystem>
13-
#include <format>
1413
#include <functional>
1514
#include <iterator>
1615
#include <memory>
@@ -21,7 +20,10 @@
2120
#include <vector>
2221

2322
#include <blake2.h>
24-
#include <qtils/macro.hpp>
23+
#include <fmt/ranges.h>
24+
#include <qtils/byte_utils.hpp>
25+
#include <qtils/hex.hpp>
26+
#include <qtils/macro/unwrap.hpp>
2527

2628
#include <morum/common.hpp>
2729
#include <morum/db.hpp>
@@ -204,8 +206,8 @@ namespace morum {
204206
if (auto hash = branch.get_child_hash(bit); hash.has_value()) {
205207
QTILS_UNWRAP(auto node_opt, loader_->load(path, *hash));
206208
if (!node_opt) {
207-
return std::unexpected(StorageError{
208-
std::format("Node hash {} path {} not found", *hash, path)});
209+
return std::unexpected(StorageError{fmt::format(
210+
"Node hash {} path {} not found", qtils::Hex{*hash}, path)});
209211
}
210212
auto node_id = nodes_->store(*node_opt);
211213
branch.set_child(bit, node_id);

src/merkle_tree/nomt_backend.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#include <morum/nomt_backend.hpp>
22

3+
#include <qtils/macro/unwrap.hpp>
4+
35
namespace morum {
46

57
qtils::OptionalRef<RawNode> Page::get_node(qtils::BitSpan<> path) {

test/merkle_tree/tree_test.cpp

+13-49
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,9 @@
66
#include <cstdlib>
77
#include <expected>
88
#include <filesystem>
9-
#include <format>
109
#include <functional>
1110
#include <memory>
1211
#include <optional>
13-
#include <print>
1412
#include <random>
1513
#include <ranges>
1614
#include <span>
@@ -26,6 +24,7 @@
2624
#include <client/TracyScoped.hpp>
2725
#include <qtils/assert.hpp>
2826
#include <qtils/bytes.hpp>
27+
#include <qtils/hex.hpp>
2928
#include <tracy/Tracy.hpp>
3029

3130
#include <morum/archive_backend.hpp>
@@ -86,7 +85,7 @@ template <typename Duration>
8685
NiceDuration(const Duration&) -> NiceDuration<Duration>;
8786

8887
template <typename Duration>
89-
struct std::formatter<NiceDuration<Duration>> {
88+
struct fmt::formatter<NiceDuration<Duration>> {
9089
template <class ParseContext>
9190
constexpr ParseContext::iterator parse(ParseContext &ctx) {
9291
auto it = ctx.begin();
@@ -100,22 +99,22 @@ struct std::formatter<NiceDuration<Duration>> {
10099

101100
if (auto n = std::chrono::duration_cast<std::chrono::seconds>(dur).count();
102101
n > 10) {
103-
std::format_to(out, "{}s", n);
102+
fmt::format_to(out, "{}s", n);
104103
return out;
105104
}
106105
if (auto n =
107106
std::chrono::duration_cast<std::chrono::milliseconds>(dur).count();
108107
n > 10) {
109-
std::format_to(out, "{}ms", n);
108+
fmt::format_to(out, "{}ms", n);
110109
return out;
111110
}
112111
if (auto n =
113112
std::chrono::duration_cast<std::chrono::microseconds>(dur).count();
114113
n > 10) {
115-
std::format_to(out, "{}us", n);
114+
fmt::format_to(out, "{}us", n);
116115
return out;
117116
}
118-
std::format_to(out, "{}ns", dur.count());
117+
fmt::format_to(out, "{}ns", dur.count());
119118
return out;
120119
}
121120
};
@@ -207,9 +206,9 @@ int main() {
207206
QTILS_ASSERT_RANGE_EQ(res_opt.value().value(), v);
208207
}
209208
previous_root = nomt.get_root_and_store(*tree).value();
210-
std::println("{} - {} - total_duration: {}",
209+
fmt::println("{} - {} - total_duration: {}",
211210
step,
212-
previous_root,
211+
qtils::Hex{previous_root},
213212
NiceDuration(Clock::now() - total_start));
214213
totals[step].nomt = Clock::now() - total_start;
215214
}
@@ -326,32 +325,21 @@ int main() {
326325

327326
stats[step].total_duration += Clock::now() - total_start;
328327

329-
std::println(
328+
fmt::println(
330329
"\r{} - {}, {}, {} nodes and {} values written, {} bytes of values, "
331330
"{} "
332331
"bytes of nodes",
333332
step,
334-
hash,
333+
qtils::Hex{hash},
335334
stats[step].total_duration,
336335
stats[step].new_nodes_written,
337336
stats[step].new_values_written,
338337
stats[step].new_values_size,
339338
stats[step].new_nodes_written * sizeof(morum::Leaf));
340-
std::println("total_duration: {}", stats[step].total_duration);
339+
fmt::println("total_duration: {}", stats[step].total_duration);
341340
totals[step].archive = stats[step].total_duration;
342341

343-
// std::println("node_reads_duration: {}",
344-
// stats[step].node_reads_duration); std::println("value_reads_duration:
345-
// {}", stats[step].value_reads_duration);
346-
// std::println("writes_in_batch_duration: {}",
347-
// stats[step].writes_in_batch_duration);
348-
// std::println("{} - batch_write_duration: {}",
349-
// step,
350-
// stats[step].batch_write_duration);
351-
352-
// std::println("{}", rocksdb::get_perf_context()->ToString(true));
353-
// std::println("{}", rocksdb::get_iostats_context()->ToString());
354-
std::println(
342+
fmt::println(
355343
"{}", "=========================================================");
356344
FrameMark;
357345
}
@@ -398,32 +386,8 @@ int main() {
398386
avg.value_reads_duration /= stats.size();
399387
avg.writes_in_batch_duration /= stats.size();
400388

401-
// std::println("Avg:");
402-
// std::println("total_duration: {}", avg.total_duration);
403-
// std::println("batch_write_duration: {}", avg.batch_write_duration);
404-
// std::println("node_reads_duration: {}", avg.node_reads_duration);
405-
// std::println("value_reads_duration: {}", avg.value_reads_duration);
406-
// std::println("writes_in_batch_duration: {}",
407-
// avg.writes_in_batch_duration);
408-
409-
// std::println("Max:");
410-
// std::println("total_duration: {}", max.total_duration);
411-
// std::println("batch_write_duration: {}", max.batch_write_duration);
412-
// std::println("node_reads_duration: {}", max.node_reads_duration);
413-
// std::println("value_reads_duration: {}", max.value_reads_duration);
414-
// std::println("writes_in_batch_duration: {}",
415-
// max.writes_in_batch_duration);
416-
417-
// std::println("Min:");
418-
// std::println("total_duration: {}", min.total_duration);
419-
// std::println("batch_write_duration: {}", min.batch_write_duration);
420-
// std::println("node_reads_duration: {}", min.node_reads_duration);
421-
// std::println("value_reads_duration: {}", min.value_reads_duration);
422-
// std::println("writes_in_batch_duration: {}",
423-
// min.writes_in_batch_duration);
424-
425389
for (int i = 0; i < STEPS_NUM; i++) {
426-
std::println("#{}: NOMT {} vs Archive {}: {:.1f}%",
390+
fmt::println("#{}: NOMT {} vs Archive {}: {:.1f}%",
427391
i,
428392
NiceDuration(totals[i].nomt),
429393
NiceDuration(totals[i].archive),

vcpkg-overlay/qtils/portfile.cmake

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ vcpkg_check_linkage(ONLY_STATIC_LIBRARY)
22
vcpkg_from_github(
33
OUT_SOURCE_PATH SOURCE_PATH
44
REPO qdrvm/qtils
5-
REF 5f46bf03ec9af39c7a1bd85e5f96ccbaa9f4a064
6-
SHA512 848577aa4f9abd3d5f8154af9bdf01c81ecb4e41ceb2993e752831ce92706e2fce31fb67a414ee0e5c69424e896941f66877d582f6fd334c193dae365f9297d1
5+
REF 837b925296b3824d9fd6b46104990dc56671a1a7
6+
SHA512 c84c82b77797fd84c1970371edc00029b784ee73682dea31503fc4f03be8f9474b1387a68ad595c217f53fa61fa2398e17014c2e6e6b1b0764bd687e0a4a3d2a
77
)
88
vcpkg_cmake_configure(SOURCE_PATH "${SOURCE_PATH}"
99
OPTIONS

0 commit comments

Comments
 (0)