22// SPDX-License-Identifier: Apache-2.0
33
44#include < algorithm>
5- #include < bit>
6- #include < bitset>
75#include < filesystem>
86#include < fstream>
97#include < iostream>
8+ #include < ranges>
109#include < regex>
1110#include < stdexcept>
1211#include < string>
@@ -251,7 +250,7 @@ void table_get(EnvConfig& config, const std::string& table, const std::optional<
251250 ensure (k.has_value () || block_num.has_value (), " You must specify either --key or --block" );
252251 auto env = open_env (config);
253252 auto txn = env.start_read ();
254- ensure (has_map (txn, table. c_str () ), [&table]() { return " Table " + table + " not found" ; });
253+ ensure (has_map (txn, table), [&table]() { return " Table " + table + " not found" ; });
255254 ::mdbx::map_handle table_map = txn.open_map (table);
256255 const std::string_view key_identifier = block_num ? " block_key" : " key" ;
257256 const Bytes key = k.value_or (block_key (*block_num));
@@ -277,8 +276,7 @@ void table_get(EnvConfig& config, const std::string& table, const std::optional<
277276 std::cout << " \n " ;
278277}
279278
280- void do_clear (EnvConfig& config, bool dry, bool always_yes, const std::vector<std::string>& table_names,
281- bool drop) {
279+ void do_clear (EnvConfig& config, bool dry, bool always_yes, const std::vector<std::string>& table_names, bool drop) {
282280 config.readonly = false ;
283281
284282 if (!config.exclusive ) {
@@ -288,22 +286,22 @@ void do_clear(EnvConfig& config, bool dry, bool always_yes, const std::vector<st
288286 auto env{open_env (config)};
289287 auto txn{env.start_write ()};
290288
291- for (const auto & tablename : table_names) {
292- if (!has_map (txn, tablename. c_str () )) {
293- std::cout << " Table " << tablename << " not found\n " ;
289+ for (const auto & table : table_names) {
290+ if (!has_map (txn, table )) {
291+ std::cout << " Table " << table << " not found\n " ;
294292 continue ;
295293 }
296294
297- mdbx::map_handle table_map{txn.open_map (tablename )};
295+ mdbx::map_handle table_map{txn.open_map (table )};
298296 size_t rcount{txn.get_map_stat (table_map).ms_entries };
299297
300298 if (!rcount && !drop) {
301- std::cout << " Table " << tablename << " is already empty. Skipping\n " ;
299+ std::cout << " Table " << table << " is already empty. Skipping\n " ;
302300 continue ;
303301 }
304302
305303 std::cout << " \n "
306- << (drop ? " Dropping" : " Emptying" ) << " table " << tablename << " (" << rcount << " records) "
304+ << (drop ? " Dropping" : " Emptying" ) << " table " << table << " (" << rcount << " records) "
307305 << std::flush;
308306
309307 if (!always_yes) {
@@ -1003,12 +1001,12 @@ static void print_table_diff(ROTxn& txn1, ROTxn& txn2, const DbTableInfo& table1
10031001 [&]() { return " value_mode mismatch: " + std::to_string (static_cast <int >(table1.info .value_mode ())) + " vs " + std::to_string (static_cast <int >(table2.info .value_mode ())); });
10041002
10051003 MapConfig table1_config{
1006- .name = table1.name . c_str () ,
1004+ .name = table1.name ,
10071005 .key_mode = table1.info .key_mode (),
10081006 .value_mode = table1.info .value_mode (),
10091007 };
10101008 MapConfig table2_config{
1011- .name = table2.name . c_str () ,
1009+ .name = table2.name ,
10121010 .key_mode = table2.info .key_mode (),
10131011 .value_mode = table2.info .value_mode (),
10141012 };
@@ -1024,7 +1022,7 @@ static void print_table_diff(ROTxn& txn1, ROTxn& txn2, const DbTableInfo& table1
10241022 " MAIN_DBI" sv,
10251023 " DbInfo" sv,
10261024 };
1027- std::any_of (kIrrelevantTables . begin (), kIrrelevantTables . end () , [&table1](const std::string_view table_name) { return table_name == table1.name ; })) {
1025+ std::ranges:: any_of (kIrrelevantTables , [&table1](const std::string_view table_name) { return table_name == table1.name ; })) {
10281026 std::cout << " Skipping irrelevant table: " << table1.name << " \n " ;
10291027 return ;
10301028 }
@@ -1050,7 +1048,7 @@ static void print_table_diff(ROTxn& txn1, ROTxn& txn2, const DbTableInfo& table1
10501048
10511049static std::optional<DbTableInfo> find_table (const DbInfo& db_info, std::string_view table) {
10521050 const auto & db_tables{db_info.tables };
1053- const auto it{std::find_if (db_tables. begin (), db_tables. end () , [=](const auto & t) { return t.name == table; })};
1051+ const auto it{std::ranges:: find_if (db_tables, [=](const auto & t) { return t.name == table; })};
10541052 return it != db_tables.end () ? std::make_optional<DbTableInfo>(*it) : std::nullopt ;
10551053}
10561054
@@ -1066,12 +1064,12 @@ static DbComparisonResult compare_db_schema(const DbInfo& db1_info, const DbInfo
10661064
10671065 // Check both databases have the same table names
10681066 for (auto & db1_table : db1_tables) {
1069- if (std::find (db2_tables. begin (), db2_tables. end () , db1_table) == db2_tables.end ()) {
1067+ if (std::ranges:: find (db2_tables, db1_table) == db2_tables.end ()) {
10701068 return tl::make_unexpected (" db1 table " + db1_table.name + " not present in db2\n " );
10711069 }
10721070 }
10731071 for (auto & db2_table : db2_tables) {
1074- if (std::find (db1_tables. begin (), db1_tables. end () , db2_table) == db1_tables.end ()) {
1072+ if (std::ranges:: find (db1_tables, db2_table) == db1_tables.end ()) {
10751073 return tl::make_unexpected (" db2 table " + db2_table.name + " not present in db1\n " );
10761074 }
10771075 }
@@ -1374,12 +1372,10 @@ void do_first_byte_analysis(EnvConfig& config) {
13741372
13751373 // Sort histogram by usage (from most used to less used)
13761374 std::vector<std::pair<uint8_t , size_t >> histogram_sorted;
1377- std::copy (histogram.begin (), histogram.end (),
1378- std::back_inserter<std::vector<std::pair<uint8_t , size_t >>>(histogram_sorted));
1379- std::sort (histogram_sorted.begin (), histogram_sorted.end (),
1380- [](std::pair<uint8_t , size_t >& a, std::pair<uint8_t , size_t >& b) -> bool {
1381- return a.second == b.second ? a.first < b.first : a.second > b.second ;
1382- });
1375+ std::ranges::copy (histogram, std::back_inserter<std::vector<std::pair<uint8_t , size_t >>>(histogram_sorted));
1376+ std::ranges::sort (histogram_sorted, [](std::pair<uint8_t , size_t >& a, std::pair<uint8_t , size_t >& b) -> bool {
1377+ return a.second == b.second ? a.first < b.first : a.second > b.second ;
1378+ });
13831379
13841380 if (!histogram_sorted.empty ()) {
13851381 std::cout << (boost::format (" %-4s %8s" ) % " Byte" % " Count" ) << " \n "
0 commit comments