v1
Brett 2023-03-05 17:21:14 -05:00
parent 62d929171c
commit c025299ee4
2 changed files with 18 additions and 4 deletions

View File

@ -90,7 +90,7 @@ namespace blt {
blt::flat_stack<BST_node*> nodeStack{}; blt::flat_stack<BST_node*> nodeStack{};
BST_node* current = root; BST_node* current = root;
while (current != nullptr || !nodeStack.isEmpty()) { while (current != nullptr || !nodeStack.empty()) {
// go all the way to the left subtree // go all the way to the left subtree
while (current != nullptr) { while (current != nullptr) {
nodeStack.push(current); nodeStack.push(current);

View File

@ -12,16 +12,30 @@
#include <vector> #include <vector>
namespace blt::string { namespace blt::string {
static inline constexpr double _static_pow(int p) {
int collection = 1;
for (int i = 0; i < p; i++)
collection *= 10;
return collection;
}
template<int decimal_places>
static inline double round_up(double value) {
constexpr double multiplier = _static_pow(decimal_places);
return ((int)(value * multiplier) + 1) / multiplier;
}
static inline std::string fromBytes(unsigned long bytes){ static inline std::string fromBytes(unsigned long bytes){
if (bytes > 1073741824) { if (bytes > 1073741824) {
// gigabyte // gigabyte
return std::to_string((double)bytes / 1024.0 / 1024.0 / 1024.0) += "gb"; return std::to_string(round_up<3>((double) bytes / 1024.0 / 1024.0 / 1024.0)) += "gb";
} else if (bytes > 1048576) { } else if (bytes > 1048576) {
// megabyte // megabyte
return std::to_string((double)bytes / 1024.0 / 1024.0) += "mb"; return std::to_string(round_up<3>((double)bytes / 1024.0 / 1024.0)) += "mb";
} else if (bytes > 1024) { } else if (bytes > 1024) {
// kilobyte // kilobyte
return std::to_string((double)bytes / 1024.0) += "kb"; return std::to_string(round_up<3>((double)bytes / 1024.0)) += "kb";
} else { } else {
return std::to_string(bytes) += "b"; return std::to_string(bytes) += "b";
} }