Skip to content

Commit

Permalink
Replace robin hood hash set/map with unordered-dense set/map
Browse files Browse the repository at this point in the history
  • Loading branch information
imwints committed Sep 13, 2023
1 parent 2c3ac48 commit cd4cd61
Show file tree
Hide file tree
Showing 18 changed files with 2,041 additions and 2,655 deletions.
2,544 changes: 0 additions & 2,544 deletions include/robin_hood.h

This file was deleted.

1,936 changes: 1,936 additions & 0 deletions include/unordered_dense.h

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/btop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ namespace Runner {
};

string debug_bg;
unordered_flat_map<string, array<uint64_t, 2>> debug_times;
map<string, array<uint64_t, 2>> debug_times;

class MyNumPunct : public std::numpunct<char>
{
Expand Down
12 changes: 6 additions & 6 deletions src/btop_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ namespace Config {
"#* The level set includes all lower levels, i.e. \"DEBUG\" will show all logging info."}
};

unordered_flat_map<std::string_view, string> strings = {
map<std::string_view, string> strings = {
{"color_theme", "Default"},
{"shown_boxes", "cpu mem net proc"},
{"graph_symbol", "braille"},
Expand All @@ -221,9 +221,9 @@ namespace Config {
{"proc_command", ""},
{"selected_name", ""},
};
unordered_flat_map<std::string_view, string> stringsTmp;
map<std::string_view, string> stringsTmp;

unordered_flat_map<std::string_view, bool> bools = {
map<std::string_view, bool> bools = {
{"theme_background", true},
{"truecolor", true},
{"rounded_corners", true},
Expand Down Expand Up @@ -269,9 +269,9 @@ namespace Config {
{"show_detailed", false},
{"proc_filtering", false},
};
unordered_flat_map<std::string_view, bool> boolsTmp;
map<std::string_view, bool> boolsTmp;

unordered_flat_map<std::string_view, int> ints = {
map<std::string_view, int> ints = {
{"update_ms", 2000},
{"net_download", 100},
{"net_upload", 100},
Expand All @@ -282,7 +282,7 @@ namespace Config {
{"proc_selected", 0},
{"proc_last_selected", 0},
};
unordered_flat_map<std::string_view, int> intsTmp;
map<std::string_view, int> intsTmp;

bool _locked(const std::string_view name) {
atomic_wait(writelock, true);
Expand Down
18 changes: 9 additions & 9 deletions src/btop_config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,28 @@ tab-size = 4

#pragma once

#include <filesystem>
#include <string>
#include <vector>
#include <filesystem>

#include <robin_hood.h>
#include <unordered_dense.h>

using std::string;
using std::vector;
using robin_hood::unordered_flat_map;
using ankerl::unordered_dense::map;

//* Functions and variables for reading and writing the btop config file
namespace Config {

extern std::filesystem::path conf_dir;
extern std::filesystem::path conf_file;

extern unordered_flat_map<std::string_view, string> strings;
extern unordered_flat_map<std::string_view, string> stringsTmp;
extern unordered_flat_map<std::string_view, bool> bools;
extern unordered_flat_map<std::string_view, bool> boolsTmp;
extern unordered_flat_map<std::string_view, int> ints;
extern unordered_flat_map<std::string_view, int> intsTmp;
extern map<std::string_view, string> strings;
extern map<std::string_view, string> stringsTmp;
extern map<std::string_view, bool> bools;
extern map<std::string_view, bool> boolsTmp;
extern map<std::string_view, int> ints;
extern map<std::string_view, int> intsTmp;

const vector<string> valid_graph_symbols = { "braille", "block", "tty" };
const vector<string> valid_graph_symbols_def = { "default", "braille", "block", "tty" };
Expand Down
29 changes: 13 additions & 16 deletions src/btop_draw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ namespace Symbols {

const array<string, 10> superscript = { "", "¹", "²", "³", "", "", "", "", "", "" };

const unordered_flat_map<string, vector<string>> graph_symbols = {
const map<string, vector<string>> graph_symbols = {
{ "braille_up", {
" ", "", "", "", "",
"", "", "", "", "",
Expand Down Expand Up @@ -297,7 +297,7 @@ namespace Draw {
return false;
}

static const unordered_flat_map<string, string> clock_custom_format = {
static const map<string, string> clock_custom_format = {
{"/user", Tools::username()},
{"/host", Tools::hostname()},
{"/uptime", ""}
Expand Down Expand Up @@ -605,7 +605,7 @@ namespace Cpu {
static long old_seconds{}; // defaults to = 0
static string old_status;
static Draw::Meter bat_meter {10, "cpu", true};
static const unordered_flat_map<string, string> bat_symbols = {
static const map<string, string> bat_symbols = {
{"charging", ""},
{"discharging", ""},
{"full", ""},
Expand Down Expand Up @@ -749,11 +749,11 @@ namespace Mem {
int disks_io_half = 0;
bool shown = true, redraw = true;
string box;
unordered_flat_map<string, Draw::Meter> mem_meters;
unordered_flat_map<string, Draw::Graph> mem_graphs;
unordered_flat_map<string, Draw::Meter> disk_meters_used;
unordered_flat_map<string, Draw::Meter> disk_meters_free;
unordered_flat_map<string, Draw::Graph> io_graphs;
map<string, Draw::Meter> mem_meters;
map<string, Draw::Graph> mem_graphs;
map<string, Draw::Meter> disk_meters_used;
map<string, Draw::Meter> disk_meters_free;
map<string, Draw::Graph> io_graphs;

string draw(const mem_info& mem, bool force_redraw, bool data_same) {
if (Runner::stopping) return "";
Expand Down Expand Up @@ -801,7 +801,7 @@ namespace Mem {
//? Disk meters and io graphs
if (show_disks) {
if (show_io_stat or io_mode) {
unordered_flat_map<string, int> custom_speeds;
map<string, int> custom_speeds;
int half_height = 0;
if (io_mode) {
disks_io_h = max((int)floor((double)(height - 2 - (disk_ios * 2)) / max(1, disk_ios)), (io_graph_combined ? 1 : 2));
Expand Down Expand Up @@ -1006,7 +1006,7 @@ namespace Net {
int b_x, b_y, b_width, b_height, d_graph_height, u_graph_height;
bool shown = true, redraw = true;
string old_ip;
unordered_flat_map<string, Draw::Graph> graphs;
map<string, Draw::Graph> graphs;
string box;

string draw(const net_info& net, bool force_redraw, bool data_same) {
Expand Down Expand Up @@ -1106,9 +1106,9 @@ namespace Proc {
bool shown = true, redraw = true;
int selected_pid = 0, selected_depth = 0;
string selected_name;
unordered_flat_map<size_t, Draw::Graph> p_graphs;
unordered_flat_map<size_t, bool> p_wide_cmd;
unordered_flat_map<size_t, int> p_counters;
map<size_t, Draw::Graph> p_graphs;
map<size_t, bool> p_wide_cmd;
map<size_t, int> p_counters;
int counter = 0;
Draw::TextEdit filter;
Draw::Graph detailed_cpu_graph;
Expand Down Expand Up @@ -1566,8 +1566,6 @@ namespace Proc {
else
++element;
}
p_graphs.compact();
p_counters.compact();

for (auto element = p_wide_cmd.begin(); element != p_wide_cmd.end();) {
if (rng::find(plist, element->first, &proc_info::pid) == plist.end()) {
Expand All @@ -1576,7 +1574,6 @@ namespace Proc {
else
++element;
}
p_wide_cmd.compact();
}

if (selected == 0 and selected_pid != 0) {
Expand Down
10 changes: 5 additions & 5 deletions src/btop_draw.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ tab-size = 4
#include <string>
#include <vector>
#include <array>
#include <robin_hood.h>
#include <unordered_dense.h>
#include <deque>

using robin_hood::unordered_flat_map;
using ankerl::unordered_dense::map;
using std::array;
using std::deque;
using std::string;
Expand Down Expand Up @@ -108,7 +108,7 @@ namespace Draw {
long long offset;
long long last = 0, max_value = 0;
bool current = true, tty_mode = false;
unordered_flat_map<bool, vector<string>> graphs = { {true, {}}, {false, {}}};
map<bool, vector<string>> graphs = { {true, {}}, {false, {}}};

//* Create two representations of the graph to switch between to represent two values for each braille character
void _create(const deque<long long>& data, int data_offset);
Expand All @@ -135,6 +135,6 @@ namespace Draw {

namespace Proc {
extern Draw::TextEdit filter;
extern unordered_flat_map<size_t, Draw::Graph> p_graphs;
extern unordered_flat_map<size_t, int> p_counters;
extern map<size_t, Draw::Graph> p_graphs;
extern map<size_t, int> p_counters;
}
4 changes: 2 additions & 2 deletions src/btop_input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ namespace rng = std::ranges;
namespace Input {

//* Map for translating key codes to readable values
const unordered_flat_map<string, string> Key_escapes = {
const map<string, string> Key_escapes = {
{"\033", "escape"},
{"\n", "enter"},
{" ", "space"},
Expand Down Expand Up @@ -79,7 +79,7 @@ namespace Input {
std::atomic<bool> interrupt (false);
std::atomic<bool> polling (false);
array<int, 2> mouse_pos;
unordered_flat_map<string, Mouse_loc> mouse_mappings;
map<string, Mouse_loc> mouse_mappings;

deque<string> history(50, "");
string old_filter;
Expand Down
6 changes: 3 additions & 3 deletions src/btop_input.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ tab-size = 4
#include <string>
#include <atomic>
#include <array>
#include <robin_hood.h>
#include <unordered_dense.h>
#include <deque>

using robin_hood::unordered_flat_map;
using ankerl::unordered_dense::map;
using std::array;
using std::atomic;
using std::deque;
Expand All @@ -44,7 +44,7 @@ namespace Input {
};

//? line, col, height, width
extern unordered_flat_map<string, Mouse_loc> mouse_mappings;
extern map<string, Mouse_loc> mouse_mappings;

extern atomic<bool> interrupt;
extern atomic<bool> polling;
Expand Down
8 changes: 4 additions & 4 deletions src/btop_menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ tab-size = 4
*/

#include <deque>
#include <robin_hood.h>
#include <unordered_dense.h>
#include <array>
#include <signal.h>
#include <errno.h>
Expand All @@ -31,7 +31,7 @@ tab-size = 4
#include "btop_draw.hpp"
#include "btop_shared.hpp"

using robin_hood::unordered_flat_map;
using ankerl::unordered_dense::map;
using std::array;
using std::ceil;
using std::max;
Expand Down Expand Up @@ -65,7 +65,7 @@ namespace Menu {
"SIGPWR", "SIGSYS"
};

unordered_flat_map<string, Input::Mouse_loc> mouse_mappings;
map<string, Input::Mouse_loc> mouse_mappings;

const array<array<string, 3>, 3> menu_normal = {
array<string, 3>{
Expand Down Expand Up @@ -1015,7 +1015,7 @@ namespace Menu {
static Draw::TextEdit editor;
static string warnings;
static bitset<8> selPred;
static const unordered_flat_map<string, std::reference_wrapper<const vector<string>>> optionsList = {
static const map<string, std::reference_wrapper<const vector<string>>> optionsList = {
{"color_theme", std::cref(Theme::themes)},
{"log_level", std::cref(Logger::log_levels)},
{"temp_scale", std::cref(Config::temp_scales)},
Expand Down
2 changes: 1 addition & 1 deletion src/btop_menu.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ namespace Menu {
extern bool redraw;

//? line, col, height, width
extern unordered_flat_map<string, Input::Mouse_loc> mouse_mappings;
extern map<string, Input::Mouse_loc> mouse_mappings;

//* Creates a message box centered on screen
//? Height of box is determined by size of content vector
Expand Down
26 changes: 13 additions & 13 deletions src/btop_shared.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ tab-size = 4
#include <tuple>
#include <vector>
#include <ifaddrs.h>
#include <robin_hood.h>
#include <unordered_dense.h>
#include <unistd.h>

using robin_hood::unordered_flat_map;
using ankerl::unordered_dense::map;
using std::array;
using std::atomic;
using std::deque;
Expand Down Expand Up @@ -96,7 +96,7 @@ namespace Cpu {
extern tuple<int, long, string> current_bat;

struct cpu_info {
unordered_flat_map<string, deque<long long>> cpu_percent = {
map<string, deque<long long>> cpu_percent = {
{"total", {}},
{"user", {}},
{"nice", {}},
Expand All @@ -122,8 +122,8 @@ namespace Cpu {
string draw(const cpu_info& cpu, bool force_redraw = false, bool data_same = false);

//* Parse /proc/cpu info for mapping of core ids
auto get_core_mapping() -> unordered_flat_map<int, int>;
extern unordered_flat_map<int, int> core_mapping;
auto get_core_mapping() -> map<int, int>;
extern map<int, int> core_mapping;

//* Get battery info from /sys
auto get_battery() -> tuple<int, long, string>;
Expand Down Expand Up @@ -155,13 +155,13 @@ namespace Mem {
};

struct mem_info {
unordered_flat_map<string, uint64_t> stats =
map<string, uint64_t> stats =
{{"used", 0}, {"available", 0}, {"cached", 0}, {"free", 0},
{"swap_total", 0}, {"swap_used", 0}, {"swap_free", 0}};
unordered_flat_map<string, deque<long long>> percent =
map<string, deque<long long>> percent =
{{"used", {}}, {"available", {}}, {"cached", {}}, {"free", {}},
{"swap_total", {}}, {"swap_used", {}}, {"swap_free", {}}};
unordered_flat_map<string, disk_info> disks;
map<string, disk_info> disks;
vector<string> disks_order;
};

Expand All @@ -183,7 +183,7 @@ namespace Net {
extern string selected_iface;
extern vector<string> interfaces;
extern bool rescale;
extern unordered_flat_map<string, uint64_t> graph_max;
extern map<string, uint64_t> graph_max;

struct net_stat {
uint64_t speed{}; // defaults to 0
Expand All @@ -195,14 +195,14 @@ namespace Net {
};

struct net_info {
unordered_flat_map<string, deque<long long>> bandwidth = { {"download", {}}, {"upload", {}} };
unordered_flat_map<string, net_stat> stat = { {"download", {}}, {"upload", {}} };
map<string, deque<long long>> bandwidth = { {"download", {}}, {"upload", {}} };
map<string, net_stat> stat = { {"download", {}}, {"upload", {}} };
string ipv4{}; // defaults to ""
string ipv6{}; // defaults to ""
bool connected{}; // defaults to false
};

extern unordered_flat_map<string, net_info> current_net;
extern map<string, net_info> current_net;

//* Collect net upload/download stats
auto collect(bool no_update=false) -> net_info&;
Expand Down Expand Up @@ -235,7 +235,7 @@ namespace Proc {
};

//? Translation from process state char to explanative string
const unordered_flat_map<char, string> proc_states = {
const map<char, string> proc_states = {
{'R', "Running"},
{'S', "Sleeping"},
{'D', "Waiting"},
Expand Down
Loading

0 comments on commit cd4cd61

Please sign in to comment.