Merge commit 'f1087e81ecdca5a59ba5ffca684c955c5b38f7c2' as 'third_party/unordered_dense'

This commit is contained in:
Siarhei Fedartsou
2024-05-30 19:06:16 +02:00
2383 changed files with 16243 additions and 0 deletions
+17
View File
@@ -0,0 +1,17 @@
#include "periodic.h"
namespace ui {
periodic::periodic(std::chrono::steady_clock::duration interval)
: m_interval(interval) {}
periodic::operator bool() {
auto now = std::chrono::steady_clock::now();
if (now < m_next) {
return false;
}
m_next = now + m_interval;
return true;
}
} // namespace ui
+16
View File
@@ -0,0 +1,16 @@
#pragma once
#include <chrono>
namespace ui {
class periodic {
std::chrono::steady_clock::time_point m_next{};
std::chrono::steady_clock::duration m_interval{};
public:
explicit periodic(std::chrono::steady_clock::duration interval);
explicit operator bool();
};
} // namespace ui
@@ -0,0 +1,53 @@
#include "progress_bar.h"
#include <algorithm> // for min
namespace {
auto split(std::string_view symbols, char sep) -> std::vector<std::string> {
auto s = std::vector<std::string>();
while (true) {
auto idx = symbols.find(sep);
if (idx == std::string_view::npos) {
break;
}
s.emplace_back(symbols.substr(0, idx));
symbols.remove_prefix(idx + 1);
}
s.emplace_back(symbols);
return s;
}
} // namespace
namespace ui {
progress_bar::progress_bar(size_t width, size_t total, std::string_view symbols)
: m_width(width)
, m_total(total)
, m_symbols(split(symbols, ' ')) {}
auto progress_bar::operator()(size_t current) const -> std::string {
auto const total_states = m_width * m_symbols.size() + 1;
auto const current_state = total_states * current / m_total;
std::string str;
auto num_full = std::min(m_width, current_state / m_symbols.size());
for (size_t i = 0; i < num_full; ++i) {
str += m_symbols.back();
}
if (num_full < m_width) {
auto remaining = current_state - num_full * m_symbols.size();
if (0U != remaining) {
str += m_symbols[remaining - 1];
}
auto num_fillers = m_width - num_full - (0U == remaining ? 0 : 1);
for (size_t i = 0; i < num_fillers; ++i) {
str.push_back(' ');
}
}
return str;
}
} // namespace ui
+21
View File
@@ -0,0 +1,21 @@
#pragma once
#include <cstddef> // for size_t
#include <string> // for string, basic_string
#include <string_view> // for string_view
#include <vector> // for vector
namespace ui {
class progress_bar {
size_t m_width;
size_t m_total;
std::vector<std::string> m_symbols;
public:
progress_bar(size_t width, size_t total, std::string_view symbols = "⡀ ⡄ ⡆ ⡇ ⡏ ⡟ ⡿ ⣿");
auto operator()(size_t current) const -> std::string;
};
} // namespace ui